From ff3b9fbaf400c344cae67ef9bdc9ba7d5f27b976 Mon Sep 17 00:00:00 2001 From: rtkay123 Date: Sun, 29 Mar 2026 16:36:13 +0200 Subject: refactor: move state to core --- lib/warden-core/src/state/database.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 lib/warden-core/src/state/database.rs (limited to 'lib/warden-core/src/state/database.rs') diff --git a/lib/warden-core/src/state/database.rs b/lib/warden-core/src/state/database.rs new file mode 100644 index 0000000..cf34484 --- /dev/null +++ b/lib/warden-core/src/state/database.rs @@ -0,0 +1,16 @@ +use sqlx::PgPool; +use tracing::{debug, error}; + +use crate::{WardenError, config::cli::database::Database}; + +pub 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}"))?) +} -- cgit v1.2.3