pub struct PoolBuilder { /* private fields */ }Expand description
Builder for configuring a connection pool.
Implementations§
Source§impl PoolBuilder
impl PoolBuilder
Sourcepub fn max_size(self, size: usize) -> Self
pub fn max_size(self, size: usize) -> Self
Set the maximum pool size. Default: 10.
A max_size of 0 means the pool will reject all acquire() calls immediately.
Sourcepub fn max_lifetime(self, lifetime: Option<Duration>) -> Self
pub fn max_lifetime(self, lifetime: Option<Duration>) -> Self
Set the maximum lifetime of a connection. Default: 30 minutes. Set to None for unlimited lifetime.
Sourcepub fn acquire_timeout(self, timeout: Option<Duration>) -> Self
pub fn acquire_timeout(self, timeout: Option<Duration>) -> Self
Set the acquire timeout. Default: 5 seconds. Set to None for fail-fast behavior when the pool is exhausted.
Sourcepub fn min_idle(self, count: usize) -> Self
pub fn min_idle(self, count: usize) -> Self
Set the minimum number of idle connections. Default: 0. When > 0, a background thread maintains this many idle connections.
Sourcepub fn max_stmt_cache_size(self, size: usize) -> Self
pub fn max_stmt_cache_size(self, size: usize) -> Self
Set the maximum number of cached prepared statements per connection. Default: 256. When the cache exceeds this size, the least recently used statement is evicted (Close sent to PG to free server memory).
Sourcepub fn stale_timeout(self, timeout: Duration) -> Self
pub fn stale_timeout(self, timeout: Duration) -> Self
Set the maximum idle duration before a connection is considered stale. Default: 30 seconds. Connections idle longer than this are dropped on acquire instead of being reused.
Sourcepub fn statement_cache_mode(self, mode: StatementCacheMode) -> Self
pub fn statement_cache_mode(self, mode: StatementCacheMode) -> Self
Set the statement cache mode for all connections in this pool.
StatementCacheMode::Named(default): named prepared statements, cached and reused. Best performance for direct connections.StatementCacheMode::Disabled: unnamed statements only — compatible with pgbouncer/PgCat transaction pooling mode.
This overrides the ?statement_cache= URL parameter.
Sourcepub fn build(self) -> Result<Pool, DriverError>
pub fn build(self) -> Result<Pool, DriverError>
Build the pool. Validates the URL but does not open connections.