From f55885710ea6f77e0e68521cce2fda6ae3d1a095 Mon Sep 17 00:00:00 2001 From: Harsh Singh Date: Thu, 26 Oct 2023 17:17:40 +0530 Subject: [PATCH] handle db url for sqlite --- fastn-core/src/library2022/processor/sql.rs | 29 ++++++++++++++++++--- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/fastn-core/src/library2022/processor/sql.rs b/fastn-core/src/library2022/processor/sql.rs index 7742353b5d..ed6efe8fd4 100644 --- a/fastn-core/src/library2022/processor/sql.rs +++ b/fastn-core/src/library2022/processor/sql.rs @@ -6,12 +6,33 @@ pub struct DatabaseConfig { pub(crate) fn get_db_config() -> ftd::interpreter::Result { let db_url = std::env::var("FASTN_DB_URL").expect("FASTN_DB_URL is not set"); - let url = url::Url::parse(&db_url).expect("Invalid DB Url"); - let db_type = url.scheme().to_string(); - let config = DatabaseConfig { db_url, db_type }; + if db_url.contains("://") { + let url = url::Url::parse(&db_url).expect("Invalid DB Url"); + let db_type = url.scheme().to_string(); + let config = DatabaseConfig { db_url, db_type }; + Ok(config) + } else { + let config = if db_url == ":memory:" { + DatabaseConfig { + db_url, + db_type: "sqlite".to_string(), + } + } else if db_url.starts_with("file://") { + let path = &db_url[7..]; + DatabaseConfig { + db_url: path.to_string(), + db_type: "sqlite".to_string(), + } + } else { + DatabaseConfig { + db_url, + db_type: "sqlite".to_string(), + } + }; - Ok(config) + Ok(config) + } } pub async fn process(