DatabasePoolBuilderTrait

Trait DatabasePoolBuilderTrait 

Source
pub trait DatabasePoolBuilderTrait: Backend {
    // Provided method
    fn create_database_pool(
        self,
    ) -> Result<DatabasePool<Self>, Error<Self::ConnectionError, Self::QueryError>> { ... }
}
Expand description

Database pool builder trait implemented for all sync backends

Provided Methods§

Source

fn create_database_pool( self, ) -> Result<DatabasePool<Self>, Error<Self::ConnectionError, Self::QueryError>>

Creates a database pool

§Example
use db_pool::{
    sync::{DatabasePoolBuilderTrait, DieselPostgresBackend},
    PrivilegedPostgresConfig,
};
use diesel::{sql_query, RunQueryDsl};
use dotenvy::dotenv;
use r2d2::Pool;

dotenv().ok();

let config = PrivilegedPostgresConfig::from_env().unwrap();

let backend = DieselPostgresBackend::new(
    config,
    || Pool::builder().max_size(10),
    || Pool::builder().max_size(2),
    move |conn| {
        sql_query("CREATE TABLE book(id SERIAL PRIMARY KEY, title TEXT NOT NULL)")
            .execute(conn)
            .unwrap();
    },
)
.unwrap();

let db_pool = backend.create_database_pool().unwrap();

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<B> DatabasePoolBuilder for B
where B: Backend + Sized,