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")?;
let mut conn = pool.acquire()?;
conn.simple_query("SELECT 1")?;
// conn is returned to pool on dropImplementations§
Source§impl Pool
impl Pool
Sourcepub fn connect(url: &str) -> Result<Self, DriverError>
pub 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 fn acquire(&self) -> Result<PoolGuard, DriverError>
pub 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 and no acquire_timeout
is set, returns DriverError::Pool immediately. If acquire_timeout is
set, blocks until a connection is returned or the timeout expires.
Sourcepub fn is_uds(&self) -> bool
pub fn is_uds(&self) -> bool
Whether this pool uses UDS connections.
Returns true when the pool URL points to a Unix domain socket.
On non-Unix platforms, always returns false.
Sourcepub fn begin(&self) -> Result<Transaction, DriverError>
pub 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 fn set_warmup_sqls<S: Into<Box<str>>>(
&self,
sqls: impl IntoIterator<Item = S>,
)
pub fn set_warmup_sqls<S: Into<Box<str>>>( &self, sqls: impl IntoIterator<Item = S>, )
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")?;
pool.set_warmup_sqls([
"SELECT id, name FROM users WHERE id = $1::int4",
"SELECT id, title FROM tickets WHERE status = ANY($1::text[])",
]);Set SQL statements to pre-PREPARE on new connections.
Accepts any iterator of items convertible to Box<str>:
["SELECT 1", "SELECT 2"]— static &str, copied into Box[format!("SET search_path TO {}", name)]— String, zero-copy move