feat: get from db by id
This commit is contained in:
parent
886fddfc41
commit
01af05b999
24
src/db.rs
24
src/db.rs
@ -86,6 +86,30 @@ struct ScriptRow {
|
|||||||
positional_binding: Option<bool>,
|
positional_binding: Option<bool>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
|
pub async fn get_script<T: AsRef<str>>(pool: &SqlitePool, id: T) -> Result<(Uuid, Script), String> {
|
||||||
|
let script_row = sqlx::query_as::<_, ScriptRow>("SELECT id, name, path, parameters, default_parameter_set, help_uri, supports_paging, supports_should_process, positional_binding FROM scripts WHERE id = ?").bind(id.as_ref())
|
||||||
|
.fetch_one(pool)
|
||||||
|
.await
|
||||||
|
.map_err(|e| e.to_string())?;
|
||||||
|
let params: Vec<Parameter> =
|
||||||
|
serde_json::from_str(&script_row.parameters).map_err(|e| e.to_string())?;
|
||||||
|
Ok((
|
||||||
|
Uuid::parse_str(&script_row.id).map_err(|e| e.to_string())?,
|
||||||
|
Script::builder()
|
||||||
|
.set_name(script_row.name)
|
||||||
|
.set_path(script_row.path)
|
||||||
|
.set_parameters(params)
|
||||||
|
.set_default_parameter_set(script_row.default_parameter_set)
|
||||||
|
.set_help_uri(script_row.help_uri)
|
||||||
|
.set_supports_paging(script_row.supports_paging)
|
||||||
|
.set_supports_should_process(script_row.supports_should_process)
|
||||||
|
.set_positional_binding(script_row.positional_binding)
|
||||||
|
.build()
|
||||||
|
.map_err(|e| e.to_string())?,
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: Return Vec<Script> instead of String-Tuple
|
// TODO: Return Vec<Script> instead of String-Tuple
|
||||||
// TODO: Add Custom Error Type
|
// TODO: Add Custom Error Type
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user