feat: add remaining parameters
chore: rename update_script to add_script
This commit is contained in:
parent
2a358b61a2
commit
07ceede2ea
23
src/db.rs
23
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());
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user