Pool

Trait Pool 

Source
pub trait Pool:
    Sized
    + Send
    + Sync
    + 'static {
    type Connection;
    type Error: Error;

    // Required methods
    fn init<'life0, 'async_trait>(
        figment: &'life0 Figment,
    ) -> Pin<Box<dyn Future<Output = Result<Self, Self::Error>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn borrow(&self) -> &Self::Connection;
}
Expand description

Generic Database driver connection pool trait.

This trait provides a generic interface to various database pooling implementations in the Rust ecosystem. It can be implemented by anyone.

This is adapted from the original rocket_db_pools. But on top we require Connection itself to be Sync. Hence, instead of cloning or allocating a new connection per request, here we only borrow a reference to the pool.

In SeaORM, only when you are about to execute a SQL statement will a connection be acquired from the pool, and returned as soon as the query finishes. This helps a bit with concurrency if the lifecycle of a request is long enough.

Required Associated Types§

Source

type Connection

The connection type managed by this pool.

Source

type Error: Error

The error type returned by Self::init().

Required Methods§

Source

fn init<'life0, 'async_trait>( figment: &'life0 Figment, ) -> Pin<Box<dyn Future<Output = Result<Self, Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Constructs a pool from a Value.

It is up to each implementor of Pool to define its accepted configuration value(s) via the Config associated type. Most integrations provided in sea_orm_rocket use [Config], which accepts a (required) url and an (optional) pool_size.

§Errors

This method returns an error if the configuration is not compatible, or if creating a pool failed due to an unavailable database server, insufficient resources, or another database-specific error.

Source

fn borrow(&self) -> &Self::Connection

Borrows a reference to the pool

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl Pool for MockPool

Source§

type Error = MockPoolErr

Source§

type Connection = bool