pub struct Pool { /* private fields */ }Expand description
A PostgreSQL connection pool.
Wraps deadpool-postgres with fail-fast acquire semantics, singleflight
query coalescing, and optional read/write splitting.
Implementations§
Source§impl Pool
impl Pool
Sourcepub async fn connect(url: &str) -> BsqlResult<Self>
pub async fn connect(url: &str) -> BsqlResult<Self>
Connect to PostgreSQL using a connection URL.
Format: postgres://user:password@host:port/dbname
Sourcepub fn builder() -> PoolBuilder
pub fn builder() -> PoolBuilder
Create a pool builder for fine-grained configuration.
Sourcepub async fn acquire(&self) -> BsqlResult<PoolConnection>
pub async fn acquire(&self) -> BsqlResult<PoolConnection>
Acquire a connection from the primary pool.
Fail-fast: returns BsqlError::Pool immediately if no connections
are available. Does not wait. Does not timeout. See CREDO principle #17.
Sourcepub fn is_pgbouncer(&self) -> bool
pub fn is_pgbouncer(&self) -> bool
Whether PgBouncer was detected between the client and PostgreSQL.
Sourcepub fn supports_named_statements(&self) -> bool
pub fn supports_named_statements(&self) -> bool
Whether named prepared statements can be used.
False when PgBouncer is detected without prepared_statements=yes.
Sourcepub fn has_replicas(&self) -> bool
pub fn has_replicas(&self) -> bool
Whether read replicas are configured.
Sourcepub async fn begin(&self) -> BsqlResult<Transaction>
pub async fn begin(&self) -> BsqlResult<Transaction>
Begin a new transaction.
Acquires a connection from the primary pool and sends BEGIN. The
connection is held for the lifetime of the returned Transaction.
Fail-fast: returns BsqlError::Pool immediately if no connections
are available. See CREDO principle #17.
Sourcepub async fn query_stream(
&self,
sql: &str,
params: &[&(dyn ToSql + Sync)],
) -> BsqlResult<QueryStream>
pub async fn query_stream( &self, sql: &str, params: &[&(dyn ToSql + Sync)], ) -> BsqlResult<QueryStream>
Execute a query and return a stream of rows.
Acquires a connection from the pool and returns a QueryStream
that holds the connection alive until the stream is consumed or
dropped. Rows arrive one at a time, avoiding buffering the
entire result set in memory.
Fail-fast: returns BsqlError::Pool immediately if no connections
are available. See CREDO principle #17.
This method is only available on Pool (not PoolConnection or
Transaction) because the stream must own the connection for its
entire lifetime.
Sourcepub fn status(&self) -> PoolStatus
pub fn status(&self) -> PoolStatus
Current pool status: available and total connections.