Skip to main content

Module transaction

Module transaction 

Source
Expand description

Transaction handle abstraction.

Decouples transaction capabilities from DbContext so callers can hold a typed handle (Box<dyn ITransaction>) returned by DbContext::begin_transaction(). The handle exposes commit / rollback (which consume it), savepoint operations, isolation level control, and a connection() accessor used internally by save_changes() to reuse the ambient transaction’s connection.

§Two control modes

  • Manuallet txn = ctx.begin_transaction().await?; ... txn.commit().await?; The handle is returned without registering an ambient; save_changes() will self-manage its own transaction. Use this when you need the handle for explicit savepoint / isolation control.
  • Scopedctx.use_transaction(|ctx| Box::pin(async move { ... })).await? Registers the handle as ambient; save_changes() calls inside the closure reuse the same transaction. Commits on Ok, rolls back on Err.

Structs§

DbTransaction
Default ITransaction implementation wrapping an IAsyncConnection.

Traits§

ITransaction
Transaction handle abstracting the Priority 2 connection-level transaction methods.