diff options
Diffstat (limited to 'lib/warden-core/src/state/mod.rs')
| -rw-r--r-- | lib/warden-core/src/state/mod.rs | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/warden-core/src/state/mod.rs b/lib/warden-core/src/state/mod.rs new file mode 100644 index 0000000..f4692c2 --- /dev/null +++ b/lib/warden-core/src/state/mod.rs @@ -0,0 +1,24 @@ +pub(crate) mod database; +use sqlx::PgPool; +use tracing_subscriber::EnvFilter; + +use crate::{WardenError, config::Configuration}; + +pub type LogHandle = tracing_subscriber::reload::Handle<EnvFilter, tracing_subscriber::Registry>; + +#[derive(Debug, Clone)] +pub struct AppState { + pub log_handle: LogHandle, + pub database: PgPool, +} + +impl AppState { + pub async fn new(log_handle: LogHandle, config: &Configuration) -> Result<Self, WardenError> { + let database = database::connect(&config.database).await?; + + Ok(Self { + log_handle, + database, + }) + } +} |
