How to send db queries from Rust via tauri_plugin_sql? #9937
-
I'm using Tauri v2-beta. I want to put a file that the user selects via a dialog into a database. The file system plugin changed and does not allow reading/writing from/to for arbitrary locations.
In order to read the file, I must pass the path to the selected file to the backend via IPC. I could read the file and send the bytes back to the frontend via IPC, but since the IPC does not support shared memory, this seems rather memory intensive. Especially for large files. A solution would be to read the file in the Rust backend, and put it into the database from the backend. The problem is, that the plugin has no documented way of sending a query to the database from the backend. From what I see in the source, I should be able to access the plugin's state, which should include the database pool. Something along the lines of #[tauri::command]
fn store_document(app_handle: tauri::AppHandle, file_path: String) {
println!("File path: {}", file_path);
// Access database pool from app state here
} However, I know too little Rust to even know how to start. I would appreciate a little assistance with this. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
It does if the path is allowed on the scope which you can do via the permissions at build time, the
Yeah, good call, especially since you'd be transporting the data twice (reading + writing).
What would this actually solve? Just to be clear, the sql js bindings will also send the file data through the IPC. Anyway, you currently have to use a db crate (like sqlx) yourself and create a new connection until tauri-apps/plugins-workspace#1381 lands. |
Beta Was this translation helpful? Give feedback.
It does if the path is allowed on the scope which you can do via the permissions at build time, the
dialog
plugin (it will automatically extend the scope until the next restart, or forever if you use the persisted-scope plugin) or the fs plugin's scope rust apis.Yeah, good call, especially since you'd be transport…