BoltexNif (boltex_nif v0.1.1)
View SourceElixir NIF bindings for the neo4rs
Rust driver for Neo4j.
All public functions are synchronous at the Elixir layer. Internally the Rust
side spawns work on a global Tokio runtime and signals completion by sending
{ref, result} back to the calling process. The Elixir wrapper blocks on a
receive until the response arrives or :timeout elapses.
High-level API
connect/1— open a connection pool.run/4/execute/4— auto-commit queries.run_with_summary/4— auto-commit +%BoltexNif.Summary{}.begin_transaction/2+txn_run/4+txn_execute/4+commit/2+rollback/2.stream_start/4+stream_next/2+stream_close/2— lazy row streaming.
Summary
Connection
Connect to a Neo4j database.
Auto-commit queries
Run a query in auto-commit mode, collecting all rows into a list of maps.
Run a query in auto-commit mode, discarding any rows.
Run a query in auto-commit mode and return a BoltexNif.Summary struct
with counters (nodes/relationships created, properties set, …),
notifications and the query bookmark (Bolt v5).
Transactions
Start an explicit transaction.
Commit a transaction. Returns {:ok, bookmark} on Bolt v5 (the bookmark may
be nil) or plain :ok otherwise.
Roll back a transaction.
Convenience wrapper: begin_transaction → run fun, commit on success,
rollback on {:error, _} or raise.
Run a query inside a transaction and collect all rows.
Run a query inside a transaction, returning its BoltexNif.Summary struct.
Streaming
Drop a stream eagerly (without consuming remaining rows).
Fetch the next row. Returns {:ok, row}, :done, or {:error, reason}.
Start a lazy row stream for cypher. Consume with stream_next/2.
Connection
Connect to a Neo4j database.
Accepted options:
:uri(required) — e.g."bolt://localhost:7687"or"neo4j://...":user/:password:db— database name (optional):fetch_size— rows per fetch window (0keeps driver default):max_connections— pool size (0keeps driver default):impersonate_user— user to impersonate for queries (Bolt v5):tls— one of:nil(default) — use scheme-driven TLS (neo4j+s://,bolt+ssc://, …){:ca, "path/to/ca.pem"}— validate the server against this CA{:mutual, ca: path | nil, cert: path, key: path}— mutual TLS:skip_validation— bypass verification (NOT for production)
:timeout— milliseconds to wait for the handshake (default 15 000)
Auto-commit queries
Run a query in auto-commit mode, collecting all rows into a list of maps.
Keys in each row are the AS aliases from the Cypher RETURN clause.
For large result sets, prefer stream_start/4 to avoid buffering
everything in memory.
Run a query in auto-commit mode, discarding any rows.
params is a map of string (or atom) keys to Elixir terms that are
marshalled to Bolt values — see the type table in the
Overview.
@spec run_with_summary(graph(), String.t(), params(), keyword()) :: {:ok, BoltexNif.Summary.t()} | {:error, term()}
Run a query in auto-commit mode and return a BoltexNif.Summary struct
with counters (nodes/relationships created, properties set, …),
notifications and the query bookmark (Bolt v5).
Transactions
Start an explicit transaction.
The returned handle must be finished with commit/2 or rollback/2; use
transaction/3 for the recommended scope-and-commit pattern.
Commit a transaction. Returns {:ok, bookmark} on Bolt v5 (the bookmark may
be nil) or plain :ok otherwise.
Roll back a transaction.
@spec transaction( graph(), (txn() -> {:ok, any()} | {:error, any()} | any()), keyword() ) :: {:ok, any()} | {:error, term()}
Convenience wrapper: begin_transaction → run fun, commit on success,
rollback on {:error, _} or raise.
The function value you return from fun drives the transaction:
{:ok, value}— commit, result is{:ok, value}.{:error, reason}— rollback, result is{:error, reason}.- any other term — commit, result is
{:ok, term}. - a raised exception — rollback, then re-raise.
Run a query inside a transaction and collect all rows.
@spec txn_run(txn(), String.t(), params(), keyword()) :: {:ok, BoltexNif.Summary.t()} | {:error, term()}
Run a query inside a transaction, returning its BoltexNif.Summary struct.
Streaming
Drop a stream eagerly (without consuming remaining rows).
Fetch the next row. Returns {:ok, row}, :done, or {:error, reason}.
Start a lazy row stream for cypher. Consume with stream_next/2.