Pudu programming language
Menu
API reference

Std.Db.withConnection

1 declaration

fn

withConnection: &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, hand it to an action, and put it back however the action

ended.

There is no return a caller can forget. A connection not put back is one

the pool has lost, and a pool that has lost all of them stops every thread

waiting on it — a failure that appears only under load and looks like the

database being slow.

A connection that cannot be lent again — its socket dropped, the server

restarted, the protocol went wrong — is closed and its place kept empty, so

the next borrower opens a fresh one. Closing the whole pool instead would

turn one lost socket into every later request failing until the program

restarts.

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.

Back to Std.DbSearch related declarations