1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
pub mod models;
pub mod queries;
pub mod schema;
pub mod views_schema;

use diesel::r2d2::{ConnectionManager, Pool};
use diesel::PgConnection;
use r2d2::PooledConnection;

#[derive(thiserror::Error, Debug)]
#[error("{0}")]
pub struct Error(r2d2::Error);

pub type DbConnectionPool = Pool<ConnectionManager<PgConnection>>;
pub type DbConnection = PooledConnection<ConnectionManager<PgConnection>>;

pub fn load_db_connection_pool(db_url: &str) -> Result<DbConnectionPool, Error> {
    Pool::builder()
        .build(ConnectionManager::<PgConnection>::new(db_url))
        .map_err(Error)
}