diff --git a/src/db.rs b/src/db.rs index b8214b8..de344e2 100644 --- a/src/db.rs +++ b/src/db.rs @@ -15,15 +15,32 @@ pub async fn init_db(pool: &SqlitePool) -> Result<(), String> { // TODO: Write the whole Script into the DB // TODO: Add Custom Error type #[allow(dead_code)] -pub async fn save_script(pool: &SqlitePool, script: &Script) -> Result<(), String> { +pub async fn add_script(pool: &SqlitePool, script: &Script) -> Result<(), String> { let id = Uuid::new_v4().to_string(); let name = script.name(); let path = script.path(); + + #[allow(clippy::expect_used)] + let parameters = serde_json::to_string(script.parameters()) + .expect("converting to json string should never fail"); + + let default_param_set = script.default_parameter_set(); + let help_uri = script.help_uri(); + let supports_paging = script.supports_paging(); + let supports_should_process = script.supports_should_process(); + let positional_bindings = script.positional_binding(); + sqlx::query!( - r#"INSERT INTO scripts (id, name, path) VALUES (?, ?, ?)"#, + r#"INSERT INTO scripts (id, name, path, parameters, default_parameter_set, help_uri, supports_paging, supports_should_process, positional_binding) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)"#, id, name, path, + parameters, + default_param_set, + help_uri, + supports_paging, + supports_should_process, + positional_bindings, ) .execute(pool) .await @@ -69,7 +86,7 @@ mod test { let script = Script::from_file("powershell/test-script.ps1").unwrap(); - assert!(save_script(&pool, &script).await.is_ok()); + assert!(add_script(&pool, &script).await.is_ok()); let want = (script.name(), script.path());