A pool of sessions.
get: a session until the scope closesreserve: a pinned session until the scope closes (transactions and listeners)use(f): a session for as long asf's effect runsinvalidate(connection): replace a sessionstats: a snapshot of session occupancy (sessions, not statements; a session that has just failed can show as idle until the pool removes it)
Attributes#
| Attribute | Type | Description |
|---|---|---|
config | = config | |
get | Effect[PgConnection, SqlError, Scope] | Checks out a session until the current scope closes, replacing
one past its |
reserve | Effect[PgConnection, SqlError, Scope] |
|
stats | Effect[PoolStats] | A snapshot of session occupancy; never fails. It counts sessions, not statements, and a session that has just failed can show as idle until the pool removes it. |
Functions#
__init__#
__init__(config, pool, check_out, slow_use, hand_out) -> None| Parameter | Type | Description |
|---|---|---|
config | PgPoolConfig | |
pool | Pool[PgConnection, SqlError] | |
check_out | Effect[PgConnection, SqlError, Scope] | |
slow_use | Callable[[], bool] | |
hand_out | Callable[[PgConnection], Effect[PgConnection]] |
def __init__(
self,
config: PgPoolConfig,
pool: Pool[PgConnection, SqlError],
check_out: Effect[PgConnection, SqlError, Scope],
slow_use: Callable[[], bool],
hand_out: Callable[[PgConnection], Effect[PgConnection]],
) -> None:
self.config = config
self._pool = pool
self._check_out = check_out
self._slow_use = slow_use
self._hand_out = hand_outuse#
use[A, E, R](f) -> Effect[A, E | SqlError, R]Lends a session to f for as long as its effect runs and
takes it back on any exit, without opening a scope; a lease that
must outlive the effect (a stream, a transaction) takes get or
reserve. Fails with f's errors, or an SqlError as
get does.
| Parameter | Type | Description |
|---|---|---|
f | Callable[[PgConnection], Effect[A, E, R]] |
Returns Effect[A, E | SqlError, R]
def use[A, E, R](
self, f: Callable[[PgConnection], Effect[A, E, R]]
) -> Effect[A, E | SqlError, R]:
"""Lends a session to ``f`` for as long as its effect runs and
takes it back on any exit, without opening a scope; a lease that
must outlive the effect (a stream, a transaction) takes ``get`` or
``reserve``. Fails with ``f``'s errors, or an ``SqlError`` as
``get`` does."""
def body() -> Effect[A, E | SqlError, R]:
if self._slow_use():
return scoped(self._check_out.flat_map(f))
return self._pool.use(lambda connection: self._hand_out(connection).flat_map(f))
return _Suspend(body)invalidate#
invalidate(connection) -> Effect[None]Removes connection's session so the pool can replace it;
never fails. Fatal protocol and socket errors invalidate sessions
on their own.
| Parameter | Type | Description |
|---|---|---|
connection | PgConnection |
Returns Effect[None]
def invalidate(self, connection: PgConnection) -> Effect[None]:
"""Removes ``connection``'s session so the pool can replace it;
never fails. Fatal protocol and socket errors invalidate sessions
on their own."""
return self._pool.invalidate(connection.base)