ash_age

⚠️ AI-Generated Code - Use at Your Own Risk

This package was initially created using AI tools as part of a larger project integration effort. While functional, it may not reflect production-ready standards or best practices for a standalone library.

Use this code at your own discretion. Review it carefully before using in production. Pull requests and contributions to improve the implementation and documentation are welcome.

Ash DataLayer for Apache AGE graph database.

Installation

Add to your mix.exs:

def deps do
  [
    {:ash_age, "~> 0.2.4"}
  ]
end

Usage

See lib/ash_age.ex for full documentation.

Quick Start

  1. Ensure Apache AGE extension is installed in PostgreSQL

  2. Register Postgrex types for AGE's agtype:

defmodule MyApp.PostgrexTypes do
  Postgrex.Types.define(
    MyApp.PostgrexTypes,
    [AshAge.Postgrex.AgtypeExtension] ++ Ecto.Adapters.Postgres.extensions(),
    []
  )
end
  1. Configure your Repo with the AGE session hook and types module:
config :my_app, MyApp.Repo,
  after_connect: {AshAge.Session, :setup, []},
  types: MyApp.PostgrexTypes

This sets search_path to public, ag_catalog, "$user" and loads the AGE extension on each connection. (public must be first to prevent shadowing Ecto's schema_migrations table.)

  1. Create an AGE graph via migration:
defmodule MyApp.Repo.Migrations.CreateAgeGraph do
  use Ecto.Migration
  import AshAge.Migration

  def up do
    create_age_graph("my_graph")
    create_vertex_label("my_graph", "Entity")
  end

  def down do
    drop_age_graph("my_graph")
  end
end
  1. Define Ash resources using AshAge.DataLayer:
defmodule MyApp.MyEntity do
  use Ash.Resource,
    domain: MyApp.Domain,
    data_layer: AshAge.DataLayer

  age do
    graph :my_graph
    repo MyApp.Repo
    label :Entity
  end

  attributes do
    uuid_primary_key :id
    attribute :tenant_id, :uuid, allow_nil?: false
    attribute :label, :string, allow_nil?: false
    attribute :properties, :map, default: %{}
  end

  actions do
    defaults [:read, :create, :update, :destroy]
  end
end

Mix Tasks

Development

cd ash_age
mix deps.get
mix test
mix format
mix credo --strict

Documentation

License

MIT