2022-11-04 18:40:14 +01:00
|
|
|
pub mod accounts;
|
|
|
|
pub mod addresses;
|
|
|
|
|
|
|
|
pub use accounts::*;
|
|
|
|
pub use addresses::*;
|
|
|
|
use config::SharedAppConfig;
|
2022-11-06 19:50:51 +01:00
|
|
|
use sqlx_core::pool::Pool;
|
|
|
|
use sqlx_core::postgres::Postgres;
|
2022-11-04 18:40:14 +01:00
|
|
|
|
|
|
|
#[derive(Clone)]
|
|
|
|
pub struct Database {
|
|
|
|
pub pool: sqlx::PgPool,
|
|
|
|
_config: SharedAppConfig,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Database {
|
|
|
|
pub async fn build(config: SharedAppConfig) -> Self {
|
|
|
|
let url = config.lock().account_manager().database_url.clone();
|
|
|
|
let pool = sqlx::PgPool::connect(&url).await.unwrap_or_else(|e| {
|
|
|
|
tracing::error!("Failed to connect to database. {e:?}");
|
|
|
|
std::process::exit(1);
|
|
|
|
});
|
|
|
|
Self {
|
|
|
|
pool,
|
|
|
|
_config: config,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-06 19:50:51 +01:00
|
|
|
pub fn pool(&self) -> Pool<Postgres> {
|
|
|
|
self.pool.clone()
|
|
|
|
}
|
2022-11-04 18:40:14 +01:00
|
|
|
}
|