From 15f196d7b9a37dfb7f9f2dd2ed4b55b2088b34d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20=C5=BBuk?= Date: Tue, 17 Sep 2024 11:49:05 +0200 Subject: [PATCH] Split DB_URL into separate vars --- fplus-database/src/lib.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/fplus-database/src/lib.rs b/fplus-database/src/lib.rs index eb177300..b49c365d 100644 --- a/fplus-database/src/lib.rs +++ b/fplus-database/src/lib.rs @@ -29,7 +29,17 @@ pub fn init() { * @return Result - The result of the operation */ pub async fn setup() -> Result<(), DbErr> { - let database_url = get_env_or_throw("DB_URL"); + let database_url = std::env::var("DB_URL").unwrap_or_else(|_| { + format!( + "postgres://{}:{}@{}:{}/{}?{}", + get_env_or_throw("DB_USER"), + get_env_or_throw("DB_PASS"), + get_env_or_throw("DB_HOST"), + std::env::var("DB_PORT").unwrap_or("5432".into()), + get_env_or_throw("DB_NAME"), + std::env::var("DB_OPTIONS").unwrap_or_default() + ) + }); let db_conn = Database::connect(&database_url).await?; let mut db_conn_global = DB_CONN.lock().unwrap(); *db_conn_global = Some(db_conn);