AshNeo4j.Cypher (AshNeo4j v0.1.1)

View Source

Ash Neo4j cypher functions

Summary

Functions

Converts a node variable, label and optional properties to cypher expression

Converts a node variable, label and optional properties to cypher node.

Converts a map to a cypher properties string. The map is converted to a string in the format {key1: value1, key2: value2}. This is used to create nodes in Neo4j.

Converts a node_relationship tuple to cypher clause, ignoring the label

Converts a relationship variable, label and optional direction to cypher relationship.

Runs some cypher

Functions

expression(variable, left, operator, right)

Converts a node variable, label and optional properties to cypher expression

Examples

iex> AshNeo4j.Cypher.expression(:s, "name", "in", "[Bill Nighy]")
"s.name in [Bill Nighy]"
iex> AshNeo4j.Cypher.expression(:s, "name", "in", "[]")
"s.name IS NOT NULL"

node(variable, label, properties \\ %{})

Converts a node variable, label and optional properties to cypher node.

Examples

iex> AshNeo4j.Cypher.node(:s, :Actor)
"(s:Actor)"
iex> AshNeo4j.Cypher.node(:s, :Actor, %{name: "Bill Nighy"})
"(s:Actor {name: 'Bill Nighy'})"

properties(map)

Converts a map to a cypher properties string. The map is converted to a string in the format {key1: value1, key2: value2}. This is used to create nodes in Neo4j.

Examples

iex> AshNeo4j.Cypher.properties(%{name: "Bill Nighy", born: 1949, bafta_winner: true})
"{name: 'Bill Nighy', born: 1949, bafta_winner: true}"

relationship(node_relationship)

Converts a node_relationship tuple to cypher clause, ignoring the label

Examples

iex> AshNeo4j.Cypher.relationship({:movies, :ACTED_IN, :outgoing})
"-[r:ACTED_IN]->"
iex> AshNeo4j.Cypher.relationship(nil)
"-[r]-"

relationship(variable, label, direction \\ nil)

Converts a relationship variable, label and optional direction to cypher relationship.

Examples

iex> AshNeo4j.Cypher.relationship(:r, :ACTED_IN, :outgoing)
"-[r:ACTED_IN]->"
iex> AshNeo4j.Cypher.relationship(:r, :ACTED_IN, :incoming)
"<-[r:ACTED_IN]-"
iex> AshNeo4j.Cypher.relationship(:r, :KNOWS)
"-[r:KNOWS]-"

run(cypher)

Runs some cypher

Examples

iex> cypher = "CREATE (n:Actor {name: 'Bill Nighy', born: 1949, bafta_winner: true}) RETURN n"
iex> {result, _} = AshNeo4j.Cypher.run(cypher)
iex> result
:ok