aboutsummaryrefslogtreecommitdiffstats
path: root/lib/warden-core/src/state
diff options
context:
space:
mode:
Diffstat (limited to 'lib/warden-core/src/state')
-rw-r--r--lib/warden-core/src/state/database.rs16
-rw-r--r--lib/warden-core/src/state/mod.rs28
2 files changed, 0 insertions, 44 deletions
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<PgPool, WardenError> {
- 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<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?;
- trace!("running database migrations");
- sqlx::migrate!("../../migrations").run(&database).await?;
- debug!("database up to date");
-
- Ok(Self {
- log_handle,
- database,
- })
- }
-}