From cec58d78e968250e4c589899eab460d1132f6d01 Mon Sep 17 00:00:00 2001 From: rtkay123 Date: Mon, 30 Mar 2026 17:46:25 +0200 Subject: refactor: generic svcs --- lib/warden-core/src/lib.rs | 1 - lib/warden-core/src/state/database.rs | 16 ---------------- lib/warden-core/src/state/mod.rs | 28 ---------------------------- 3 files changed, 45 deletions(-) delete mode 100644 lib/warden-core/src/state/database.rs delete mode 100644 lib/warden-core/src/state/mod.rs (limited to 'lib/warden-core') diff --git a/lib/warden-core/src/lib.rs b/lib/warden-core/src/lib.rs index 413087b..f200ba1 100644 --- a/lib/warden-core/src/lib.rs +++ b/lib/warden-core/src/lib.rs @@ -1,4 +1,3 @@ mod error; pub use error::WardenError; pub mod config; -pub mod state; diff --git a/lib/warden-core/src/state/database.rs b/lib/warden-core/src/state/database.rs deleted file mode 100644 index 4167424..0000000 --- a/lib/warden-core/src/state/database.rs +++ /dev/null @@ -1,16 +0,0 @@ -use sqlx::PgPool; -use tracing::{debug, error}; - -use crate::{WardenError, config::cli::database::Database}; - -pub(crate) async fn connect(config: &Database) -> Result { - let url = config.get_url()?; - let host = url.host_str(); - debug!(host = host, "connecting to database"); - - Ok(sqlx::postgres::PgPoolOptions::new() - .max_connections(config.database_pool_size.unwrap_or(10)) - .connect(url.as_str()) - .await - .inspect_err(|e| error!("{e}"))?) -} diff --git a/lib/warden-core/src/state/mod.rs b/lib/warden-core/src/state/mod.rs deleted file mode 100644 index 18e44b8..0000000 --- a/lib/warden-core/src/state/mod.rs +++ /dev/null @@ -1,28 +0,0 @@ -pub(crate) mod database; -use sqlx::PgPool; -use tracing::{debug, trace}; -use tracing_subscriber::EnvFilter; - -use crate::{WardenError, config::Configuration}; - -pub type LogHandle = tracing_subscriber::reload::Handle; - -#[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 { - let database = database::connect(&config.database).await?; - trace!("running database migrations"); - sqlx::migrate!("../../migrations").run(&database).await?; - debug!("database up to date"); - - Ok(Self { - log_handle, - database, - }) - } -} -- cgit v1.2.3