Trait DatabasePoolBuilderTrait

Source
pub trait DatabasePoolBuilderTrait: Backend {
    // Provided method
    fn create_database_pool<'async_trait>(
        self,
    ) -> Pin<Box<dyn Future<Output = Result<DatabasePool<Self>, Error<Self::BuildError, Self::PoolError, Self::ConnectionError, Self::QueryError>>> + Send + 'async_trait>>
       where Self: Send + 'async_trait { ... }
}
Expand description

Database pool builder trait implemented for all async backends

Provided Methods§

Source

fn create_database_pool<'async_trait>( self, ) -> Pin<Box<dyn Future<Output = Result<DatabasePool<Self>, Error<Self::BuildError, Self::PoolError, Self::ConnectionError, Self::QueryError>>> + Send + 'async_trait>>
where Self: Send + 'async_trait,

Creates a database pool

§Example
use bb8::Pool;
use db_pool::{
    r#async::{DatabasePoolBuilderTrait, DieselAsyncPostgresBackend, DieselBb8},
    PrivilegedPostgresConfig,
};
use diesel::sql_query;
use diesel_async::RunQueryDsl;
use dotenvy::dotenv;

async fn f() {
    dotenv().ok();

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

    let backend = DieselAsyncPostgresBackend::<DieselBb8>::new(
        config,
        |_| Pool::builder().max_size(10),
        |_| Pool::builder().max_size(2),
        None,
        move |mut conn| {
            Box::pin(async {
                sql_query("CREATE TABLE book(id SERIAL PRIMARY KEY, title TEXT NOT NULL)")
                    .execute(&mut conn)
                    .await
                    .unwrap();
                Some(conn)
            })
        },
    )
    .await
    .unwrap();

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

tokio_test::block_on(f());

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§