Tursox.Transaction (tursox v0.2.1)

Copy Markdown View Source

Rollback-safe direct transaction operations and bounded whole-callback retry.

MVCC is experimental upstream and provides snapshot isolation. Concurrent transactions use tested BEGIN CONCURRENT SQL because Turso 0.7.2 has no public Rust TransactionBehavior::Concurrent variant.

Summary

Functions

Begins a transaction in the selected mode.

Runs a tested WAL/MVCC checkpoint pragma and returns its ordered rows.

Commits the active transaction.

Retries a complete transaction callback only after retryable engine errors.

Rolls back the active transaction.

Sets and verifies the experimental MVCC checkpoint threshold.

Runs a callback and commits only its successful return value.

Functions

begin(connection, opts \\ [])

@spec begin(
  Tursox.Connection.t(),
  keyword()
) :: :ok | {:error, Tursox.Error.t()}

Begins a transaction in the selected mode.

checkpoint(connection, mode \\ :passive)

@spec checkpoint(Tursox.Connection.t(), :passive | :full | :restart | :truncate) ::
  {:ok, [[term()]]} | {:error, Tursox.Error.t()}

Runs a tested WAL/MVCC checkpoint pragma and returns its ordered rows.

commit(connection)

@spec commit(Tursox.Connection.t()) :: :ok | {:error, Tursox.Error.t()}

Commits the active transaction.

retry_transaction(connection, fun, opts \\ [])

@spec retry_transaction(Tursox.Connection.t(), (-> term()), keyword()) ::
  {:ok, term()} | {:error, term() | Tursox.Error.t()}

Retries a complete transaction callback only after retryable engine errors.

rollback(connection)

@spec rollback(Tursox.Connection.t()) :: :ok | {:error, Tursox.Error.t()}

Rolls back the active transaction.

set_mvcc_checkpoint_threshold(connection, threshold)

@spec set_mvcc_checkpoint_threshold(Tursox.Connection.t(), non_neg_integer()) ::
  {:ok, non_neg_integer()} | {:error, Tursox.Error.t()}

Sets and verifies the experimental MVCC checkpoint threshold.

transaction(connection, fun, opts \\ [])

@spec transaction(Tursox.Connection.t(), (-> term()), keyword()) ::
  {:ok, term()} | {:error, term() | Tursox.Error.t()} | no_return()

Runs a callback and commits only its successful return value.

{:error, reason}, exceptions, throws, and exits roll back. Raised/thrown/exited control flow is re-raised after rollback.