Trait sea_orm_rocket::Pool
source · pub trait Pool: Sized + Send + Sync + 'static {
type Connection;
type Error: Error;
fn init<'life0, 'async_trait>(
figment: &'life0 Figment
) -> Pin<Box<dyn Future<Output = Result<Self, Self::Error>> + Send + 'async_trait>>
where
'life0: 'async_trait,
Self: '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
sourcetype Connection
type Connection
The connection type managed by this pool.
sourcetype Error: Error
type Error: Error
The error type returned by Self::init()
.
Required Methods
sourcefn init<'life0, 'async_trait>(
figment: &'life0 Figment
) -> Pin<Box<dyn Future<Output = Result<Self, Self::Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: 'async_trait,
fn init<'life0, 'async_trait>(
figment: &'life0 Figment
) -> Pin<Box<dyn Future<Output = Result<Self, Self::Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: '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.
sourcefn borrow(&self) -> &Self::Connection
fn borrow(&self) -> &Self::Connection
Borrows a reference to the pool