Skip to main content

ConnectionPool

Trait ConnectionPool 

Source
pub trait ConnectionPool: Send + Sync {
    // Required methods
    fn get<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<Box<dyn Connection + Send>, OxiSqlError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn pool_size(&self) -> usize;
    fn idle_count(&self) -> usize;
    fn active_count(&self) -> usize;
    fn health_check<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<(), OxiSqlError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn close<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
}
Expand description

A pool of database connections.

Implementors manage a bounded set of backend connections and hand them out to callers on demand. When the returned Box<dyn Connection> is dropped, the underlying connection is returned to the pool automatically (handled by each backend’s pool implementation).

The trait is object-safe: Box<dyn ConnectionPool> is a valid type.

Required Methods§

Source

fn get<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Box<dyn Connection + Send>, OxiSqlError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Check out a connection from the pool.

Blocks until a connection is available or returns an error if the pool is exhausted / timed out.

Source

fn pool_size(&self) -> usize

Maximum number of connections the pool will hold.

Source

fn idle_count(&self) -> usize

Number of connections currently idle (available for checkout).

Source

fn active_count(&self) -> usize

Number of connections currently checked out (active).

Source

fn health_check<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<(), OxiSqlError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Verify that the pool is healthy by probing the backend.

For RDBMS backends this typically executes SELECT 1 on an idle connection. For in-memory backends it is a no-op.

Source

fn close<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Drain all idle connections and prevent new checkouts.

Active (checked-out) connections are allowed to finish normally; they are closed when returned to the pool after this call.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§