From eb098ea0fd95d883168cf8aac77be9eaf2c27047 Mon Sep 17 00:00:00 2001 From: itsscb Date: Sun, 25 May 2025 21:05:56 +0200 Subject: [PATCH] feat: make db stateful + read scripts from disk --- Cargo.toml | 1 + powershell/test-script.ps1 | 7 ++++- src/db.rs | 24 ++++++++++++++++ src/lib.rs | 57 +++++++++++++++++++++++++++++++++----- src/main.rs | 4 ++- src/router.rs | 5 ++-- 6 files changed, 87 insertions(+), 11 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index b7d91cc..8ae3aef 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,3 +18,4 @@ tower-http = { version = "0.6.4", features = ["fs"] } tracing = { version = "0.1.41", features = ["async-await"] } tracing-subscriber = "0.3.19" uuid = { version = "1.16.0", features = ["v4"] } +walkdir = "2.5.0" diff --git a/powershell/test-script.ps1 b/powershell/test-script.ps1 index 66255ba..7ac785e 100644 --- a/powershell/test-script.ps1 +++ b/powershell/test-script.ps1 @@ -46,4 +46,9 @@ [bool]$IsEnabled ) -process {} +process { + 0..20 | %{ + Write-Output "Info: $($_)" + Write-Warning "Warning: $($_)" + } +} diff --git a/src/db.rs b/src/db.rs index beaeb8c..a6bcb89 100644 --- a/src/db.rs +++ b/src/db.rs @@ -12,6 +12,30 @@ pub async fn init_db(pool: &SqlitePool) -> Result<(), String> { Ok(()) } +pub async fn open>(path: T) -> Result { + let db_url = format!("sqlite://{}", path.as_ref()); + + SqlitePool::connect(&db_url) + .await + .map_err(|e| e.to_string()) +} + +pub async fn new>(path: T) -> Result { + std::fs::File::create_new(path.as_ref()).map_err(|e| e.to_string())?; + let db_url = format!("sqlite://{}", path.as_ref()); + + SqlitePool::connect(&db_url) + .await + .map_err(|e| e.to_string()) +} + +pub async fn import_scripts(pool: &SqlitePool, scripts: Vec