Module Neodriver_eio.Tx

Explicit transactions (BEGIN/COMMIT/ROLLBACK with per-transaction state).

Explicit transaction on a single connection.

A t wraps a connection with the per-transaction state: Open after BEGIN, Failed after any error inside the transaction, Closed after COMMIT/ROLLBACK. Operations on a closed transaction return a Transaction_error "Transaction closed"; operations on a failed transaction fail without touching the server (except ROLLBACK, which recovers the connection with a RESET).

Modeled on the Python driver's AsyncTransaction (_async/work/transaction.py).

type state =
  1. | Open
  2. | Failed
  3. | Closed
    (*

    Per-transaction state.

    *)
type t

An explicit transaction.

val begin_transaction : ?pipelined:bool -> ?on_begin_db:(string -> unit) -> Conn.t -> extra:Neodriver_packstream.Packstream.value -> fetch_size:int option -> telemetry:int option -> (t * string option, Neodriver_core.Errors.t) Stdlib.result

Send BEGIN on conn and return an Open transaction together with the db the server reports the transaction runs on (if any). A RESET is sent first if the connection is in the Failed state (recovering from a previous failed transaction). fetch_size is the session's fetch size, used for the transaction's result PULL batches. telemetry batches a TELEMETRY notification with the BEGIN. With pipelined the BEGIN is not read back (the execute_query BEGIN pipelining): the first run consumes it and, when the server reports a db, hands it to on_begin_db; the returned db is then None.

val run : t -> hydration:Neodriver_core.Hydration.t -> query:string -> parameters:(string * Neodriver_core.Values.t) list -> (Neodriver_eio__.Neo4j_result.t, Neodriver_core.Errors.t) Stdlib.result

Send RUN for query inside the transaction; the result is streamed lazily via Result. On any error the transaction becomes Failed and an Error _ is returned. The transaction's still-open results are drained before commit/rollback.

val commit : t -> (string option, Neodriver_core.Errors.t) Stdlib.result

Send COMMIT, applying the transaction's writes, and return the bookmark from the response.

val rollback : t -> (unit, Neodriver_core.Errors.t) Stdlib.result

Send ROLLBACK, discarding the transaction's writes. A transaction a server FAILURE already terminated needs no ROLLBACK (Conn resets the connection eagerly on a FAILURE); a connection-level failure during ROLLBACK is best-effort, only a server FAILURE answering the ROLLBACK surfaces.

val close : t -> (unit, Neodriver_core.Errors.t) Stdlib.result

Close the transaction, rolling back if it is still open.

val closed : t -> bool

Whether the transaction has been committed or rolled back.

val failed : t -> bool

Whether the transaction has failed.