pub struct Pool { /* private fields */ }Expand description
A connection pool with LIFO ordering and fail-fast semantics.
§Example
let pool = bsql_driver_postgres::Pool::connect("postgres://user:pass@localhost/db").await?;
let mut conn = pool.acquire().await?;
conn.simple_query("SELECT 1").await?;
// conn is returned to pool on dropImplementations§
Source§impl Pool
impl Pool
Sourcepub async fn connect(url: &str) -> Result<Self, DriverError>
pub async fn connect(url: &str) -> Result<Self, DriverError>
Create a pool from a connection URL with default settings (max_size = 10).
Validates the URL but does not open any connections yet (lazy initialization).
Sourcepub fn builder() -> PoolBuilder
pub fn builder() -> PoolBuilder
Create a pool builder for custom configuration.
Sourcepub async fn acquire(&self) -> Result<PoolGuard, DriverError>
pub async fn acquire(&self) -> Result<PoolGuard, DriverError>
Acquire a connection from the pool.
Returns immediately with the most recently used idle connection (LIFO).
If no idle connections are available and the pool is below max_size, a new
connection is created. If the pool is at max_size, returns
DriverError::Pool immediately — no blocking.
Sourcepub fn is_uds(&self) -> bool
pub fn is_uds(&self) -> bool
Whether this pool uses sync (UDS) connections.
Returns true when the pool URL points to a Unix domain socket.
On non-Unix platforms, always returns false.
Sourcepub async fn begin(&self) -> Result<Transaction, DriverError>
pub async fn begin(&self) -> Result<Transaction, DriverError>
Begin a transaction. Acquires a connection and sends BEGIN.
Sourcepub fn open_count(&self) -> usize
pub fn open_count(&self) -> usize
Current number of open connections (idle + in-use).
Sourcepub fn status(&self) -> PoolStatus
pub fn status(&self) -> PoolStatus
Pool status metrics.
Sourcepub async fn close(&self)
pub async fn close(&self)
Set the SQL statements to pre-PREPARE on new connections.
Each SQL string is PREPAREd (Parse+Describe+Sync) on new connections
before they are returned from acquire(). This eliminates the first-use
Parse overhead for frequently executed queries.
Warmup errors are silently ignored — a bad warmup SQL must not prevent the connection from being usable.
§Example
let pool = bsql_driver_postgres::Pool::connect("postgres://user:pass@localhost/db").await?;
pool.set_warmup_sqls(&[
"SELECT id, name FROM users WHERE id = $1::int4",
"SELECT id, title FROM tickets WHERE status = ANY($1::text[])",
]);Close the pool. No new acquires are accepted. All idle connections are sent Terminate and dropped.