> {
let mut stmt = self.conn.prepare(
"SELECT ext_id, identifier, path, data, version, enabled, installed_at FROM extensions",
@@ -983,4 +1073,72 @@ mod tests {
fs::remove_file(&db_path).unwrap();
}
+
+ #[test]
+ fn test_select_and_execute() {
+ let dir = tempdir().unwrap();
+ let db_path = dir.path().join("test.db");
+ let db = JarvisDB::new(&db_path, None).unwrap();
+ db.init().unwrap();
+
+ // Create a simple todo table
+ db.execute(
+ "CREATE TABLE todos (id INTEGER PRIMARY KEY, title TEXT, completed BOOLEAN)",
+ vec![],
+ )
+ .unwrap();
+
+ // Test execute with INSERT
+ let (rows_affected, last_id) = db
+ .execute(
+ "INSERT INTO todos (title, completed) VALUES (?1, ?2)",
+ vec![json!("Buy groceries"), json!(false)],
+ )
+ .unwrap();
+ assert_eq!(rows_affected, 1);
+ assert_eq!(last_id, 1);
+
+ // Test select with basic query
+ let results = db
+ .select(
+ "SELECT title, completed FROM todos WHERE id = ?1".to_string(),
+ vec![json!(1)],
+ )
+ .unwrap();
+ assert_eq!(results.len(), 1);
+ assert_eq!(results[0]["title"], "Buy groceries");
+ assert_eq!(results[0]["completed"], "false");
+
+ // Test execute with UPDATE
+ let (rows_affected, _) = db
+ .execute(
+ "UPDATE todos SET completed = ?1 WHERE id = ?2",
+ vec![json!(true), json!(1)],
+ )
+ .unwrap();
+ assert_eq!(rows_affected, 1);
+
+ // Verify the update with select
+ let results = db
+ .select(
+ "SELECT completed FROM todos WHERE id = ?1".to_string(),
+ vec![json!(1)],
+ )
+ .unwrap();
+ assert_eq!(results[0]["completed"], "true");
+
+ // Test execute with DELETE
+ let (rows_affected, _) = db
+ .execute("DELETE FROM todos WHERE id = ?1", vec![json!(1)])
+ .unwrap();
+ assert_eq!(rows_affected, 1);
+
+ // Verify the deletion
+ let results = db
+ .select("SELECT COUNT(*) as count FROM todos".to_string(), vec![])
+ .unwrap();
+ assert_eq!(results[0]["count"], 0);
+
+ fs::remove_file(&db_path).unwrap();
+ }
}
diff --git a/packages/tauri-plugins/jarvis/build.rs b/packages/tauri-plugins/jarvis/build.rs
index f3bcbc4..94829c3 100644
--- a/packages/tauri-plugins/jarvis/build.rs
+++ b/packages/tauri-plugins/jarvis/build.rs
@@ -98,6 +98,8 @@ const COMMANDS: &[&str] = &[
"search_extension_data",
"delete_extension_data_by_id",
"update_extension_data_by_id",
+ "select",
+ "execute",
/* -------------------------------- Clipboard ------------------------------- */
"add_to_history",
"get_history",
diff --git a/packages/tauri-plugins/jarvis/permissions/all.toml b/packages/tauri-plugins/jarvis/permissions/all.toml
index 3e5222d..77fa122 100644
--- a/packages/tauri-plugins/jarvis/permissions/all.toml
+++ b/packages/tauri-plugins/jarvis/permissions/all.toml
@@ -65,6 +65,8 @@ commands.allow = [
"get_ext_label_map",
"get_frontmost_app",
# Database
+ "select",
+ "execute",
"create_extension",
"get_all_extensions",
"get_unique_extension_by_identifier",
diff --git a/packages/tauri-plugins/jarvis/permissions/autogenerated/commands/execute.toml b/packages/tauri-plugins/jarvis/permissions/autogenerated/commands/execute.toml
new file mode 100644
index 0000000..d98be89
--- /dev/null
+++ b/packages/tauri-plugins/jarvis/permissions/autogenerated/commands/execute.toml
@@ -0,0 +1,13 @@
+# Automatically generated - DO NOT EDIT!
+
+"$schema" = "../../schemas/schema.json"
+
+[[permission]]
+identifier = "allow-execute"
+description = "Enables the execute command without any pre-configured scope."
+commands.allow = ["execute"]
+
+[[permission]]
+identifier = "deny-execute"
+description = "Denies the execute command without any pre-configured scope."
+commands.deny = ["execute"]
diff --git a/packages/tauri-plugins/jarvis/permissions/autogenerated/commands/select.toml b/packages/tauri-plugins/jarvis/permissions/autogenerated/commands/select.toml
new file mode 100644
index 0000000..5a13a02
--- /dev/null
+++ b/packages/tauri-plugins/jarvis/permissions/autogenerated/commands/select.toml
@@ -0,0 +1,13 @@
+# Automatically generated - DO NOT EDIT!
+
+"$schema" = "../../schemas/schema.json"
+
+[[permission]]
+identifier = "allow-select"
+description = "Enables the select command without any pre-configured scope."
+commands.allow = ["select"]
+
+[[permission]]
+identifier = "deny-select"
+description = "Denies the select command without any pre-configured scope."
+commands.deny = ["select"]
diff --git a/packages/tauri-plugins/jarvis/permissions/autogenerated/reference.md b/packages/tauri-plugins/jarvis/permissions/autogenerated/reference.md
index 43a78fd..06546b4 100644
--- a/packages/tauri-plugins/jarvis/permissions/autogenerated/reference.md
+++ b/packages/tauri-plugins/jarvis/permissions/autogenerated/reference.md
@@ -492,6 +492,32 @@ Denies the empty_trash command without any pre-configured scope.
+`jarvis:allow-execute`
+
+ |
+
+
+Enables the execute command without any pre-configured scope.
+
+ |
+
+
+
+
+
+`jarvis:deny-execute`
+
+ |
+
+
+Denies the execute command without any pre-configured scope.
+
+ |
+
+
+
+
+
`jarvis:allow-file-search`
|
@@ -1610,6 +1636,32 @@ Denies the search_extension_data command without any pre-configured scope.
+`jarvis:allow-select`
+
+ |
+
+
+Enables the select command without any pre-configured scope.
+
+ |
+
+
+
+
+
+`jarvis:deny-select`
+
+ |
+
+
+Denies the select command without any pre-configured scope.
+
+ |
+
+
+
+
+
`jarvis:allow-server-is-running`
|
diff --git a/packages/tauri-plugins/jarvis/permissions/schemas/schema.json b/packages/tauri-plugins/jarvis/permissions/schemas/schema.json
index 32302ff..ac9ff84 100644
--- a/packages/tauri-plugins/jarvis/permissions/schemas/schema.json
+++ b/packages/tauri-plugins/jarvis/permissions/schemas/schema.json
@@ -479,6 +479,16 @@
"type": "string",
"const": "deny-empty-trash"
},
+ {
+ "description": "Enables the execute command without any pre-configured scope.",
+ "type": "string",
+ "const": "allow-execute"
+ },
+ {
+ "description": "Denies the execute command without any pre-configured scope.",
+ "type": "string",
+ "const": "deny-execute"
+ },
{
"description": "Enables the file_search command without any pre-configured scope.",
"type": "string",
@@ -909,6 +919,16 @@
"type": "string",
"const": "deny-search-extension-data"
},
+ {
+ "description": "Enables the select command without any pre-configured scope.",
+ "type": "string",
+ "const": "allow-select"
+ },
+ {
+ "description": "Denies the select command without any pre-configured scope.",
+ "type": "string",
+ "const": "deny-select"
+ },
{
"description": "Enables the server_is_running command without any pre-configured scope.",
"type": "string",
diff --git a/packages/tauri-plugins/jarvis/src/commands/db.rs b/packages/tauri-plugins/jarvis/src/commands/db.rs
index f833837..dc0a1ff 100644
--- a/packages/tauri-plugins/jarvis/src/commands/db.rs
+++ b/packages/tauri-plugins/jarvis/src/commands/db.rs
@@ -2,6 +2,7 @@ use db::{
models::{Cmd, CmdType, Ext, ExtData, ExtDataField, ExtDataSearchQuery, SQLSortOrder},
JarvisDB,
};
+use serde_json::{json, Value as JsonValue};
use std::{path::PathBuf, sync::Mutex};
use tauri::State;
@@ -245,3 +246,31 @@ pub async fn update_extension_data_by_id(
.update_extension_data_by_id(data_id, data, search_text)
.map_err(|err| err.to_string())
}
+
+#[tauri::command]
+pub async fn select(
+ db: State<'_, DBState>,
+ query: &str,
+ values: Vec,
+) -> Result, String> {
+ db.db
+ .lock()
+ .unwrap()
+ .select(query.to_string(), values)
+ .map_err(|err| err.to_string())
+}
+
+#[tauri::command]
+pub async fn execute(
+ db: State<'_, DBState>,
+ query: &str,
+ values: Vec,
+) -> Result, String> {
+ let (rows_affected, last_id) = db
+ .db
+ .lock()
+ .unwrap()
+ .execute(query, values)
+ .map_err(|err| err.to_string())?;
+ Ok(vec![json!([rows_affected, last_id])])
+}
diff --git a/packages/tauri-plugins/jarvis/src/lib.rs b/packages/tauri-plugins/jarvis/src/lib.rs
index 58da91d..06d3087 100644
--- a/packages/tauri-plugins/jarvis/src/lib.rs
+++ b/packages/tauri-plugins/jarvis/src/lib.rs
@@ -140,6 +140,9 @@ pub fn init() -> TauriPlugin {
// commands::storage::ext_store_wrapper_load,
// commands::storage::ext_store_wrapper_save,
/* -------------------------------- database -------------------------------- */
+ commands::db::select,
+ commands::db::execute,
+ commands::db::create_extension,
commands::db::create_extension,
commands::db::get_all_extensions,
commands::db::get_unique_extension_by_identifier,