AshNeo4j DataLayer Neo4j Helper
Summary
Functions
Creates a neo4j node with labels and properties
Delete all neo4j nodes and relationships
Delete neo4j nodes
Merges a neo4j node with label and properties
Tests if two nodes are related by traversal ## Examples
Tests if two nodes are directly related ## Examples
Reads limited nodes from Neo4j, given label, limit and optionally properties
Reads nodes from Neo4j, given label, and optionally properties
Reads nodes from Neo4j, returning any related nodes
Creates source neo4j node with label, properties and relationships to existing nodes
Relates two nodes with a relationship type, merging relationship ## Examples
Relates two nodes unrelating the destination node from any similar relationships ## Examples
Relates two nodes unrelating the source node from any similar relationships ## Examples
Relates two nodes unrelating the source and destination node from any similar relationships ## Examples
Safely delete neo4j nodes, delete is guarded by relationships
Unrelates two nodes with a relationship type ## Examples
Updates neo4j node properties
Functions
Creates a neo4j node with labels and properties
Examples
iex> {result, _} = AshNeo4j.Neo4jHelper.create_node([:Cinema, :Actor], %{name: "Bill Nighy"})
iex> result
:ok
@spec delete_all() :: {:error, %{:__exception__ => true, :__struct__ => atom(), optional(atom()) => any()}} | {:ok, any()}
Delete all neo4j nodes and relationships
Examples
iex> {result, _} = AshNeo4j.Neo4jHelper.delete_all()
iex> result
:ok
Delete neo4j nodes
Examples
iex> {result, _} = AshNeo4j.Neo4jHelper.delete_nodes(:Actor)
iex> result
:ok
iex> AshNeo4j.Neo4jHelper.create_node([:Actor], %{name: "Bill Nighy"})
iex> {result, _} = AshNeo4j.Neo4jHelper.delete_nodes(:Actor, %{name: "Bill Nighy"})
iex> result
:ok
@spec merge_node(atom(), map()) :: {:error, %{:__exception__ => true, :__struct__ => atom(), optional(atom()) => any()}} | {:ok, any()}
Merges a neo4j node with label and properties
Examples
iex> {result, _} = AshNeo4j.Neo4jHelper.merge_node(:Actor, %{name: "Bill Nighy", born: 1949})
iex> result
:ok
Tests if two nodes are related by traversal ## Examples
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"})
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)
iex> AshNeo4j.Neo4jHelper.nodes_relate_how?(:Actor, %{name: "Bill Nighy"}, :Actor, %{name: "Keira Knightley"}, [ACTED_IN: :outgoing, ACTED_IN: :incoming])
true
Tests if two nodes are directly related ## Examples
iex> AshNeo4j.Neo4jHelper.create_node([:Actor], %{name: "Bill Nighy", born: 1949})
iex> AshNeo4j.Neo4jHelper.create_node([:Movie], %{title: "Love Actually"})
iex> AshNeo4j.Neo4jHelper.relate_nodes(:Actor, %{name: "Bill Nighy"}, :Movie, %{title: "Love Actually"}, :ACTED_IN, :outgoing)
iex> AshNeo4j.Neo4jHelper.nodes_relate_how?(:Actor, %{name: "Bill Nighy"}, :Movie, %{title: "Love Actually"}, :ACTED_IN, :outgoing)
true
Reads limited nodes from Neo4j, given label, limit and optionally properties
Examples
iex> AshNeo4j.Neo4jHelper.create_node([:Actor], %{name: "Bill Nighy", born: 1949})
iex> {:ok, %{records: records}} = AshNeo4j.Neo4jHelper.read_limited(:Actor, 1)
iex> length(records)
1
Reads nodes from Neo4j, given label, and optionally properties
Examples
iex> AshNeo4j.Neo4jHelper.create_node([:Actor], %{name: "Bill Nighy", born: 1949})
iex> {:ok, %{records: records}} = AshNeo4j.Neo4jHelper.read_nodes(:Actor, %{name: "Bill Nighy"})
iex> length(records)
1
Creates source neo4j node with label, properties and relationships to existing nodes
Examples
iex> AshNeo4j.Neo4jHelper.create_node([:Actor], %{title: "Bill Nighy"})
iex> AshNeo4j.Neo4jHelper.create_node([:Actor], %{title: "Keira Knightley"})
iex> AshNeo4j.Neo4jHelper.create_node([:Movie], %{title: "Love Actually"})
iex> AshNeo4j.Neo4jHelper.create_node([:Movie], %{title: "Bend it Like Beckham"})
iex> AshNeo4j.Neo4jHelper.create_node([:Movie], %{title: "The Immitation Game"})
iex> :ok = AshNeo4j.Neo4jHelper.relate_nodes(:Actor, %{name: "Bill Nighy"}, [{:Movie, %{title: "Love Actually"}, :ACTED_IN, :outgoing, false}])
iex> :ok = AshNeo4j.Neo4jHelper.relate_nodes(:Actor, %{name: "Keira Knightley"}, [{:Movie, %{title: "Love Actually"}, :ACTED_IN, :outgoing, false}, {:Movie, %{title: "Bend it Like Beckham"}, :ACTED_IN, :outgoing, false}])
@spec relate_nodes(atom(), map(), atom(), map(), atom(), atom()) :: {:error, %{:__exception__ => true, :__struct__ => atom(), optional(atom()) => any()}} | {:ok, any()}
Relates two nodes with a relationship type, merging relationship ## Examples
iex> AshNeo4j.Neo4jHelper.create_node([:Actor], %{name: "Bill Nighy", born: 1949})
iex> AshNeo4j.Neo4jHelper.create_node([:Movie], %{title: "Love Actually"})
iex> {result, _} = AshNeo4j.Neo4jHelper.relate_nodes(:Actor, %{name: "Bill Nighy"}, :Movie, %{title: "Love Actually"}, :ACTED_IN, :outgoing)
iex> result
:ok
@spec relate_nodes_unrelating_destination( atom(), map(), atom(), map(), atom(), atom() ) :: {:error, %{:__exception__ => true, :__struct__ => atom(), optional(atom()) => any()}} | {:ok, any()}
Relates two nodes unrelating the destination node from any similar relationships ## Examples
iex> AshNeo4j.Neo4jHelper.create_node([:Fan], %{name: "Matt"})
iex> AshNeo4j.Neo4jHelper.create_node([:Movie], %{title: "Love Actually"})
iex> AshNeo4j.Neo4jHelper.create_node([:Movie], %{title: "Bend it Like Beckham"})
iex> AshNeo4j.Neo4jHelper.relate_nodes(:Fan, %{name: "Matt"}, :Movie, %{title: "Love Actually"}, :FAVOURITE, :outgoing)
iex> {result, _} = AshNeo4j.Neo4jHelper.relate_nodes_unrelating_destination(:Movie, %{title: "Bend it Like Beckham"}, :Fan, %{name: "Matt"}, :FAVOURITE, :incoming)
iex> result
:ok
@spec relate_nodes_unrelating_source(atom(), map(), atom(), map(), atom(), atom()) :: {:error, %{:__exception__ => true, :__struct__ => atom(), optional(atom()) => any()}} | {:ok, any()}
Relates two nodes unrelating the source node from any similar relationships ## Examples
iex> AshNeo4j.Neo4jHelper.create_node([:Fan], %{name: "Matt"})
iex> AshNeo4j.Neo4jHelper.create_node([:Movie], %{title: "Love Actually"})
iex> AshNeo4j.Neo4jHelper.create_node([:Movie], %{title: "Bend it Like Beckham"})
iex> AshNeo4j.Neo4jHelper.relate_nodes(:Fan, %{name: "Matt"}, :Movie, %{title: "Love Actually"}, :FAVOURITE, :outgoing)
iex> {result, _} = AshNeo4j.Neo4jHelper.relate_nodes_unrelating_source(:Fan, %{name: "Matt"}, :Movie, %{title: "Bend it Like Beckham"}, :FAVOURITE, :outgoing)
iex> result
:ok
@spec relate_nodes_unrelating_source_and_destination( atom(), map(), atom(), map(), atom(), atom() ) :: {:error, %{:__exception__ => true, :__struct__ => atom(), optional(atom()) => any()}} | {:ok, any()}
Relates two nodes unrelating the source and destination node from any similar relationships ## Examples
iex> AshNeo4j.Neo4jHelper.create_node([:Person], %{name: "Marlo"})
iex> AshNeo4j.Neo4jHelper.create_node([:Person], %{name: "Harry"})
iex> AshNeo4j.Neo4jHelper.create_node([:Person], %{name: "Marion"})
iex> AshNeo4j.Neo4jHelper.create_node([:Person], %{name: "Robin"})
iex> AshNeo4j.Neo4jHelper.relate_nodes(:Person, %{name: "Marlo"}, :Person, %{name: "Harry"}, :PARTNER, :outgoing)
iex> AshNeo4j.Neo4jHelper.relate_nodes(:Person, %{name: "Marion"}, :Person, %{name: "Robin"}, :PARTNER, :outgoing)
iex> {result, _} = AshNeo4j.Neo4jHelper.relate_nodes_unrelating_source_and_destination(:Person, %{name: "Marlo"}, :Person, %{name: "Robin"}, :PARTNER, :outgoing)
iex> result
:ok
Safely delete neo4j nodes, delete is guarded by relationships
Examples
iex> AshNeo4j.Neo4jHelper.create_node([:Actor], %{name: "Keira Knightley"})
iex> AshNeo4j.Neo4jHelper.create_node([:Movie], %{title: "Love Actually"})
iex> AshNeo4j.Neo4jHelper.create_node([:Movie], %{title: "Bend it Like Beckham"})
iex> AshNeo4j.Neo4jHelper.relate_nodes(:Actor, %{name: "Keira Knightley"}, [{:Movie, %{title: "Love Actually"}, :ACTED_IN, :outgoing, false},
...> {:Movie, %{title: "Bend it Like Beckham"}, :ACTED_IN, :outgoing, false}])
iex> {result, _} = AshNeo4j.Neo4jHelper.safe_delete_nodes(:Actor, %{name: "Keira Knightley"}, [{:ACTED_IN, :outgoing, :Movie}, {:LIVES_AT, :outgoing, :Place}])
iex> result
:error
iex> {result, _} = AshNeo4j.Neo4jHelper.safe_delete_nodes(:Actor, %{name: "Keira Knightley"}, [{:LIVES_AT, :outgoing, :Place}])
iex> result
:ok
@spec unrelate_nodes(atom(), map(), atom(), map(), atom(), atom()) :: {:error, %{:__exception__ => true, :__struct__ => atom(), optional(atom()) => any()}} | {:ok, any()}
Unrelates two nodes with a relationship type ## Examples
iex> AshNeo4j.Neo4jHelper.create_node([:Actor], %{name: "Bill Nighy", born: 1949})
iex> AshNeo4j.Neo4jHelper.create_node([:Movie], %{title: "Love Actually"})
iex> AshNeo4j.Neo4jHelper.relate_nodes(:Actor, %{name: "Bill Nighy"}, :Movie, %{title: "Love Actually"}, :ACTED_IN, :outgoing)
iex> {result, _} = AshNeo4j.Neo4jHelper.unrelate_nodes(:Actor, %{name: "Bill Nighy"}, :Movie, %{title: "Love Actually"}, :ACTED_IN, :outgoing)
iex> result
:ok
@spec update_node(atom(), map(), map(), list()) :: {:error, %{:__exception__ => true, :__struct__ => atom(), optional(atom()) => any()}} | {:ok, any()}
Updates neo4j node properties
Examples
iex> AshNeo4j.Neo4jHelper.create_node([:Actor], %{name: "Bill Nighy"})
iex> {result, _} = AshNeo4j.Neo4jHelper.update_node(:Actor, %{name: "Bill Nighy"}, %{born: 1949})
iex> result
:ok