pub mod blocks; pub mod transactions; use crate::config::DatabaseConfig; use deadpool_postgres::{Config, CreatePoolError, ManagerConfig, RecyclingMethod, Runtime}; use std::ops::Deref; use std::sync::Arc; use tokio_postgres::NoTls; type Result = std::result::Result>; type Connection = deadpool_postgres::Client; #[derive(Clone)] pub struct Database(Arc); impl Deref for Database { type Target = deadpool_postgres::Pool; fn deref(&self) -> &Self::Target { &self.0 } } impl From for Config { fn from(config: DatabaseConfig) -> Self { let mut c = Self::new(); c.user = Some(config.user); c.password = Some(config.password); c.host = Some(config.host); c.port = Some(config.port); c.dbname = Some(config.database); c.manager = Some(ManagerConfig { recycling_method: RecyclingMethod::Verified, }); c } } impl Database { pub fn new(config: DatabaseConfig) -> std::result::Result { Ok(Self(Arc::new( Config::from(config).create_pool(Some(Runtime::Tokio1), NoTls)?, ))) } }