Bolt.Sips v1.0.0-rc2 Bolt.Sips View Source
A Neo4j Elixir driver wrapped around the Bolt protocol.
Link to this section Summary
Functions
Returns a specification to start this module under a supervisor
returns an environment specific Bolt.Sips configuration
Returns a pool name which can be used to acquire a connection
The same as query/2 but raises a Bolt.Sips.Exception if it fails. Returns the server response otherwise
The same as query/3 but raises a Bolt.Sips.Exception if it fails
sends the query (and its parameters) to the server and returns {:ok, Bolt.Sips.Response}
or
{:error, error}
otherwise
send a query and an associated map of parameters. Returns the server response or an error
Rollback a database transaction and release lock on connection
Start the connection process and connect to Neo4j
Link to this section Types
Link to this section Functions
Returns a specification to start this module under a supervisor.
See Supervisor
.
returns an environment specific Bolt.Sips configuration.
Returns a pool name which can be used to acquire a connection.
The same as query/2 but raises a Bolt.Sips.Exception if it fails. Returns the server response otherwise.
The same as query/3 but raises a Bolt.Sips.Exception if it fails.
sends the query (and its parameters) to the server and returns {:ok, Bolt.Sips.Response}
or
{:error, error}
otherwise
send a query and an associated map of parameters. Returns the server response or an error
rollback(DBConnection.t(), reason :: any()) :: no_return()
Rollback a database transaction and release lock on connection.
When inside of a transaction/3
call does a non-local return, using a
throw/1
to cause the transaction to enter a failed state and the
transaction/3
call returns {:error, reason}
. If transaction/3
calls are
nested the connection is marked as failed until the outermost transaction call
does the database rollback.
Example
{:error, :oops} = Bolt.Sips.transaction(pool, fun(conn) ->
Bolt.Sips.rollback(conn, :oops)
end)
Start the connection process and connect to Neo4j
Options:
:url
- If present, it will be used for extracting the host name, the port and the authentication details and will override the: hostname, port, username and the password, if these were already defined! Since this driver is devoted to the Bolt protocol only, the protocol if present in the url will be ignored and considered by defaultbolt://
:hostname
- Server hostname (default: NEO4J_HOST env variable, then localhost);:port
- Server port (default: NEO4J_PORT env variable, then 7687);:username
- Username;:password
- User password;:pool_size
- maximum pool size;:max_overflow
- maximum number of workers created if pool is empty:timeout
- Connect timeout in milliseconds (default:15000
):retry_linear_backoff
- with Bolt, the initial handshake sequence (happening before sending any commands to the server) is represented by two important calls, executed in sequence:handshake
andinit
, and they must both succeed, before sending any (Cypher) requests. You can see the details in the Bolt protocol specs. This sequence is also sensitive to latencies, such as: network latencies, busy servers, etc., and because of that we’re introducing a simple support for retrying the handshake (and the subsequent requests) with a linear backoff, and try the handshake sequence (or the request) a couple of times before giving up. See examples below.
Example of valid configurations (i.e. defined in config/dev.exs) and usage:
config :bolt_sips, Bolt,
url: 'bolt://demo:demo@hobby-wowsoeasy.dbs.graphenedb.com:24786',
ssl: true
config :bolt_sips, Bolt,
url: "bolt://Bilbo:Baggins@hobby-hobbits.dbs.graphenedb.com:24786",
ssl: true,
timeout: 15_000,
retry_linear_backoff: [delay: 150, factor: 2, tries: 3]
config :bolt_sips, Bolt,
hostname: 'localhost',
basic_auth: [username: "neo4j", password: "*********"],
port: 7687,
pool_size: 5,
max_overflow: 1
Sample code:
opts = Application.get_env(:bolt_sips, Bolt)
{:ok, pid} = Bolt.Sips.start_link(opts)
Bolt.Sips.query!(pid, "CREATE (a:Person {name:'Bob'})")
Bolt.Sips.query!(pid, "MATCH (a:Person) RETURN a.name AS name")
|> Enum.map(&(&1["name"]))
transaction(DBConnection.t(), (DBConnection.t() -> result), opts :: Keyword.t()) :: {:ok, result} | {:error, reason :: any()} when result: var
Example:
setup do
{:ok, [main_conn: Bolt.Sips.conn()]}
end
test "execute statements in transaction", %{main_conn: main_conn} do
Bolt.Sips.transaction(main_conn, fn conn ->
book =
Bolt.Sips.query!(conn, "CREATE (b:Book {title: "The Game Of Trolls"}) return b")
|> List.first()
assert %{"b" => g_o_t} = book
assert g_o_t.properties["title"] == "The Game Of Trolls"
Bolt.Sips.rollback(conn, :changed_my_mind)
end)
books = Bolt.Sips.query!(main_conn, "MATCH (b:Book {title: "The Game Of Trolls"}) return b")
assert length(books) == 0
end