Bolt.Sips v0.1.0 Bolt.Sips

A Neo4j Elixir driver wrapped around the Bolt protocol.

Summary

Functions

begin a new transaction

given you have an open transaction, you can use this to send a commit request

returns an environment specific Bolt.Sips configuration

returns a Bolt.Sips.Connection

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

The same as query/2 but raises a Bolt.Sips.Error if it fails. Returns the server response otherwise

The same as query/3 but raises a Bolt.Sips.Error if it fails

given that you have an open transaction, you can send a rollback request. The server will rollback the transaction. Any further statements trying to run in this transaction will fail immediately

Start the connection process and connect to Neo4j

Functions

begin(conn)

Specs

begin(Bolt.Sips.Connection) :: Bolt.Sips.Connection

begin a new transaction.

commit(conn)

Specs

commit(Bolt.Sips.Connection) :: Bolt.Sips.Response

given you have an open transaction, you can use this to send a commit request

config()

returns an environment specific Bolt.Sips configuration.

conn()

returns a Bolt.Sips.Connection

query(conn, statement)

Specs

query(Bolt.Sips.Connection, String.t) ::
  {:ok, Bolt.Sips.Response} |
  {:error, Bolt.Sips.Error}

sends the query (and its parameters) to the server and returns {:ok, Bolt.Sips.Response} or {:error, error} otherwise

query(conn, statement, params)

Specs

query(Bolt.Sips.Connection, String.t, Map.t) ::
  {:ok, Bolt.Sips.Response} |
  {:error, Bolt.Sips.Error}

send a query and an associated map of parameters. Returns the server response or an error

query!(conn, statement)

Specs

query!(Bolt.Sips.Connection, String.t) ::
  Bolt.Sips.Response |
  Bolt.Sips.Exception

The same as query/2 but raises a Bolt.Sips.Error if it fails. Returns the server response otherwise.

query!(conn, statement, params)

Specs

query!(Bolt.Sips.Connection, String.t, Map.t) ::
  Bolt.Sips.Response |
  Bolt.Sips.Exception

The same as query/3 but raises a Bolt.Sips.Error if it fails.

rollback(conn)

Specs

rollback(Bolt.Sips.Connection) :: Bolt.Sips.Connection

given that you have an open transaction, you can send a rollback request. The server will rollback the transaction. Any further statements trying to run in this transaction will fail immediately.

start_link(opts)

Specs

start_link(Keyword.t) ::
  {:ok, pid} |
  {:error, Bolt.Sips.Error.t}

Start the connection process and connect to Neo4j

Options:

  • :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) Poolboy will block the current process and wait for an available worker, failing after a timeout, when the pool is full;

Example of valid configurations (i.e. defined in config/dev.exs) and usage:

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)

conn = Bolt.Sips.conn
Bolt.Sips.query!(conn, "CREATE (a:Person {name:'Bob'})")
Bolt.Sips.query!(conn, "MATCH (a:Person) RETURN a.name AS name")
|> Enum.map(&(&1["name"]))

In the future we may use the DBConnection framework.