Compare commits
3 Commits
05a4e24483
...
07ceede2ea
Author | SHA1 | Date | |
---|---|---|---|
07ceede2ea | |||
2a358b61a2 | |||
a2a9be299b |
@ -1,5 +1,11 @@
|
||||
CREATE TABLE IF NOT EXISTS scripts (
|
||||
id TEXT PRIMARY KEY,
|
||||
name TEXT NOT NULL,
|
||||
path TEXT NOT NULL
|
||||
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
|
||||
)
|
||||
|
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());
|
||||
|
||||
|
@ -27,6 +27,27 @@ 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