AshNeo4j.Neo4jHelper (AshNeo4j v0.2.6)

View Source

AshNeo4j 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

Merges a neo4j node with label and properties

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

Functions

create_node(label, properties)

@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

create_node_with_relationship(label, properties, dest_label, dest_properties, edge_label, edge_direction)

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

create_node_with_relationships(label, properties, relationships)

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

delete_all()

@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_nodes(label, properties \\ %{})

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

merge_node(label, properties)

@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

nodes_relate_how?(source_label, source_properties, dest_label, dest_properties, edge_label, edge_direction)

@spec nodes_relate_how?(atom(), map(), atom(), map(), atom(), atom()) ::
  :error | false | true

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

read_limited(label, limit, properties \\ %{})

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

read_nodes(label, properties \\ %{})

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

relate_nodes(source_label, source_properties, dest_label, dest_properties, edge_label, edge_direction)

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

safe_delete_nodes(label, properties, relationships)

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

unrelate_nodes(source_label, source_properties, dest_label, dest_properties, edge_label, edge_direction)

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

update_node(label, match_properties, set_properties, remove_properties \\ [])

@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