Skip to main content

Module session

Module session 

Source
Expand description

Block-owned transaction session over a guarded pooled connection.

SqlTxSession is the concrete TransactionSession implementation for transacted { datasource } blocks: the sql component’s Arc::downcast target reached through the port’s Any supertrait upcast. It is the sole owner of its pooled connection (the connection is never stored in exchange extensions), armed with a discard guard from checkout until an acknowledged finalization: any phase except Done/Detached dropped out from under the session detaches the connection synchronously (R0, DiscardOnDrop).

The lifecycle keys on a private TxPhase, never on the frozen TransactionState: “BEGIN bytes may be on the wire” and “COMMIT handed off” drive the finalization decision but cannot be expressed by the port enum (604c §A). BEGIN / COMMIT / ROLLBACK are issued as plain statements on the borrowed connection — no sqlx Transaction wrapper is ever stored, and the borrow is confined to one await scope inside this module.

Unit-tier testability without Docker: the driver-facing statement IO is behind the private TxIo trait (the real backend is AnyConnIo over an AnyPool connection; fixtures script a fake), and the time source is behind TxTimer (the default TokioTimer runs on tokio’s clock, so start_paused tests get a virtual clock; an injected timer replaces it). The camel-api port is untouched by both seams.

Rulings: .opencode/fleet/orders/604c-sqltrans-s2-ruling.md (§A/§B) and 604d-sqltrans-s2-ruling2.md (total rollback contract). Binding precedence: openspec/changes/sqltrans/specs/sql-transactions/spec.md.

Structs§

SqlTxSession
One block-owned transaction on one datasource.