test_match v0.1.0 TestMatch.LPG.Cypher.Client
Module providing a simple library for querying LPG models in a Neo4j instance via Cypher.
Link to this section Summary
Functions
Deletes all nodes and relationships in database.
Returns a default Cypher query.
Returns a Cypher query from query_file
.
Dumps all nodes and relationships in database.
Dumps all nodes and relationships in database.
Opens up a Bolt database connection with the app config.
Queries database for one node.
Queries database for one node and relationships.
Queries database for node by id
.
Queries database for one node ID.
Queries database for limit
number of node IDs. If no limit
is given then all node IDs are retuned.
Queries database for limit
number of nodes. If no limit
is given then all nodes are retuned.
Queries database for limit
number of nodes and relationships. If no limit
is given then all nodes and relationships are retuned.
Queries database for one path.
Queries database for limit
number of paths. If no limit
is given then all paths are retuned.
Queries database for one relationship.
Queries database for relationship by id
.
Queries database for one relationship ID.
Queries database for limit
number of relationship IDs. If no limit
is given then all relationship IDs are retuned.
Queries database for limit
number of relationships. If no limit
is given then all relationships are retuned.
Deletes all nodes and relationships in database.
Queries Bolt connection with Cypher query.
The same as rquery/1
but raises a runtime error if it fails.
Counts nodes, relationships and paths in database.
Link to this section Functions
clear()
Deletes all nodes and relationships in database.
Examples
iex> Cypher_Client.clear()
%{stats: %{"nodes-deleted" => 171, "relationships-deleted" => 253}, type: "w"}
cypher_query()
Returns a default Cypher query.
cypher_query(query_file)
Returns a Cypher query from query_file
.
dump(graph_file)
Dumps all nodes and relationships in database.
Examples
iex(3)> Cypher_Client.dump("nobelprizes.cypher")
[
%{
"batchSize" => 20000,
"batches" => 4,
"cleanupStatements" => nil,
"cypherStatements" => nil,
"file" => ".../test_match/priv/lpg/graphs/nobelprizes.cypher",
"format" => "cypher",
"nodeStatements" => nil,
"nodes" => 21027,
"properties" => 49184,
"relationshipStatements" => nil,
"relationships" => 43267,
"rows" => 64294,
"schemaStatements" => nil,
"source" => "database: nodes(21027), rels(43267)",
"time" => 949
}
]
dump(query_file, graph_file)
Dumps all nodes and relationships in database.
Examples
iex(3)> cypher_dump("match (n) return n limit 3", "limit3.cypher")
[
%{
"batchSize" => 20000,
"batches" => 1,
"cleanupStatements" => nil,
"cypherStatements" => nil,
"file" => ".../test_match/priv/lpg/graphs/limit3.cypher",
"format" => "cypher",
"nodeStatements" => nil,
"nodes" => 3,
"properties" => 3,
"relationshipStatements" => nil,
"relationships" => 0,
"rows" => 3,
"schemaStatements" => nil,
"source" => "statement: nodes(3), rels(0)",
"time" => 1
}
]
init()
Opens up a Bolt database connection with the app config.
Examples
iex> Cypher_Client.init()
[
socket: Bolt.Sips.Socket,
port: 7687,
hostname: 'localhost',
retry_linear_backoff: [delay: 150, factor: 2, tries: 3],
with_etls: false,
ssl: false,
timeout: 15000,
max_overflow: 2,
pool_size: 5,
url: "bolt://localhost:7687",
basic_auth: [username: "neo4j", password: "neo4jtest"]
]
node1()
Queries database for one node.
node1_and_relationships()
Queries database for one node and relationships.
node_by_id(id)
Queries database for node by id
.
Examples
iex> Cypher_Client.node_by_id(311)
[
%{
"n" => %Bolt.Sips.Types.Node{
id: 311,
labels: ["Book"],
properties: %{}
}
},
]
node_id1()
Queries database for one node ID.
node_ids(limit \\ nil)
Queries database for limit
number of node IDs. If no limit
is given then all node IDs are retuned.
Examples
iex> Cypher_Client.node_ids()
[
%{"id(n)" => 1804},
%{"id(n)" => 1805},
%{"id(n)" => 1806},
%{"id(n)" => 1807},
%{"id(n)" => 6277}
]
nodes(limit \\ nil)
Queries database for limit
number of nodes. If no limit
is given then all nodes are retuned.
Examples
iex> Cypher_Client.nodes(2)
[
%{
"n" => %Bolt.Sips.Types.Node{
id: 311,
labels: ["Book"],
properties: %{}
}
},
%{
"n" => %Bolt.Sips.Types.Node{
id: 312,
labels: ["Book"],
properties: %{}
}
}
]
nodes_and_relationships(limit \\ nil)
Queries database for limit
number of nodes and relationships. If no limit
is given then all nodes and relationships are retuned.
Examples
iex> Cypher_Client.nodes_and_relationships()
[
%{
"n" => %Bolt.Sips.Types.Node{
id: 1546,
labels: ["Book"],
properties: %{
"date" => "2018-03-14",
"format" => "Paper",
"iri" => "urn:isbn:978-1-68050-252-7",
"title" => "Adopting Elixir"
}
},
"r" => %Bolt.Sips.Types.Relationship{
end: 1548,
id: 1689,
properties: %{"role" => "second author"},
start: 1546,
type: "AUTHORED_BY"
}
},
...
]
path1()
Queries database for one path.
paths(limit \\ nil)
Queries database for limit
number of paths. If no limit
is given then all paths are retuned.
Examples
iex> Cypher_Client.paths()
[
%{
"p" => %Bolt.Sips.Types.Path{
nodes: [
%Bolt.Sips.Types.Node{
id: 1548,
labels: ["Author"],
properties: %{"iri" => "https://twitter.com/josevalim"}
},
%Bolt.Sips.Types.Node{
id: 1546,
labels: ["Book"],
properties: %{
"date" => "2018-03-14",
"format" => "Paper",
"iri" => "urn:isbn:978-1-68050-252-7",
"title" => "Adopting Elixir"
}
}
],
relationships: [
%Bolt.Sips.Types.UnboundRelationship{
end: nil,
id: 1689,
properties: %{"role" => "second author"},
start: nil,
type: "AUTHORED_BY"
}
],
sequence: [-1, 1]
}
},
...
]
relationship1()
Queries database for one relationship.
relationship_by_id(id)
Queries database for relationship by id
.
Examples
iex> Cypher_Client.relationship_by_id(9265)
[
%{
"r" => %Bolt.Sips.Types.Relationship{
end: 1786,
id: 9265,
properties: %{},
start: 1783,
type: "ns0__license"
}
}
]
relationship_id1()
Queries database for one relationship ID.
relationship_ids(limit \\ nil)
Queries database for limit
number of relationship IDs. If no limit
is given then all relationship IDs are retuned.
Examples
iex> Cypher_Client.relationship_ids()
[
%{"id(n)" => 1804},
%{"id(n)" => 1805},
%{"id(n)" => 1806},
%{"id(n)" => 1807},
%{"id(n)" => 6277}
]
relationships(limit \\ nil)
Queries database for limit
number of relationships. If no limit
is given then all relationships are retuned.
Examples
iex> Cypher_Client.relationships()
[
%{
"r" => %Bolt.Sips.Types.Relationship{
end: 1548,
id: 1689,
properties: %{"role" => "second author"},
start: 1546,
type: "AUTHORED_BY"
}
},
...
]
reset()
Deletes all nodes and relationships in database.
Examples
iex> Cypher_Client.reset()
%{stats: %{"nodes-deleted" => 171, "relationships-deleted" => 253}, type: "w"}
rquery(cypher_query \\ cypher_query())
Queries Bolt connection with Cypher query.
Examples
iex> Cypher_Client.rquery("match (n) return n limit 1")
{:ok,
[
%{
"n" => %Bolt.Sips.Types.Node{
id: 919,
labels: ["Resource"],
properties: %{
"rdfs__label" => "Hello World",
"uri" => "http://dbpedia.org/resource/Hello_World"
}
}
}
]}
rquery!(cypher_query \\ cypher_query())
The same as rquery/1
but raises a runtime error if it fails.
Examples
iex> Cypher_Client.rquery!("match (n) return n limit 1")
[
%{
"n" => %Bolt.Sips.Types.Node{
id: 919,
labels: ["Resource"],
properties: %{
"rdfs__label" => "Hello World",
"uri" => "http://dbpedia.org/resource/Hello_World"
}
}
}
]
test()
Counts nodes, relationships and paths in database.
Examples
iex> Cypher_Client.test()
[%{"nodes" => 171, "paths" => 506, "relationships" => 253}]