Crates.io | tauri-plugin-rusqlite |
lib.rs | tauri-plugin-rusqlite |
version | 0.4.4 |
source | src |
created_at | 2024-03-21 02:38:14.440739 |
updated_at | 2024-04-19 03:59:32.572552 |
description | Tauri Plugin based on Rusqlite |
homepage | |
repository | |
max_upload_size | |
id | 1181161 |
size | 38,859 |
This plugin enables access to an SQLite database within Tauri applications. It is inspired by the tauri-plugin-sqlite plugin but is based on rusqlite.
npm run tauri dev
Enter the src-tauri
directory in your project's structure.
Execute the following command to add tauri-plugin-rusqlite to your project's dependencies:
cargo add tauri-plugin-rusqlite
main.rs
file located in the src-tauri/src
directory of your project. Modify the main
function to include the plugin initialization code.fn main() {
tauri::Builder::default()
.plugin(tauri_plugin_rusqlite::init()) // add this
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
Navigate to the root directory of your source code.
Execute the following command in your terminal:
npm i tauri-plugin-rusqlite-api
import Rusqlite from 'tauri-plugin-rusqlite-api'
const database = await Rusqlite.openInMemory("test.db");
or
const database = await Rusqlite.openInPath("./folder/test.db");
let scripts = [{
name: "create_table",
sql: "CREATE TABLE test (id INTEGER PRIMARY KEY, integer_value INTEGER, real_value REAL, text_value TEXT, blob_value BLOB); CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT NOT NULL);"
}];
await database.migration(scripts);
or
await database.batch(
"CREATE TABLE test (id INTEGER PRIMARY KEY, integer_value INTEGER, real_value REAL, text_value TEXT, blob_value BLOB); CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT NOT NULL);");
await database.batch("DROP TABLE test;");
await database.update("INSERT INTO test (integer_value, real_value, text_value, blob_value) VALUES (:integer_value, :real_value, :text_value, :blob_value)",
new Map([
[":integer_value", parseInt(target.integer_value.value)],
[":real_value", parseFloat(target.real_value.value)],
[":text_value", target.text_value.value],
[":blob_value", target.blob_value.value]
]));
let result = await database.select("SELECT * FROM test", new Map());
...
result.map((item) => {
return {
id: item.id,
...
};
});
await database.close();