test_neo4j v0.1.0 TestNeo4j
Top-level module used in "Property graphs and Elixir" post.
The post shows how to access Neo4j graph databases with Elixir using the bolt_sips package.
Link to this section Summary
Functions
Reads a Books
graph from the graphs library
Deletes all nodes and relationships in database
Opens up a Bolt database connection with the app config
Reads a Movies
graph from the graphs library
Queries database for one node
Queries database for one node and relationships
Queries database for all nodes
Queries database for all nodes and relationships
Parses a graphgist to return a Cypher graph
Queries database for one path
Queries database for all paths
Reads a default Cypher graph from the graphs library
Reads a user Cypher graph from the graphs library
Reads a default graphgist from the graphgists library
Reads a user graphgist from the graphgists library
Reads a default Cypher query from the queries library
Reads a named Cypher query from the queries library
Queries database for one relationship
Queries database for all relationships
Deletes all nodes and relationships in database
Counts nodes, relationships and paths in database
Link to this section Functions
books()
Reads a Books
graph from the graphs library.
Examples
iex> books()
"//\n// create nodes\n//\nCREATE\n(book:Book {\n iri: " <> ...
clear(conn)
Deletes all nodes and relationships in database.
Examples
iex> conn |> reset()
%{stats: %{"nodes-deleted" => 171, "relationships-deleted" => 253}, type: "w"}
init()
Opens up a Bolt database connection with the app config.
Examples
iex> 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"]
]
movies()
Reads a Movies
graph from the graphs library.
Examples
iex> movies()
"CREATE (TheMatrix:Movie {title:'The Matrix', released:1999," <> ...
node1(conn)
Queries database for one node.
Examples
iex> conn |> node1()
[
%{
"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"
}
}
}
]
node1_and_relationships(conn)
Queries database for one node and relationships.
Examples
iex> conn |> node1_and_relationships()
[
%{
"n" => %Bolt.Sips.Types.Node{
id: 1548,
labels: ["Author"],
properties: %{"iri" => "https://twitter.com/josevalim"}
},
"r" => %Bolt.Sips.Types.Relationship{
end: 1548,
id: 1689,
properties: %{"role" => "second author"},
start: 1546,
type: "AUTHORED_BY"
}
},
...
]
nodes(conn)
Queries database for all nodes.
Examples
iex> conn |> nodes()
[
%{
"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"
}
}
},
...
]
nodes_and_relationships(conn)
Queries database for all nodes and relationships.
Examples
iex> conn |> 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"
}
},
...
]
parse(graphgist)
Parses a graphgist to return a Cypher graph.
Examples
iex> parse(read_graphgist())
"CREATE\n (a:Person {name: 'Alice'}),\n (b:Person {name: 'Bob'}),\n" <> ...
path1(conn)
Queries database for one path.
Examples
iex> conn |> path1()
[
%{
"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]
}
}
]
paths(conn)
Queries database for all paths.
Examples
iex> conn |> 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]
}
},
...
]
read_graph()
Reads a default Cypher graph from the graphs library.
Examples
iex> read_graph()
"//\n// create nodes\n//\nCREATE\n(book:Book {\n iri: " <> ...
read_graph(graph_file)
Reads a user Cypher graph from the graphs library.
Examples
iex> read_graph("books.cypher")
"//\n// create nodes\n//\nCREATE\n(book:Book {\n iri: " <> ...
read_graphgist()
Reads a default graphgist from the graphgists library.
Examples
iex> read_graphgist()
"= REPLACEME: TITLE OF YOUR GRAPHGIST\n:neo4j-version: 2.3.0\n:author:" <> ...
read_graphgist(graphgist_file)
Reads a user graphgist from the graphgists library.
Examples
iex> read_graphgist("template.adoc")
"= REPLACEME: TITLE OF YOUR GRAPHGIST\n:neo4j-version: 2.3.0\n:author:" <> ...
read_query()
Reads a default Cypher query from the queries library.
Examples
iex> read_query()
"match (n) return n limit 1\n"
read_query(query_file)
Reads a named Cypher query from the queries library.
Examples
iex> read_query("nodes.cypher")
"match (n) return n\n"
relationship1(conn)
Queries database for one relationship.
Examples
iex> conn |> relationship1()
[
%{
"r" => %Bolt.Sips.Types.Relationship{
end: 1548,
id: 1689,
properties: %{"role" => "second author"},
start: 1546,
type: "AUTHORED_BY"
}
}
]
relationships(conn)
Queries database for all relationships.
Examples
iex> conn |> relationships()
[
%{
"r" => %Bolt.Sips.Types.Relationship{
end: 1548,
id: 1689,
properties: %{"role" => "second author"},
start: 1546,
type: "AUTHORED_BY"
}
},
...
]
reset(conn)
Deletes all nodes and relationships in database.
Examples
iex> conn |> reset()
%{stats: %{"nodes-deleted" => 171, "relationships-deleted" => 253}, type: "w"}
test(conn)
Counts nodes, relationships and paths in database.
Examples
iex> conn |> test()
[%{"nodes" => 171, "paths" => 506, "relationships" => 253}]