33 lines
765 B
Rust
33 lines
765 B
Rust
pub mod accounts;
|
|
pub mod addresses;
|
|
|
|
pub use accounts::*;
|
|
pub use addresses::*;
|
|
use config::SharedAppConfig;
|
|
use sqlx_core::pool::Pool;
|
|
use sqlx_core::postgres::Postgres;
|
|
|
|
#[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,
|
|
}
|
|
}
|
|
|
|
pub fn pool(&self) -> Pool<Postgres> {
|
|
self.pool.clone()
|
|
}
|
|
}
|