Skip to main content

PoolBuilder

Struct PoolBuilder 

Source
pub struct PoolBuilder { /* private fields */ }
Expand description

Builder for configuring a connection pool.

§Example

use bsql::Pool;

let pool = Pool::builder()
    .url("postgres://user:pass@localhost/mydb")
    .max_size(20)
    .lifetime_secs(900)
    .timeout_secs(5)
    .min_idle(2)
    .build()?;

Implementations§

Source§

impl PoolBuilder

Source

pub fn url(self, url: &str) -> Self

Configure the pool from a PostgreSQL connection URL.

Format: postgres://user:password@host:port/dbname

Source

pub fn max_size(self, size: usize) -> Self

Source

pub fn max_lifetime(self, d: Option<Duration>) -> Self

Set the maximum lifetime of a connection. Connections older than this are discarded when returned to the pool. Default: 30 minutes.

Pass None for unlimited lifetime.

Source

pub fn max_lifetime_secs(self, secs: u64) -> Self

Set the maximum lifetime in seconds. Convenience for max_lifetime(Some(Duration::from_secs(secs))).

Source

pub fn lifetime_secs(self, secs: u64) -> Self

Shorthand for max_lifetime_secs.

Source

pub fn acquire_timeout(self, d: Option<Duration>) -> Self

Set the maximum time to wait for a connection when the pool is exhausted. Default: 5 seconds.

Pass None for fail-fast behavior (no waiting, immediate error).

Source

pub fn acquire_timeout_secs(self, secs: u64) -> Self

Set the acquire timeout in seconds. Convenience for acquire_timeout(Some(Duration::from_secs(secs))).

Source

pub fn timeout_secs(self, secs: u64) -> Self

Shorthand for acquire_timeout_secs.

Source

pub fn min_idle(self, n: usize) -> Self

Set the minimum number of idle connections to maintain. Default: 0.

When greater than 0, a background task creates connections as needed to maintain this idle floor.

Source

pub fn replica_url(self, url: &str) -> Self

Set a read replica URL for read/write splitting.

When configured, query_raw_readonly (used by SELECT queries) routes to the replica pool. All writes go to the primary. When no replica is configured, all queries use the primary.

Source

pub fn replica_max_size(self, size: usize) -> Self

Set the max pool size for the replica pool. Defaults to the same value as max_size.

Source

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.

Source

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.

Source

pub async fn build(self) -> BsqlResult<PgPool>

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.