Skip to main content

Module transaction

Module transaction 

Source
Expand description

Transaction helpers with consistent error mapping and rollback tracing.

Service code can either manually begin/commit/rollback with uniform error conversion or run a callback inside with_transaction. The rollback guard logs dropped transactions, which helps catch early-return paths that rely on rollback-on-drop instead of making rollback explicit.

§Pattern

Standard service-layer transaction usage:

transaction::with_transaction(db, async |txn| {
    repo::operation(txn, ...).await?;
    repo::another_operation(txn, ...).await?;
    Ok(())
})
.await?;

Functions§

begin
Begins and returns a transaction so the caller can commit or roll it back.
commit
Commits a transaction and maps errors consistently.
rollback
Rolls back a transaction and maps errors consistently.
with_transaction
Runs a transaction callback with consistent tracing and rollback guarding.
with_transaction_retry
Runs a complete transaction boundary with bounded retries selected by the product.