Std.Db.transaction
1 declaration
fn
transaction: &Std.Db.Pool -> fn(Std.Db.Session.Connection) -> (Result[T, Std.Db.Session.DbError], Std.Db.Session.Connection) -> Result[T, Std.Db.Session.DbError]This is a callable function.
What it does
Take a connection, run an action inside a transaction on it, and put it
back.
The connection is held for the whole operation, which is the point. A
caller that reaches for the pool once per statement gets a different
connection each time, so BEGIN lands on one and the work that was meant
to be inside it lands on another — and the transaction, holding nothing,
commits nothing and rolls back nothing. Nothing about that reads as wrong
at the call site; it appears as rows that should have been undone and were
not.
Holding one connection is also what stops another caller interleaving work
between the BEGIN and the COMMIT: a connection lent to this operation
is not in the pool for anyone else to take.
Read the signature
- The text after the name is the type checked by Pudu.
- Read arrows from left to right: inputs come first, and the final type is returned.
- & borrows a value for this call instead of moving or copying it.
- Names inside [ ] are type arguments, such as the item type held by a collection.
- Result makes success and recoverable failure part of the function's type.
