Skip to main content

Pool

Struct Pool 

Source
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

Source

pub async fn connect(url: &str) -> BsqlResult<Self>

Connect to PostgreSQL using a connection URL.

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

Source

pub fn builder() -> PoolBuilder

Create a pool builder for fine-grained configuration.

Source

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.

Source

pub fn is_pgbouncer(&self) -> bool

Whether PgBouncer was detected between the client and PostgreSQL.

Source

pub fn supports_named_statements(&self) -> bool

Whether named prepared statements can be used.

False when PgBouncer is detected without prepared_statements=yes.

Source

pub fn has_replicas(&self) -> bool

Whether read replicas are configured.

Source

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.

Source

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.

Source

pub fn status(&self) -> PoolStatus

Current pool status: available and total connections.

Trait Implementations§

Source§

impl Executor for Pool

Source§

async fn query_raw( &self, sql: &str, params: &[&(dyn ToSql + Sync)], ) -> BsqlResult<Arc<Vec<Row>>>

Execute a query and return all rows (shared via Arc for singleflight).
Source§

async fn query_raw_readonly( &self, sql: &str, params: &[&(dyn ToSql + Sync)], ) -> BsqlResult<Arc<Vec<Row>>>

Execute a read-only query. Routes to replicas when available. Read more
Source§

async fn execute_raw( &self, sql: &str, params: &[&(dyn ToSql + Sync)], ) -> BsqlResult<u64>

Execute a query and return the number of affected rows.

Auto Trait Implementations§

§

impl !Freeze for Pool

§

impl !RefUnwindSafe for Pool

§

impl Send for Pool

§

impl Sync for Pool

§

impl Unpin for Pool

§

impl UnsafeUnpin for Pool

§

impl !UnwindSafe for Pool

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more