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"}
]
endUsage
See lib/ash_age.ex for full documentation.
Quick Start
Ensure Apache AGE extension is installed in PostgreSQL
Register Postgrex types for AGE's
agtype:
defmodule MyApp.PostgrexTypes do
Postgrex.Types.define(
MyApp.PostgrexTypes,
[AshAge.Postgrex.AgtypeExtension] ++ Ecto.Adapters.Postgres.extensions(),
[]
)
end- 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.)
- 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- 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
endMix Tasks
mix ash_age.install— Print step-by-step setup instructionsmix ash_age.gen.migration NAME— Generate a timestamped AGE migrationmix ash_age.verify— Verify AGE extension, search_path, and graph existence
Development
cd ash_age
mix deps.get
mix test
mix format
mix credo --strictDocumentation
- CONTRIBUTING.md — Contribution guidelines
- LICENSE — MIT License
- usage-rules.md — AI agent usage patterns (via
usage_rulespackage)
License
MIT