Skip to content

Ash DataLayer for Apache AGE graph database. MIT licensed. Open source library managed via Base MCP. For contributions and issues, see: https://github.com/baselabs/ash_age

License

Notifications You must be signed in to change notification settings

baselabs/ash_age

Repository files navigation

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.1.0"}
  ]
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

  • mix ash_age.install — Print step-by-step setup instructions
  • mix ash_age.gen.migration NAME — Generate a timestamped AGE migration
  • mix ash_age.verify — Verify AGE extension, search_path, and graph existence

Development

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

Documentation

  • CONTRIBUTING.md — Contribution guidelines
  • LICENSE — MIT License
  • usage-rules.md — AI agent usage patterns (via usage_rules package)

License

MIT

About

Ash DataLayer for Apache AGE graph database. MIT licensed. Open source library managed via Base MCP. For contributions and issues, see: https://github.com/baselabs/ash_age

Resources

License

Contributing

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •  

Languages