Skip to main content

ConnectionPool

Trait ConnectionPool 

Source
pub trait ConnectionPool<D: Driver>: Debug {
    // Required methods
    fn get<'s>(&'s self) -> BoxFuture<'s, Result<PooledConnection<D>>>;
    fn timeout_get<'s>(
        &'s self,
        timeout: Duration,
    ) -> BoxFuture<'s, Result<PooledConnection<D>>>;
    fn detach<'s>(&'s self) -> BoxFuture<'s, Result<D::Connection>>;
    fn resize(&self, max_size: usize) -> Result<()>;
    fn into_box(self) -> Box<dyn ConnectionPool<D>>
       where D: 'static;
    fn close(self) -> BoxFuture<'static, Result<()>>;
}
Expand description

A managed pool of reusable database connections.

Every method that yields connections produces a PooledConnection that is automatically returned to the pool on drop, keeping the number of open database connections bounded.

Required Methods§

Source

fn get<'s>(&'s self) -> BoxFuture<'s, Result<PooledConnection<D>>>

Acquires a connection from the pool.

If all connections are in use and the pool is at its maximum size, this call waits until one becomes available or the configured [PoolConfig::wait_timeout] elapses, at which point an error is returned.

Source

fn timeout_get<'s>( &'s self, timeout: Duration, ) -> BoxFuture<'s, Result<PooledConnection<D>>>

Acquires a connection from the pool with an explicit timeout.

Identical to get but overrides the configured wait timeout with timeout. Useful when individual call sites need stricter or looser deadlines than the pool-level default.

Source

fn detach<'s>(&'s self) -> BoxFuture<'s, Result<D::Connection>>

Acquires a connection and removes it from pool management.

The returned D::Connection is a plain, pool-unaware connection. It will not be returned to the pool when dropped, the underlying database connection is closed instead. Use this when you need to hand a connection to code that does not know about the pool, or when you want to guarantee the connection is fully closed rather than recycled.

Source

fn resize(&self, max_size: usize) -> Result<()>

Changes the maximum number of connections the pool may hold.

Source

fn into_box(self) -> Box<dyn ConnectionPool<D>>
where D: 'static,

Converts this pool into a sized type-erased Box<dyn ConnectionPool<D>>.

Driver::connect_pool returns an opaque impl ConnectionPool<D> type that cannot be named or stored in struct fields, returned from trait implementations, or otherwise used where a concrete named type is required.

Source

fn close(self) -> BoxFuture<'static, Result<()>>

Closes the pool, marking it as unavailable and dropping all managed connections.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl<D: Driver> ConnectionPool<D> for Pool<DBConnectionManager<D>>
where <D as Driver>::Connection: Debug,

Source§

fn get<'s>(&'s self) -> BoxFuture<'s, Result<PooledConnection<D>>>

Source§

fn timeout_get<'s>( &'s self, timeout: Duration, ) -> BoxFuture<'s, Result<PooledConnection<D>>>

Source§

fn detach<'s>(&'s self) -> BoxFuture<'s, Result<D::Connection>>
where Self: Sized,

Source§

fn resize(&self, max_size: usize) -> Result<()>

Source§

fn into_box(self) -> Box<dyn ConnectionPool<D>>
where D: 'static,

Source§

fn close(self) -> BoxFuture<'static, Result<()>>

Implementors§