Maintainers
Pricing
Enterprise
More
More
Documentation
Try Live
Rankings
Install
Blog
Docs7
Ask
New
Add Docs
AshNeo4j
https://hexdocs.pm/ash_neo4j/
Admin
Ash DataLayer for Neo4j, configurable using a simple DSL.
Tokens:
103,647
Snippets:
1,070
Trust Score:
9
Update:
3 months ago
Context
Chat
Benchmark
Latest
Show doc for...
Code
Info
Show Results
Tokens:
Raw
Copy
Link
Tokens:
Raw
Copy
Link
### start() Source: https://hexdocs.pm/ash_neo4j/AshNeo4j.BoltyHelper.html Starts Bolty with default configuration. ```APIDOC ## start() ### Description Starts Bolty, returns :ok or {:error, error}. ### Method `start` ### Parameters None ``` -------------------------------- ### start Source: https://hexdocs.pm/ash_neo4j/AshNeo4j.BoltyHelper.html Starts Bolty with default configuration. ```APIDOC ## start ### Description Starts Bolty, returns :ok or {:error, error}. ### Function Signature start() ### Returns - `:ok` or `{:error, error}`: The result of starting Bolty. ``` -------------------------------- ### start(config) Source: https://hexdocs.pm/ash_neo4j/AshNeo4j.BoltyHelper.html Starts Bolty with a provided configuration. ```APIDOC ## start(config) ### Description Starts Bolty with config, returns :ok or {:error, error}. ### Method `start` ### Parameters #### Path Parameters - **config** (map) - Required - The configuration map for starting Bolty. ``` -------------------------------- ### start(config) Source: https://hexdocs.pm/ash_neo4j/AshNeo4j.BoltyHelper.html Starts Bolty with a custom configuration. ```APIDOC ## start(config) ### Description Starts Bolty with config, returns :ok or {:error, error}. ### Function Signature start(config) ### Parameters #### Path Parameters - **config** (any) - Required - The configuration to start Bolty with. ``` -------------------------------- ### Checkout Sandbox Connection and Start Transaction Source: https://hexdocs.pm/ash_neo4j/AshNeo4j.Sandbox.html Use this setup in your ExUnit tests to get an isolated Neo4j connection and transaction. The `on_exit` call is optional but recommended for clarity. ```elixir setup do AshNeo4j.Sandbox.checkout() on_exit(&AshNeo4j.Sandbox.rollback/0) end ``` -------------------------------- ### Install AshNeo4j Source: https://hexdocs.pm/ash_neo4j/Mix.Tasks.AshNeo4j.Install.html Run this command in your terminal to install AshNeo4j. ```bash mix igniter.install ash_neo4j ``` -------------------------------- ### Example Usage of AshNeo4j worlds/1 Source: https://hexdocs.pm/ash_neo4j/AshNeo4j.html Demonstrates how to retrieve a record using Ash.get! and then use AshNeo4j.worlds/1 to get the worlds a node participates in. It also shows how to extract the outermost world. ```elixir record = Ash.get!(SomeBaseInstance, id) AshNeo4j.worlds(record) #=> [{MyApp, MyApp.ConcreteInstance}, {Diffo.Provider, Diffo.Provider.Instance}] # Consumers typically want the outermost (most-nuanced) world: {domain, resource} = hd(AshNeo4j.worlds(record)) ``` -------------------------------- ### Install AshNeo4j and Kino Source: https://hexdocs.pm/ash_neo4j/managing_schema.html Install the necessary dependencies for AshNeo4j and Kino. This is typically done at the beginning of a project or script. ```elixir Mix.install( [ {:ash_neo4j, "~> 0.10"}, {:kino, "~> 0.14"} ], consolidate_protocols: false ) ``` -------------------------------- ### Install Ash Neo4j and Kino Source: https://hexdocs.pm/ash_neo4j/ash_neo4j_datalayer.html Install the Ash Neo4j datalayer and Kino for interactive livebook tutorials. Ensure consolidate_protocols is set to false. ```elixir Mix.install( [ {:ash_neo4j, "~> 0.9"}, {:kino, "~> 0.14"} ], consolidate_protocols: false ) ``` -------------------------------- ### Start Bolty Helper Process Source: https://hexdocs.pm/ash_neo4j/ash_neo4j_datalayer.html Start the Bolty process using the defined configuration. This ensures Ash Neo4j can connect to Neo4j. ```elixir AshNeo4j.BoltyHelper.start(config) ``` -------------------------------- ### Create Node Example Source: https://hexdocs.pm/ash_neo4j/AshNeo4j.Neo4jHelper.html Demonstrates how to create a node with specified labels and properties. This is a prerequisite for relationship operations. ```Elixir iex> AshNeo4j.Neo4jHelper.create_node([:Actor], %{name: "Keira Knightley"}) iex> AshNeo4j.Neo4jHelper.create_node([:Actor], %{name: "Bill Nighy"}) iex> AshNeo4j.Neo4jHelper.create_node([:Movie], %{title: "Love Actually"}) ``` -------------------------------- ### Create Specification Instances Source: https://hexdocs.pm/ash_neo4j/ash_neo4j_datalayer.html Example of creating multiple instances of the Specification resource with different attributes. ```elixir broadband_v1 = Specification |> Ash.create!(%{name: "broadband"}) nbn_ethernet_v1 = Specification |> Ash.create!(%{name: "nbnEthernet", type: :resource}) mobile_backup_v2 = Specification |> Ash.create!(%{name: "mobileBackup", major_version: 2, minor_version: 3}) esim_v1 = Specification |> Ash.create!(%{name: "esim", type: :resource}) specifications = [broadband_v1, mobile_backup_v2, nbn_ethernet_v1, esim_v1] ``` -------------------------------- ### Setup for Ash Neo4j Sandbox Testing Source: https://hexdocs.pm/ash_neo4j/index.html This setup ensures test isolation by checking out a dedicated Neo4j connection with an open transaction for each test. The `on_exit` call is optional but recommended for clarity. ```elixir setup_all do AshNeo4j.BoltyHelper.start() end setup do AshNeo4j.Sandbox.checkout() on_exit(&AshNeo4j.Sandbox.rollback/0) end ``` -------------------------------- ### start_bolt_apoc() Source: https://hexdocs.pm/ash_neo4j/AshNeo4j.BoltyHelper.html Starts the BoltApoc pool for Neo4j 5.x Community with APOC. ```APIDOC ## start_bolt_apoc() ### Description Starts the BoltApoc pool (Neo4j 5.x Community + APOC, #386). Returns :ok, {:error, error}, or {:error, :not_configured} when no BoltApoc config is present. ### Method `start_bolt_apoc` ### Parameters None ``` -------------------------------- ### start_bolt6() Source: https://hexdocs.pm/ash_neo4j/AshNeo4j.BoltyHelper.html Starts the Bolt6 pool for Neo4j 2026.05 with Bolt 6.0. ```APIDOC ## start_bolt6() ### Description Starts the Bolt6 pool (Neo4j 2026.05, Bolt 6.0). Returns :ok, {:error, error}, or {:error, :not_configured} when no Bolt6 config is present. ### Method `start_bolt6` ### Parameters None ``` -------------------------------- ### start_bolt_apoc Source: https://hexdocs.pm/ash_neo4j/AshNeo4j.BoltyHelper.html Starts the BoltApoc pool for Neo4j 5.x Community with APOC. ```APIDOC ## start_bolt_apoc ### Description Starts the BoltApoc pool (Neo4j 5.x Community + APOC, #386). Returns :ok, {:error, error}, or {:error, :not_configured} when no BoltApoc config is present. ### Function Signature start_bolt_apoc() ### Returns - `:ok`, `{:error, error}`, or `{:error, :not_configured}`: The result of starting the BoltApoc pool. ``` -------------------------------- ### start_bolt6 Source: https://hexdocs.pm/ash_neo4j/AshNeo4j.BoltyHelper.html Starts the Bolt6 pool for Neo4j 2026.05 and Bolt 6.0. ```APIDOC ## start_bolt6 ### Description Starts the Bolt6 pool (Neo4j 2026.05, Bolt 6.0). Returns :ok, {:error, error}, or {:error, :not_configured} when no Bolt6 config is present. ### Function Signature start_bolt6() ### Returns - `:ok`, `{:error, error}`, or `{:error, :not_configured}`: The result of starting the Bolt6 pool. ``` -------------------------------- ### Running Ash Neo4j Test Suite Source: https://hexdocs.pm/ash_neo4j/index.html Commands to start the necessary Neo4j instances using Docker Compose and run the test suite. Includes options for running the full suite with additional Neo4j versions and APOC. ```bash docker compose up -d --wait # bolt5 → 7687, bolt6 → 7689, apoc → 7691 mix test # default suite (7687 only) mix test --include cypher25 --include bolt6 --include apoc # full suite docker compose down # tear down ``` -------------------------------- ### Create and Recreate Vector Indexes Source: https://hexdocs.pm/ash_neo4j/managing_schema.html Provides examples for creating a vector index and for recreating it if dimensions or similarity function have changed. Recreating drops and then re-creates the index. ```elixir # create it (Cypher 25 required) AshNeo4j.Vector.create_index(Schema.Note, :embedding) # changed :dimensions or :similarity_function? recreate drops then re-creates: AshNeo4j.Vector.create_index(Schema.Note, :embedding, recreate: true, similarity_function: :euclidean) ``` -------------------------------- ### Relate Nodes Example Source: https://hexdocs.pm/ash_neo4j/AshNeo4j.Neo4jHelper.html Shows how to establish a relationship between two nodes. This function is used to link entities in the graph database. ```Elixir iex> AshNeo4j.Neo4jHelper.relate_nodes(:Actor, %{name: "Keira Knightley"}, :Movie, %{title: "Love Actually"}, :ACTED_IN, :outgoing) iex> AshNeo4j.Neo4jHelper.relate_nodes(:Actor, %{name: "Bill Nighy"}, :Movie, %{title: "Love Actually"}, :ACTED_IN, :outgoing) ``` -------------------------------- ### Get Neo4j DSL Options Source: https://hexdocs.pm/ash_neo4j/AshNeo4j.DataLayer.Domain.Info.html Retrieves a map of Neo4j DSL options, including configured or default values. ```elixir neo4j_options(dsl_or_extended) ``` -------------------------------- ### Get Neo4j Options Source: https://hexdocs.pm/ash_neo4j/AshNeo4j.DataLayer.Info.html Retrieves a map containing the Neo4j DSL options, including any configured or default values. ```elixir @spec neo4j_options(dsl_or_extended :: module() | map()) :: %{ required(atom()) => any() } ``` -------------------------------- ### Get All Labels for a Resource Source: https://hexdocs.pm/ash_neo4j/AshNeo4j.Resource.Info.html Returns the full list of labels applied to a node on creation. The order is domain, module, resource fragment base type, and domain fragment. Useful for understanding the full graph representation of a resource. ```elixir @spec all_labels(Ash.Resource.t()) :: [atom()] | nil ``` -------------------------------- ### Get Index Creation Statements Source: https://hexdocs.pm/ash_neo4j/changelog.html Returns the Cypher statements required to create a spatial index without executing them against the database. Useful for review or dry runs. ```elixir AshNeo4j.Spatial.index_statements(Place, [:pet, :home]) ``` -------------------------------- ### Get Domain Label of a Resource Source: https://hexdocs.pm/ash_neo4j/AshNeo4j.Resource.Info.html Retrieves the PascalCase short name of the domain's Elixir Module name. Used only during resource creation. ```elixir @spec domain_label(Ash.Resource.t()) :: atom() | nil ``` -------------------------------- ### Get Resource Graph Mapping Source: https://hexdocs.pm/ash_neo4j/AshNeo4j.Resource.Info.html Returns the complete graph mapping for a resource as a `%AshNeo4j.ResourceMapping{}` struct. This is the definitive source for how an Ash resource maps to the Neo4j graph. ```elixir @spec mapping(Ash.Resource.t()) :: AshNeo4j.ResourceMapping.t() ``` -------------------------------- ### Get Constraint Statements for Post Resource Source: https://hexdocs.pm/ash_neo4j/AshNeo4j.Constraint.html Returns the `CREATE CONSTRAINT` Cypher statements that would be run for the `Post` resource's primary key and unique identities. This function does not modify the database. ```elixir AshNeo4j.Constraint.constraint_statements(Post) #=> {:ok, ["CREATE CONSTRAINT post_pk IF NOT EXISTS FOR (n:Post) REQUIRE n.uuid IS UNIQUE", # "CREATE CONSTRAINT post_unique_unique IF NOT EXISTS FOR (n:Post) REQUIRE n.unique IS UNIQUE"]} ``` -------------------------------- ### Configure and Connect to Neo4j Source: https://hexdocs.pm/ash_neo4j/managing_schema.html Configure the connection details for your local Neo4j instance and establish a connection using AshNeo4j.BoltyHelper. Only live 'create / drop / SHOW' cells require an active connection; dry-run cells do not. ```elixir config = [ uri: "bolt://localhost:7687", auth: [username: "neo4j", password: "password"], user_agent: "ashNeo4jSchemaHowTo/1", pool_size: 5, prefix: :default, name: Bolt, versions: [6.0, {5, 6..8}, {5, 0..4}], log: false ] AshNeo4j.BoltyHelper.start(config) AshNeo4j.BoltyHelper.is_connected() ``` -------------------------------- ### Create Resource Instances Source: https://hexdocs.pm/ash_neo4j/ash_neo4j_datalayer.html Create new resource instances with specified names and specifications. These instances are then collected into a list. ```elixir esim_0001 = Resource |> Ash.create!(%{name: "esim_0001", specified_by: esim_v1.id}) nbn_ethernet_0001 = Resource |> Ash.create!(%{name: "nbnEthernet_0001", specified_by: nbn_ethernet_v1.id}) resources = [esim_0001, nbn_ethernet_0001] ``` -------------------------------- ### Create Service Instances Source: https://hexdocs.pm/ash_neo4j/ash_neo4j_datalayer.html Create new service instances, each associated with a specific specification. The created services are stored in a list. ```elixir broadband_0001 = Service |> Ash.create!(%{name: "broadband_0001", specified_by: broadband_v1.id}) mobile_backup_0001 = Service |> Ash.create!(%{name: "mobileBackup_0001", specified_by: mobile_backup_v2.id}) services = [broadband_0001, mobile_backup_0001] ``` -------------------------------- ### Get Neo4j Label (Unsafe) Source: https://hexdocs.pm/ash_neo4j/AshNeo4j.DataLayer.Info.html Retrieves the optional node label. Raises an error on failure. ```elixir @spec neo4j_label!(dsl_or_extended :: module() | map()) :: atom() | no_return() ``` -------------------------------- ### Get Neo4j Label (Safe) Source: https://hexdocs.pm/ash_neo4j/AshNeo4j.DataLayer.Info.html Retrieves the optional node label. Returns :error on failure. ```elixir @spec neo4j_label(dsl_or_extended :: module() | map()) :: {:ok, atom()} | :error ``` -------------------------------- ### Migrate Box Attribute Source: https://hexdocs.pm/ash_neo4j/changelog.html Example of migrating a spatial attribute from AshNeo4j.Type.Box to AshGeo.GeoJson for polygon types. ```elixir attribute :b, AshGeo.GeoJson, constraints: [geo_types: [:polygon], force_srid: 4326] ``` -------------------------------- ### Create and Relate Nodes Source: https://hexdocs.pm/ash_neo4j/AshNeo4j.Neo4jHelper.html Demonstrates creating two nodes (Actor and Movie) and then relating them with an 'ACTED_IN' relationship. ```elixir iex> AshNeo4j.Neo4jHelper.create_node([:Actor], %{name: "Bill Nighy", born: 1949}) ``` ```elixir iex> AshNeo4j.Neo4jHelper.create_node([:Movie], %{title: "Love Actually"}) ``` ```elixir iex> {result, _} = AshNeo4j.Neo4jHelper.relate_nodes(:Actor, %{name: "Bill Nighy"}, :Movie, %{title: "Love Actually"}, :ACTED_IN, :outgoing) ``` ```elixir iex> result :ok ``` -------------------------------- ### Migrate Point Attribute Source: https://hexdocs.pm/ash_neo4j/changelog.html Example of migrating a spatial attribute from AshNeo4j.Type.Point to AshGeo.GeoJson for point types. ```elixir attribute :loc, AshGeo.GeoJson, constraints: [geo_types: [:point], force_srid: 4326] ``` -------------------------------- ### checkout() Source: https://hexdocs.pm/ash_neo4j/AshNeo4j.Sandbox.html Checks out a sandbox connection and begins a Neo4j transaction. All Cypher queries from the calling process are routed to this connection and executed within the open transaction. The transaction is rolled back automatically when the calling process exits. Raises if called more than once without an intervening `rollback/0`. ```APIDOC ## checkout() ### Description Checks out a sandbox connection and begins a Neo4j transaction. All Cypher queries from the calling process are routed to this connection and executed within the open transaction. The transaction is rolled back automatically when the calling process exits. Raises if called more than once without an intervening `rollback/0`. ### Function Signature ```elixir @spec checkout() :: :ok ``` ``` -------------------------------- ### APOC Availability Healthcheck Source: https://hexdocs.pm/ash_neo4j/changelog.html Detects if APOC procedures are installed on the server, allowing graceful degradation of APOC-dependent paths. ```elixir AshNeo4j.APOC ``` -------------------------------- ### Retrieve Bolty Connection Policy Source: https://hexdocs.pm/ash_neo4j/ash_neo4j_datalayer.html Get the resolved capabilities for the current Neo4j connection, known as the Bolty Policy. ```elixir AshNeo4j.BoltyHelper.policy() ``` -------------------------------- ### Get Relationship Attributes Source: https://hexdocs.pm/ash_neo4j/AshNeo4j.Resource.Info.html Returns the relationship attributes for the resource. Use to access metadata about the resource's relationships. ```elixir @spec relationship_attributes(Ash.Resource.t()) :: keyword() | nil ``` -------------------------------- ### Get Node Relationship by Name Source: https://hexdocs.pm/ash_neo4j/AshNeo4j.Resource.Info.html Returns a node_relationship that matches the provided relationship name. The name can be an atom or a string. ```elixir @spec node_relationship(Ash.Resource.t(), atom() | String.t()) :: tuple() | nil ``` -------------------------------- ### Paginate Nodes with Order, Skip, and Limit Source: https://hexdocs.pm/ash_neo4j/AshNeo4j.Cypher.Query.html Applies SKIP/LIMIT pagination and ORDER BY to source nodes before edge expansion. Use this to ensure pagination is scoped to nodes rather than edges. It's a no-op if neither skip nor limit is provided. ```Elixir @spec paginate_nodes( t(), [{String.t(), :asc | :desc}], non_neg_integer() | nil, pos_integer() | nil ) :: t() ``` -------------------------------- ### Get Short Module Name Source: https://hexdocs.pm/ash_neo4j/AshNeo4j.Util.html Retrieves the short name of an Elixir Module. This is useful for simplifying module references. ```elixir iex> AshNeo4j.Util.short_name(MyApp.Domain.User) :User ``` -------------------------------- ### Create Constraints for Resource with Options Source: https://hexdocs.pm/ash_neo4j/AshNeo4j.Constraint.html Executes `CREATE CONSTRAINT … IF NOT EXISTS` for a resource's primary key and identities. It returns a list of responses or an error if an identity cannot be enforced. ```elixir AshNeo4j.Constraint.create_constraints(resource, opts \\ []) ``` -------------------------------- ### Create Neo4j Schema for Resources Source: https://hexdocs.pm/ash_neo4j/managing_schema.html A typical release task to create the schema for multiple resources. This process is idempotent, ensuring it's safe to run on every release. It iterates through a list of resources and creates their respective constraints and indexes. ```elixir for resource <- [Schema.Product, Schema.Listing] do {resource, AshNeo4j.Constraint.create_constraints(resource)} end ``` -------------------------------- ### AshNeo4j.Unknown Constructor Source: https://hexdocs.pm/ash_neo4j/AshNeo4j.Unknown.html Builds an AshNeo4j.Unknown struct, stamping it with the query world, a reason (leaf atom or nested unknown), and optional local context. ```elixir new(world, reason, context \\ %{}) ``` -------------------------------- ### Define NxTensor Attribute Source: https://hexdocs.pm/ash_neo4j/AshNeo4j.Type.NxTensor.html Example of how to define an attribute using the NxTensor type with specified constraints for type and shape. ```elixir attribute :weights, AshNeo4j.Type.NxTensor, constraints: [type: :f32, shape: [3, 3]] ``` -------------------------------- ### Create Neo4j Spatial Indexes Source: https://hexdocs.pm/ash_neo4j/AshNeo4j.Spatial.html Use `create_index/3` to set up Neo4j POINT indexes for spatial queries. It handles different geometry types and nested attributes. The function is idempotent and safe to run repeatedly. ```elixir AshNeo4j.Spatial.create_index(Place, :location) # non-Point geometry → both bbSW and bbNE indexes AshNeo4j.Spatial.create_index(Place, :bounds) # nested geometry — [attribute, field...] path into a TypedStruct AshNeo4j.Spatial.create_index(Place, [:pet, :home]) # rebuild (DROP IF EXISTS + CREATE) after a storage-shape change AshNeo4j.Spatial.create_index(Place, :location, recreate: true) ``` -------------------------------- ### Define Vector Attribute in AshNeo4j Source: https://hexdocs.pm/ash_neo4j/AshNeo4j.Type.Vector.html Example of how to define a vector attribute with specific element type and dimensions constraints. ```elixir attribute :embedding, AshNeo4j.Type.Vector, constraints: [element_type: :float32, dimensions: 1536] ``` -------------------------------- ### from_bolt/1 Source: https://hexdocs.pm/ash_neo4j/AshNeo4j.Error.Neo4j.html Maps errors from `AshNeo4j.Cypher.run/1` to a classified `AshNeo4j.Error.Neo4j` struct. ```APIDOC ## from_bolt/1 ### Description Maps an error surfaced from `Cypher.run/1` to a classified `AshNeo4j.Error.Neo4j`. A `%Bolty.Error{}` with a Neo4j status code is classified by that code; any other error term is wrapped with `category: :other`. ### Function Signature `from_bolt(error)` ### Parameters - `error`: The error term surfaced from `AshNeo4j.Cypher.run/1`. ``` -------------------------------- ### Configure Destruction Guards Source: https://hexdocs.pm/ash_neo4j/readme.html Use the `guard` DSL to protect resources from destruction when certain relationships exist. This is useful for maintaining data integrity when other resources depend on the resource being guarded. ```elixir neo4j do guard [{:WRITTEN_BY, :outgoing, :Post}] end ``` -------------------------------- ### apoc_available? Source: https://hexdocs.pm/ash_neo4j/AshNeo4j.BoltyHelper.html Checks if the current Neo4j connection pool has APOC installed. This is useful for health checks before using APOC functions. ```APIDOC ## apoc_available? ### Description Returns `true` when the current pool (see `current_pool/0`) is connected to a Neo4j server with **APOC** installed (#386) — useful as a deploy/start-up healthcheck before relying on an `apoc.*` `fragment(...)`. ### Function Signature apoc_available?() ### Returns - `boolean`: `true` if APOC is available, `false` otherwise. ``` -------------------------------- ### Targeting a Second Neo4j Instance with Pool Routing Source: https://hexdocs.pm/ash_neo4j/readme.html Demonstrates how to route a test's queries and capability checks to a different Neo4j server using `with_pool/2`. This is useful for running specific tests, like Cypher-25 vector tests, against different Neo4j versions or configurations. ```elixir AshNeo4j.BoltyHelper.current_pool()/0 with_pool/2 ``` -------------------------------- ### Get Neo4j Label (OK/Error) Source: https://hexdocs.pm/ash_neo4j/AshNeo4j.DataLayer.Domain.Info.html Retrieves the Neo4j label atom for node creation. Returns :ok atom or :error. ```elixir neo4j_label(dsl_or_extended) ``` -------------------------------- ### Define Ash Domain with No Configuration Inclusion Source: https://hexdocs.pm/ash_neo4j/managing_schema.html Configure an Ash domain to not validate configuration inclusion. This is useful for simplifying domain setup. ```elixir defmodule Schema.Domain do use Ash.Domain, validate_config_inclusion?: false resources do allow_unregistered? true end end ``` -------------------------------- ### run(cypher, params) Source: https://hexdocs.pm/ash_neo4j/AshNeo4j.Cypher.html Executes a raw Cypher query with optional parameters. ```APIDOC ## run(cypher, params) ### Description Executes a raw Cypher query with optional parameters. ### Parameters - **cypher** (string) - Required - The Cypher query string to execute. - **params** (map) - Optional - A map of parameters to bind to the query. ``` -------------------------------- ### Get Effective Relate Source: https://hexdocs.pm/ash_neo4j/AshNeo4j.Resource.Info.html Returns the effective relate of the resource, merging DSL and defaults. Use to understand how relationships are defined and applied. ```elixir @spec relate(Ash.Resource.t()) :: [tuple()] | nil ``` -------------------------------- ### Define Listing Resource with Composite Primary Key Source: https://hexdocs.pm/ash_neo4j/managing_schema.html Define a Listing resource with a composite primary key composed of 'marketplace' and 'sku'. This enforces uniqueness across these two attributes. ```elixir defmodule Schema.Listing do use Ash.Resource, domain: Schema.Domain, data_layer: AshNeo4j.DataLayer neo4j do label :Listing end attributes do # a composite primary key → one composite IS UNIQUE constraint attribute :marketplace, :string, allow_nil?: false, primary_key?: true, public?: true attribute :sku, :string, allow_nil?: false, primary_key?: true, public?: true attribute :price, :integer, public?: true end end ``` -------------------------------- ### Get Domain from Unknown Source: https://hexdocs.pm/ash_neo4j/AshNeo4j.Unknown.html Retrieves the Ash Domain associated with the query frame from an AshNeo4j.Unknown. Returns nil if no resolvable world is present. ```elixir @spec domain(t()) :: module() | nil ``` -------------------------------- ### Bulk Updates and Destroys Source: https://hexdocs.pm/ash_neo4j/changelog.html Runs bulk update and destroy operations as a single query via Ash.bulk_update/Ash.bulk_destroy with strategy: :atomic. ```elixir Ash.bulk_update ``` ```elixir Ash.bulk_destroy ``` -------------------------------- ### Get Neo4j Label (Bang Version) Source: https://hexdocs.pm/ash_neo4j/AshNeo4j.DataLayer.Domain.Info.html Retrieves the Neo4j label atom for node creation. Raises an error if retrieval fails. ```elixir neo4j_label!(dsl_or_extended) ``` -------------------------------- ### Create Spatial Index with Options Source: https://hexdocs.pm/ash_neo4j/changelog.html Creates a Neo4j spatial index with options for recreation or specifying a custom index name. The `recreate: true` option performs a DROP and CREATE operation. ```elixir AshNeo4j.Spatial.create_index(Place, [:pet, :home], recreate: true, name: "custom_index_name") ``` -------------------------------- ### Get Relationship from Source Attribute Source: https://hexdocs.pm/ash_neo4j/AshNeo4j.Resource.Info.html Returns the relationship associated with a specific source attribute, if one exists. Useful for attribute-level relationship introspection. ```elixir @spec relationship(Ash.Resource.t(), atom() | String.t()) :: tuple() | nil ``` -------------------------------- ### all_labels Source: https://hexdocs.pm/ash_neo4j/AshNeo4j.Resource.Info.html Returns the full list of labels written to the node on CREATE. The labels include the domain label, module label, base type label, and domain fragment label if applicable. ```APIDOC ## all_labels(resource) ### Description Returns the full list of labels written to the node on CREATE. Always starts with the domain label, followed by the module label, then any additional base type label from a resource fragment, then the domain fragment label if the domain uses `AshNeo4j.DataLayer.Domain`. For example, `DiffoExample.Access.Shelf` (using `BaseInstance` and a `Telco` domain fragment) returns `[:Access, :Shelf, :Instance, :Telco]`. ### Function Signature ```elixir @spec all_labels(Ash.Resource.t()) :: [atom()] | nil ``` ``` -------------------------------- ### Get Neo4j Skip Attributes (Unsafe) Source: https://hexdocs.pm/ash_neo4j/AshNeo4j.DataLayer.Info.html Retrieves an optional list of attributes not to be stored directly as node properties. Raises an error on failure. ```elixir @spec neo4j_skip!(dsl_or_extended :: module() | map()) :: [atom()] | no_return() ``` -------------------------------- ### run/1, run/2 Source: https://hexdocs.pm/ash_neo4j/AshNeo4j.Cypher.html Runs a given Cypher query against the Neo4j database. Supports queries with or without parameters. ```APIDOC ## run(query, params \\ nil) ### Description Runs a Cypher query against the connected Neo4j database. The `query` argument is a string containing the Cypher statement. An optional `params` argument can be provided as a map for parameterized queries. ### Method `AshNeo4j.Cypher.run(query)` `AshNeo4j.Cypher.run(query, params)` ### Parameters - **query** (string) - The Cypher query to execute. - **params** (map, optional) - A map of parameters to use with the query. ### Returns - `{result, _}` where `result` is typically `:ok` upon successful execution. The second element of the tuple is often related to query metadata or results, depending on the implementation details not fully specified here. ### Examples ```elixir # Example with a CREATE statement cypher = "CREATE (n:Actor {name: 'Bill Nighy', born: 1949, bafta_winner: true}) RETURN n" {result, _} = AshNeo4j.Cypher.run(cypher) # result is :ok # Example with a MATCH statement and parameters cypher = "MATCH (n:Actor {name: $name}) RETURN n" params = %{name: "Bill Nighy"} {result, _} = AshNeo4j.Cypher.run(cypher, params) # result is :ok ``` ``` -------------------------------- ### Get Neo4j Skip Attributes (Safe) Source: https://hexdocs.pm/ash_neo4j/AshNeo4j.DataLayer.Info.html Retrieves an optional list of attributes not to be stored directly as node properties. Returns :error on failure. ```elixir @spec neo4j_skip(dsl_or_extended :: module() | map()) :: {:ok, [atom()]} | :error ``` -------------------------------- ### Filtering and Sorting with Vector Cosine Distance Source: https://hexdocs.pm/ash_neo4j/AshNeo4j.Functions.VectorCosineDistance.html Example of using vector_cosine_distance to filter and sort query results. This expression works with both AshNeo4j and AshPostgres. ```elixir Ash.Query.filter(query, vector_cosine_distance(embedding, ^q) < 0.5) |> Ash.Query.sort({calc(vector_cosine_distance(embedding, ^q), type: :float), :asc}) |> Ash.Query.limit(10) ``` -------------------------------- ### Create Constraints for a Resource Source: https://hexdocs.pm/ash_neo4j/AshNeo4j.Constraint.html Use this to create all necessary uniqueness constraints for a resource, including its primary key and all defined identities. Statements include 'IF NOT EXISTS' for safe repeated execution. ```elixir AshNeo4j.Constraint.create_constraints(AssignmentRelationship) ``` -------------------------------- ### run/1 Source: https://hexdocs.pm/ash_neo4j/AshNeo4j.Cypher.html Runs some Cypher query. This is a convenience function for executing a pre-built Cypher query. ```APIDOC ## run(query) ### Description Runs some cypher. ### Parameters * **query**: The Cypher query to run. ``` -------------------------------- ### Get Node Relationship Source: https://hexdocs.pm/ash_neo4j/AshNeo4j.Resource.Info.html Retrieves a node relationship matching the edge label, direction, and destination label. Use when querying for specific relationship configurations. ```elixir @spec node_relationship(Ash.Resource.t(), atom(), atom(), atom()) :: tuple() | nil ``` ```elixir @spec node_relationship(Ash.Resource.t(), atom(), atom(), [atom()]) :: tuple() | nil ``` -------------------------------- ### Build AshNeo4j.Unknown Source: https://hexdocs.pm/ash_neo4j/AshNeo4j.Unknown.html Constructs a new AshNeo4j.Unknown. This function is used to stamp an unknown state with the query world, a reason, and optional context. ```elixir @spec new(module() | nil, atom() | struct(), term()) :: t() ``` -------------------------------- ### Get World Chain from Unknown Source: https://hexdocs.pm/ash_neo4j/AshNeo4j.Unknown.html Extracts the sequence of world frames that an AshNeo4j.Unknown has passed through, ordered from outermost to innermost. Layers without a world are omitted. ```elixir @spec world_chain(t()) :: [module()] ``` -------------------------------- ### Get Neo4j Relate Info (Unsafe) Source: https://hexdocs.pm/ash_neo4j/AshNeo4j.DataLayer.Info.html Retrieves an optional list of relationships as tuples of {relationship_name, edge_label, edge_direction, destination_label}. Raises an error on failure. ```elixir @spec neo4j_relate!(dsl_or_extended :: module() | map()) :: [{atom(), atom(), atom(), atom()}] | no_return() ``` -------------------------------- ### Get Neo4j Relate Info (Safe) Source: https://hexdocs.pm/ash_neo4j/AshNeo4j.DataLayer.Info.html Retrieves an optional list of relationships as tuples of {relationship_name, edge_label, edge_direction, destination_label}. Returns :error on failure. ```elixir @spec neo4j_relate(dsl_or_extended :: module() | map()) :: {:ok, [{atom(), atom(), atom(), atom()}]} | :error ``` -------------------------------- ### run/2 Source: https://hexdocs.pm/ash_neo4j/AshNeo4j.Cypher.html Runs a Cypher query with associated parameters. This function allows for parameterized queries, which is the recommended way to execute Cypher to prevent injection vulnerabilities. ```APIDOC ## run(cypher, params \\ %{}) ### Description Runs some cypher with parameters. ### Parameters * **cypher**: The Cypher query string. * **params**: A map of parameters to use in the query. ``` -------------------------------- ### Get Neo4j Guard Info (Unsafe) Source: https://hexdocs.pm/ash_neo4j/AshNeo4j.DataLayer.Info.html Retrieves an optional list of node relationships as tuples of {edge_label, edge_direction, destination_label}. Raises an error on failure. ```elixir @spec neo4j_guard!(dsl_or_extended :: module() | map()) :: [{atom(), atom(), atom()}] | no_return() ``` -------------------------------- ### Create AshNeo4j.Error.RequiresDynamicLabels Exception Source: https://hexdocs.pm/ash_neo4j/AshNeo4j.Error.RequiresDynamicLabels.html Use this function to create an instance of the `AshNeo4j.Error.RequiresDynamicLabels` exception without immediately raising it. This can be useful for logging or inspection purposes. ```elixir exception(args :: Keyword.t()) :: %AshNeo4j.Error.RequiresDynamicLabels{ __exception__: term(), bread_crumbs: term(), class: term(), path: term(), splode: term(), stacktrace: term(), vars: term() } ``` -------------------------------- ### Get Neo4j Guard Info (Safe) Source: https://hexdocs.pm/ash_neo4j/AshNeo4j.DataLayer.Info.html Retrieves an optional list of node relationships as tuples of {edge_label, edge_direction, destination_label}. Returns :error on failure. ```elixir @spec neo4j_guard(dsl_or_extended :: module() | map()) :: {:ok, [{atom(), atom(), atom()}]} | :error ``` -------------------------------- ### Define Product Resource with UUID Primary Key and Unique SKU Identity Source: https://hexdocs.pm/ash_neo4j/managing_schema.html Define a Product resource using Ash Neo4j. It features a UUID primary key and a single-attribute identity for SKU uniqueness. ```elixir defmodule Schema.Product do use Ash.Resource, domain: Schema.Domain, data_layer: AshNeo4j.DataLayer neo4j do label :Product end attributes do uuid_primary_key :id attribute :sku, :string, allow_nil?: false, public?: true attribute :name, :string, public?: true end identities do # a single-attribute identity → one uniqueness constraint identity :unique_sku, [:sku] end end ``` -------------------------------- ### Render Cypher Query to String and Parameters Source: https://hexdocs.pm/ash_neo4j/AshNeo4j.Cypher.html Renders a `%Cypher.Query{}` struct into a `{cypher_string, params}` tuple. Useful for executing generated queries. ```elixir iex> query = %AshNeo4j.Cypher.Query{ ...> clauses: [ ...> %AshNeo4j.Cypher.Match{pattern: "(s:Actor)"}, ...> %AshNeo4j.Cypher.Return{items: ["s"]}, ...> %AshNeo4j.Cypher.Limit{value: 5} ...> ], ...> params: %{} ...> } iex> AshNeo4j.Cypher.render(query) {"MATCH (s:Actor) RETURN s LIMIT 5", %{}} ``` ```elixir iex> query = %AshNeo4j.Cypher.Query{ ...> clauses: [ ...> %AshNeo4j.Cypher.Call{ ...> branches: [ ...> "MATCH (s:Place) WHERE s.uuid = $b0_s_uuid_0 RETURN s", ...> "MATCH (s:Place) WHERE s.uuid = $b1_s_uuid_0 RETURN s" ...> ], ...> union_type: :union_all ...> }, ...> %AshNeo4j.Cypher.OptionalMatch{pattern: "(s)-[r]-(d)"}, ...> %AshNeo4j.Cypher.Return{items: ["s", "r", "d"]} ...> ], ...> params: %{"b0_s_uuid_0" => "x", "b1_s_uuid_0" => "y"} ...> } iex> {cypher, _params} = AshNeo4j.Cypher.render(query) iex> cypher "CALL { MATCH (s:Place) WHERE s.uuid = $b0_s_uuid_0 RETURN s UNION ALL MATCH (s:Place) WHERE s.uuid = $b1_s_uuid_0 RETURN s } OPTIONAL MATCH (s)-[r]-(d) RETURN s, r, d" ```