From 8ed77d7ab484121e9d70158e14c9fd6c243f1c70 Mon Sep 17 00:00:00 2001 From: FxQnLr Date: Mon, 12 Feb 2024 14:58:08 +0100 Subject: Close #9. Config impl with struct and files --- src/db.rs | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) (limited to 'src/db.rs') diff --git a/src/db.rs b/src/db.rs index 8a6b16e..489a000 100644 --- a/src/db.rs +++ b/src/db.rs @@ -1,13 +1,7 @@ -#[cfg(debug_assertions)] -use std::env; - use serde::Serialize; use sqlx::{PgPool, postgres::PgPoolOptions}; use tracing::{debug, info}; -#[cfg(not(debug_assertions))] -use crate::config::SETTINGS; - #[derive(Serialize, Debug)] pub struct Device { pub id: String, @@ -17,18 +11,12 @@ pub struct Device { pub times: Option> } -pub async fn init_db_pool() -> PgPool { - #[cfg(not(debug_assertions))] - let db_url = SETTINGS.get_string("database.url").unwrap(); - - #[cfg(debug_assertions)] - let db_url = env::var("DATABASE_URL").unwrap(); - +pub async fn init_db_pool(db_url: &str) -> PgPool { debug!("attempt to connect dbPool to '{}'", db_url); let pool = PgPoolOptions::new() .max_connections(5) - .connect(&db_url) + .connect(db_url) .await .unwrap(); -- cgit v1.2.3