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.