AshNeo4j

View Source

Module Version Hex Docs License

Ash DataLayer for Neo4j, configurable using a simple DSL

Installation

Add to the deps:

def deps do
  [
    {:ash_neo4j, "~> 0.1.1"},
  ]
end

Usage

Configure AshNeo4j.DataLayer as data_layer: within use Ash.Resource options:

  use Ash.Resource,
    data_layer: AshNeo4j.DataLayer

Configuration

Each Ash.Resource requires configuration of its AshNeo4j.DataLayer. An example Comment resource is given below, it can belong to a Post resource.

defmodule Comment.Resource do
  use Ash.Resource,
    data_layer: AshNeo4j.DataLayer

  neo4j do
    label :Comment
    store [:id, :title]
    translate id: :uuid
    relate [{:post, :BELONGS_TO, :outgoing}]
  end

  actions do
    default_accept(:*)
    defaults([:create, :read, :update, :destroy])
  end

  attributes do
    uuid_primary_key(:id)
    attribute(:title, :string, public?: true)
  end

  relationships do
    belongs_to(:post, Post, public?: true)
  end
end

Label

The DSL is used to label the Ash Resource's underlying graph node.

  neo4j do
    label :Comment
  end

Store

The DSL is used to store the Ash Resource's attributes as node properties, without translation.

  neo4j do
    store [:id, :title, :score, :public, :unique]
  end

Translate

The DSL may be used to translate the Ash Resource's attributes to node properties.

  neo4j do
    translate id: :uuid
  end

Relate

The DSL is used to direct any node relationships.

  neo4j do
    relate [{:post, :BELONGS_TO, :outgoing}]
  end

Installing Neo4j and Configuring Boltx

ash_neo4j uses neo4j which must be installed and running.

Your Ash application needs to configure, start and supervise boltx, see boltx documentation. Make sure to configure any required authorisation.

I've used Neo4j community edition 4.4 (bolt 4.4) and to connect using boltx I needed to also set the environment variable BOLT_VERSIONS=4.4 to steer [bolt protocol handshake] (https://neo4j.com/docs/bolt/current/bolt/handshake).

Limitations and Future Work

Currently ash_neo4j only supports Ash read actions, with some limited support for relationships. Support for create, update and destroy actions is next.

Collaboration on ash_neo4j welcome via github, please use discussions and/or issues as appropriate.

Acknowledgements

Thanks to the Ash Core for ash 🚀, including ash_csv which was an exemplar.

Thanks to Sagastume for boltx which AFAIK was based on bolt_sips by Florin Patrascu.

Thanks to the Neo4j Core for neo4j which pioneered graph databases.

Diffo.dev Neo4j Deployment Centre.