diff --git a/lib/postgres.dart b/lib/postgres.dart index fb4e4299..d76086a2 100644 --- a/lib/postgres.dart +++ b/lib/postgres.dart @@ -125,6 +125,18 @@ class Sql { factory Sql.named(String sql, {String substitution}) = SqlImpl.named; } +/// A capability for preparing and executing SQL statements. +/// +/// This is **not** necessarily a 1:1 mapping to a PostgreSQL physical database +/// connection or session. +/// +/// An implementation may represent: +/// +/// - a dedicated database connection. +/// - a session executed on a connection borrowed from a pool. +/// - or another abstraction capable of executing queries. +/// +/// A session may also operate in a transactional context ([TxSession]). abstract class Session { /// Whether this connection is currently open. /// diff --git a/lib/src/pool/pool_api.dart b/lib/src/pool/pool_api.dart index b4af7ba6..a3d8e9e5 100644 --- a/lib/src/pool/pool_api.dart +++ b/lib/src/pool/pool_api.dart @@ -57,6 +57,10 @@ class PoolSettings extends ConnectionSettings { /// specified data range. /// - a primary/replica status, whic may be specified for cases where stale or /// read-only data is acceptable +/// +/// This interface implements [Session] and [SessionExecutor] as a convenience +/// API that internally acquires a pooled connection via [withConnection] for +/// each operation. abstract class Pool implements Session, SessionExecutor { factory Pool.withSelector( EndpointSelector selector, { @@ -125,8 +129,9 @@ abstract class Pool implements Session, SessionExecutor { // TODO: decide whether PgSession.execute and prepare methods should also take locality parameter } -typedef EndpointSelector = - FutureOr Function(EndpointSelectorContext context); +typedef EndpointSelector = FutureOr Function( + EndpointSelectorContext context, +); final class EndpointSelectorContext { final L? locality;