class Neo4j::Bolt::Connection
- Neo4j::Bolt::Connection
- Reference
- Object
Defined in:
neo4j/bolt/connection.crConstant Summary
-
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.
-
.new(uri : URI, ssl : Bool = true, connection_retries = 5)
Initializes this connection with the given URI and SSL flag.
- .new
Instance Method Summary
- #begin(metadata = Map.new)
- #close
- #commit
-
#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.
-
#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.
- #exec_cast(query : String, types : Tuple(*TYPES)) forall TYPES
-
#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.
-
#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.
- #exec_cast(query : String, types : Tuple(*TYPES), &) : Nil forall TYPES
-
#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.
- #exec_cast_scalar(query : String, type : T) forall T
-
#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.
-
#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.
- #execute(_query, **parameters, &block : List -> )
-
#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.
-
#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.
-
#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.
- #rollback
-
#transaction(metadata = Map.new, &)
Wrap a group of queries into an atomic transaction.
Instance methods inherited from class Object
to_bolt_params : Neo4j::Value
to_bolt_params
Constructor Detail
Initializes this connection with the given URL string and SSL flag.
connection = Neo4j::Bolt::Connection.new("bolt://neo4j:password@localhost", ssl: false)
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)
Instance Method Detail
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: "[email protected]"}, {User})
MATCH (user:User { email: $email })
RETURN user
CYPHER
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" => "[email protected]"}, {User})
MATCH (user:User { email: $email })
RETURN user
CYPHER
# => [{User(@id="4478440e-1897-41a9-812d-91f6d21b994b", @email="[email protected]")}]
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: "[email protected]"}, {User}) do |(user)|
MATCH (user:User { email: $email })
RETURN user
CYPHER
process user
end
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" => "[email protected]"}, {User}) do |(user)|
MATCH (user:User { email: $email })
RETURN user
CYPHER
process user
end
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" => "[email protected]"}, User)
MATCH (user:User { email: $email })
RETURN user
LIMIT 1
CYPHER
# => User(@id="4478440e-1897-41a9-812d-91f6d21b994b", @email="[email protected]")
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" => "[email protected]"}, {User})
MATCH (user:User { email: $email })
RETURN user
LIMIT 1
CYPHER
# => {User(@id="4478440e-1897-41a9-812d-91f6d21b994b", @email="[email protected]")}
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 RETURN
ed 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.
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})
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)
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.
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
.