Bolt.Sips v0.1.11 Boltex.Bolt

The Boltex.Bolt module handles the Bolt protocol specific steps (i.e. handshake, init) as well as sending and receiving messages and wrapping them in chunks.

It abstracts transportation, expecing the transport layer to define send/2 and recv/3 analogous to :gen_tcp.

Summary

Functions

Acknowdledge a server error

Does the handshake

Initialises the connection

Runs a statement (most likely Cypher statement) and returns a list of the records and a summary

Sends a list of messages using the Bolt protocol and PackStream encoding

Unpacks (or in other words parses) a message

Functions

ack_failure(transport, port)

Acknowdledge a server error.

This function is supposed to be called after a failure response has been received from the server.

handshake(transport, port)

Does the handshake

init(transport, port, auth \\ nil)

Initialises the connection.

Expects a transport module (i.e. gen_tcp) and a Port. Accepts authorisation params in the form of {username, password}.

Examples

iex> Boltex.Bolt.init :gen_tcp, port
:ok

iex> Boltex.Bolt.init :gen_tcp, port, {"username", "password"}
:ok
receive_data(transport, port, previous \\ [])

Receives data.

This function is supposed to be called after a request to the server has been made. It receives data chunks, mends them (if they were split between frames) and decodes them using PackStream.

When just a single message is received (i.e. to acknowledge a command), this function returns a tuple with two items, the first being the signature and the second being the message(s) itself. If a list of messages is received it will return a list of the former.

The same goes for the messages: If there was a single data point in a message said data point will be returned by itself. If there were multiple data points, the list will be returned.

The signature is represented as one of the following:

  • :success
  • :record
  • :ignored
  • :failure
run_statement(transport, port, statement, params \\ %{})

Runs a statement (most likely Cypher statement) and returns a list of the records and a summary.

Records are represented using PackStream’s record data type. Their Elixir representation is a Keyword with the indexse :sig and :fields.

Examples

iex> Boltex.Bolt.run_statement("MATCH (n) RETURN n")
[
  {:record, [sig: 1, fields: [1, "Exmaple", "Labels", %{"some_attribute" => "some_value"}]]},
  {:success, %{"type" => "r"}}
]
send_messages(transport, port, messages)

Sends a list of messages using the Bolt protocol and PackStream encoding.

Messages have to be in the form of {[messages], signature}.

unpack(arg)

Unpacks (or in other words parses) a message.