use anyhow::Result; use diesel::pg::PgConnection; use diesel::prelude::*; use diesel::r2d2::{ConnectionManager, PooledConnection}; use lazy_static::lazy_static; use crate::CONFIG; pub mod models; pub mod schema; pub type Pool = diesel::r2d2::Pool>; pub type Connection = PgConnection; pub type PoolConnection = PooledConnection>; pub fn establish_connection() -> ConnectionResult { use diesel::Connection; PgConnection::establish(&CONFIG.db_url) } pub fn pool() -> Result { Ok(diesel::r2d2::Pool::builder() .build(ConnectionManager::::new(&*CONFIG.db_url))?) } lazy_static! { pub static ref POOL: Pool = pool().unwrap(); }