Compare commits
No commits in common. "07ceede2ea712318c462329719a6be5a15b54bde" and "05a4e24483d15347630c495980cb9563de7acae7" have entirely different histories.
07ceede2ea
...
05a4e24483
@ -1,11 +1,5 @@
|
||||
CREATE TABLE IF NOT EXISTS scripts (
|
||||
id TEXT PRIMARY KEY,
|
||||
name TEXT NOT NULL,
|
||||
path TEXT NOT NULL,
|
||||
parameters TEXT NOT NULL,
|
||||
default_parameter_set TEXT,
|
||||
help_uri TEXT,
|
||||
supports_paging TEXT,
|
||||
supports_should_process BOOLEAN,
|
||||
positional_binding BOOLEAN
|
||||
id TEXT PRIMARY KEY,
|
||||
name TEXT NOT NULL,
|
||||
path TEXT NOT NULL
|
||||
)
|
||||
|
23
src/db.rs
23
src/db.rs
@ -15,32 +15,15 @@ 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 add_script(pool: &SqlitePool, script: &Script) -> Result<(), String> {
|
||||
pub async fn save_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, parameters, default_parameter_set, help_uri, supports_paging, supports_should_process, positional_binding) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)"#,
|
||||
r#"INSERT INTO scripts (id, name, path) VALUES (?, ?, ?)"#,
|
||||
id,
|
||||
name,
|
||||
path,
|
||||
parameters,
|
||||
default_param_set,
|
||||
help_uri,
|
||||
supports_paging,
|
||||
supports_should_process,
|
||||
positional_bindings,
|
||||
)
|
||||
.execute(pool)
|
||||
.await
|
||||
@ -86,7 +69,7 @@ mod test {
|
||||
|
||||
let script = Script::from_file("powershell/test-script.ps1").unwrap();
|
||||
|
||||
assert!(add_script(&pool, &script).await.is_ok());
|
||||
assert!(save_script(&pool, &script).await.is_ok());
|
||||
|
||||
let want = (script.name(), script.path());
|
||||
|
||||
|
@ -27,27 +27,6 @@ impl Script {
|
||||
&self.path
|
||||
}
|
||||
|
||||
pub fn parameters(&self) -> &Vec<Parameter> {
|
||||
&self.parameters
|
||||
}
|
||||
|
||||
pub fn default_parameter_set(&self) -> Option<&str> {
|
||||
self.default_parameter_set.as_ref().map(|x| x as _)
|
||||
}
|
||||
|
||||
pub fn help_uri(&self) -> Option<&str> {
|
||||
self.help_uri.as_ref().map(|x| x as _)
|
||||
}
|
||||
pub fn supports_paging(&self) -> Option<&str> {
|
||||
self.supports_paging.as_ref().map(|x| x as _)
|
||||
}
|
||||
pub fn supports_should_process(&self) -> Option<bool> {
|
||||
self.supports_should_process
|
||||
}
|
||||
pub fn positional_binding(&self) -> Option<bool> {
|
||||
self.positional_binding
|
||||
}
|
||||
|
||||
pub fn from_file<P: AsRef<str>>(path: P) -> Result<Self, String> {
|
||||
let func = get_parse_function();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user