AshNeo4j.Neo4jHelper (AshNeo4j v0.2.6)
View SourceAshNeo4j DataLayer Neo4j Helper
Summary
Functions
Creates a neo4j node with label and properties
Creates source neo4j node with label, properties and relationship to an existing node
Creates source neo4j node with label, properties and relationships to existing nodes
Delete all neo4j nodes and relationships
Delete neo4j nodes
Merges a neo4j node with label and properties
Tests if two nodes are related with a relationship type ## Examples
Reads limited nodes from Neo4j, given label, limit and optionally properties
Reads nodes from Neo4j, given label, and optionally properties
Relates two nodes with a relationship type, merging relationship ## Examples
Delete neo4j nodes
Unrelates two nodes with a relationship type ## Examples
Updates neo4j node properties
Functions
@spec create_node(atom(), map()) :: {:error, %{:__exception__ => true, :__struct__ => atom(), optional(atom()) => any()}} | {:ok, any()}
Creates a neo4j node with label and properties
Examples
iex> {result, _} = AshNeo4j.Neo4jHelper.create_node(:Actor, %{name: "Bill Nighy"})
iex> result
:ok
Creates source neo4j node with label, properties and relationship to an existing node
Examples
iex> AshNeo4j.Neo4jHelper.create_node(:Movie, %{title: "Love Actually"})
iex> {result, _} = AshNeo4j.Neo4jHelper.create_node_with_relationship(:Actor, %{name: "Keira Knightley"}, :Movie, %{title: "Love Actually"}, :ACTED_IN, :outgoing)
iex> result
:ok
Creates source neo4j node with label, properties and relationships to existing nodes
Examples
iex> AshNeo4j.Neo4jHelper.create_node(:Movie, %{title: "Love Actually"})
iex> AshNeo4j.Neo4jHelper.create_node(:Movie, %{title: "Bend it Like Beckham"})
iex> {result, _} = AshNeo4j.Neo4jHelper.create_node_with_relationships(:Actor, %{name: "Bill Nighy"}, [{:Movie, %{title: "Love Actually"}, :ACTED_IN, :outgoing}])
iex> result
:ok
iex> {result, _} = AshNeo4j.Neo4jHelper.create_node_with_relationships(:Actor, %{name: "Keira Knightley"}, [{:Movie, %{title: "Love Actually"}, :ACTED_IN, :outgoing}, {:Movie, %{title: "Bend it Like Beckham"}, :ACTED_IN, :outgoing}])
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 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> 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
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
Delete neo4j nodes
Examples
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_with_relationships(:Actor, %{name: "Keira Knightley"}, [{:Movie, %{title: "Love Actually"}, :ACTED_IN, :outgoing}, {:Movie, %{title: "Bend it Like Beckham"}, :ACTED_IN, :outgoing}])
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
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