class

Neo4j::Bolt::Connection

Inherits Reference / Object

Constants

EXCEPTIONS = {"Neo.ClientError.Schema.IndexAlreadyExists" => IndexAlreadyExists, "Neo.ClientError.Schema.ConstraintValidationFailed" => ConstraintValidationFailed, "Neo.ClientError.Schema.EquivalentSchemaRuleAlreadyExists" => EquivalentSchemaRuleAlreadyExists, "Neo.ClientError.Procedure.ProcedureCallFailed" => ProcedureCallFailed, "Neo.ClientError.Statement.ParameterMissing" => ParameterMissing, "Neo.ClientError.Statement.SyntaxError" => SyntaxError, "Neo.ClientError.Statement.ArgumentError" => ArgumentError}
GOGOBOLT = "``\xB0\u0017".to_slice
SUPPORTED_VERSIONS = {516, 260, 4, 0}

Constructors

new(url : String, ssl : Bool = true)

Initializes this connection with the given URL string and SSL flag.

connection = Neo4j::Bolt::Connection.new("bolt://neo4j:password@localhost", ssl: false)
Source
new(uri : URI, ssl : Bool = true, connection_retries = 5)

Initializes this connection with the given URI and SSL flag. SSL defaults to true so that, if you omit it by mistake, you aren't sending your database credentials in plaintext.

uri = URI.parse("bolt://neo4j:password@localhost")
connection = Neo4j::Bolt::Connection.new(uri, ssl: false)
Source

Instance methods

begin(metadata = Map.new)
Source
close
Source
commit
Source
exec_cast(query : String, parameters : NamedTuple, types : Tuple)

Execute the given query with the given parameters, returning an array containing the results cast into the given types.

struct User
  Neo4j.map_node(
    id: UUID,
    email: String,
  )
end

connection.exec_cast(<<-CYPHER, {email: "me@example.com"}, {User})
  MATCH (user:User { email: $email })
  RETURN user
CYPHER
Source
exec_cast(query : String, parameters : Map, types : Tuple(*TYPES)) forall TYPES

Execute the given query with the given parameters, returning an array containing the results cast into the given types.

struct User
  Neo4j.map_node(
    id: UUID,
    email: String,
  )
end

connection.exec_cast(<<-CYPHER, Neo4j::Map{"email" => "me@example.com"}, {User})
  MATCH (user:User { email: $email })
  RETURN user
CYPHER
# => [{User(@id="4478440e-1897-41a9-812d-91f6d21b994b", @email="me@example.com")}]
Source
exec_cast(query : String, types : Tuple(*TYPES)) forall TYPES
Source
exec_cast(query : String, parameters : NamedTuple, types : Tuple, &)

Execute the given query with the given parameters, yielding a tuple containing the results cast into the given types.

struct User
  Neo4j.map_node(
    id: UUID,
    email: String,
  )
end

connection.exec_cast(<<-CYPHER, {email: "me@example.com"}, {User}) do |(user)|
  MATCH (user:User { email: $email })
  RETURN user
CYPHER
  process user
end
Source
exec_cast(query : String, parameters : Map, types : Tuple(*TYPES), metadata = Map.new, &) : Nil forall TYPES

Execute the given query with the given parameters, yielding a tuple containing the results cast into the given types.

struct User
  Neo4j.map_node(
    id: UUID,
    email: String,
  )
end

connection.exec_cast(<<-CYPHER, Neo4j::Map{"email" => "me@example.com"}, {User}) do |(user)|
  MATCH (user:User { email: $email })
  RETURN user
CYPHER
  process user
end
Source
exec_cast(query : String, types : Tuple(*TYPES), &) : Nil forall TYPES
Source
exec_cast_scalar(query : String, parameters : Map, type : T) forall T

Execute the given query with the given parameters, returning a single result cast to the given type.

struct User
  Neo4j.map_node(
    id: UUID,
    email: String,
  )
end

connection.exec_cast_scalar(<<-CYPHER, Neo4j::Map{"email" => "me@example.com"}, User)
  MATCH (user:User { email: $email })
  RETURN user
  LIMIT 1
CYPHER
# => User(@id="4478440e-1897-41a9-812d-91f6d21b994b", @email="me@example.com")
Source
exec_cast_scalar(query : String, type : T) forall T
Source
exec_cast_single(query : String, parameters : Map, types : Tuple(*TYPES)) forall TYPES

Execute the given query with the given parameters, returning an array containing the results cast into the given types.

struct User
  Neo4j.map_node(
    id: UUID,
    email: String,
  )
end

connection.exec_cast_single(<<-CYPHER, Neo4j::Map{"email" => "me@example.com"}, {User})
  MATCH (user:User { email: $email })
  RETURN user
  LIMIT 1
CYPHER
# => {User(@id="4478440e-1897-41a9-812d-91f6d21b994b", @email="me@example.com")}
Source
execute(query, parameters : Map, metadata = Map.new, &block : List -> )

Executes the given query with the given parameters and executes the block once for each result returned from the database.

connection.execute <<-CYPHER, Neo4j::Map{"id" => 123} do |(user)|
  MATCH (user:User { id: $id })
  RETURN user
CYPHER
  process User.new(user.as Neo4j::Node)
end

In the example above, we used () in the block arguments to destructure the list of RETURNed values. Also note that we need to cast it down to a Neo4j::Node. All values in results have the compile-time type of Neo4j::Value and so will need to be cast down to its specific type.

Source
execute(_query, **parameters, &block : List -> )
Source
execute(query, parameters : Map, metadata = Map.new)

Execute the given query with the given parameters, returning a Result object containing query metadata and the query results in an array.

connection.execute(query, Neo4j::Map{"id" => 123})
Source
execute(_query query, **params)

Execute the given query with the given parameters, returning a Result object containing query metadata and the query results in an array.

This method provides a convenient shorthand for providing a Neo4j::Map of query parameters.

connection.execute(query, id: 123)
Source
reset

If the connection gets into a wonky state, this method tells the server to reset it back to a normal state, but you lose everything you haven't pulled down yet.

Source
rollback
Source
transaction(metadata = Map.new, &)

Wrap a group of queries into an atomic transaction. Yields a Neo4j::Bolt::Transaction.

connection.transaction do |txn|
  connection.execute query1
  connection.execute query2
end

Exceptions raised within the block will roll back the transaction. To roll back the transaction manually and exit the block, call txn.rollback.

Source

Nested types