Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
[package]
name = "tauri-plugin-rusqlite"
version = "0.4.4"
version = "0.5.0"
authors = [ "Kess" ]
description = "Tauri Plugin based on Rusqlite"
description = "A Tauri plugin for rusqlite"
license = "MIT"
readme = "README.md"
edition = "2021"
rust-version = "1.60"
exclude = [ "/examples", "/webview-dist", "/webview-src", "node_modules" ]
rust-version = "1.77.2"
exclude = ["/examples", "/dist-js", "/guest-js", "/node_modules"]
links = "tauri-plugin-rusqlite"

[dependencies]
tauri = { version = "1.5.4" }
tauri = "2"
serde = "1.0"
thiserror = "1.0"
rusqlite = { version = "0.31.0", features = [ "bundled" ] }
serde_json = "1.0.114"
serde_json = "1.0"
thiserror = "2"
rusqlite = { version = "0.34.0", features = [ "bundled" ] }
md5 = "0.7.0"

[build-dependencies]
tauri-plugin = { version = "2.0.4", features = ["build"] }
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@

This plugin enables access to an SQLite database within Tauri applications. It is inspired by the [tauri-plugin-sqlite](https://github.com/lzdyes/tauri-plugin-sqlite) plugin but is based on [rusqlite](https://github.com/rusqlite/rusqlite).

The current version supports Tauri 2.0. To use this plugin with Tauri 1.x, use the 1.4.4 release of this plugin.

## Example

- Full example at: <https://github.com/kessdev/tauri-plugin-rusqlite/tree/main/examples/rusqlite-demo>
- Execute the following command in your terminal:

``` bash
cd examples/rusqlite-demo
npm i
npm run tauri dev
```

Expand Down Expand Up @@ -62,6 +66,8 @@ or
const database = await Rusqlite.openInPath("./folder/test.db");
```

To use `openInPath` you will need permission to read/write to the database path (see example code). If the file does not exist at the path then an empty sqlite db is created. (Note: folders will not be created, so check that the folder exists before calling `openInPath`.)

### Init database

``` ts
Expand Down
5 changes: 5 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const COMMANDS: &[&str] = &["open_in_memory", "open_in_path", "migration", "update", "select", "batch", "close"];

fn main() {
tauri_plugin::Builder::new(COMMANDS).build();
}
32 changes: 32 additions & 0 deletions dist-js/index.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
'use strict';

var core = require('@tauri-apps/api/core');

class Rusqlite {
constructor(name) {
this.name = name;
}
static async openInMemory(name) {
return await core.invoke('plugin:rusqlite|open_in_memory', { name: name }).then(() => new Rusqlite(name));
}
static async openInPath(path) {
return await core.invoke('plugin:rusqlite|open_in_path', { path: path }).then(() => new Rusqlite(path));
}
async migration(migrations) {
return await core.invoke('plugin:rusqlite|migration', { name: this.name, migrations });
}
async update(sql, parameters) {
return await core.invoke('plugin:rusqlite|update', { name: this.name, sql, parameters });
}
async select(sql, parameters) {
return await core.invoke('plugin:rusqlite|select', { name: this.name, sql, parameters });
}
async batch(sql) {
return await core.invoke('plugin:rusqlite|batch', { name: this.name, sql });
}
async close() {
return await core.invoke('plugin:rusqlite|close', { name: this.name });
}
}

module.exports = Rusqlite;
File renamed without changes.
30 changes: 30 additions & 0 deletions dist-js/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { invoke } from '@tauri-apps/api/core';

class Rusqlite {
constructor(name) {
this.name = name;
}
static async openInMemory(name) {
return await invoke('plugin:rusqlite|open_in_memory', { name: name }).then(() => new Rusqlite(name));
}
static async openInPath(path) {
return await invoke('plugin:rusqlite|open_in_path', { path: path }).then(() => new Rusqlite(path));
}
async migration(migrations) {
return await invoke('plugin:rusqlite|migration', { name: this.name, migrations });
}
async update(sql, parameters) {
return await invoke('plugin:rusqlite|update', { name: this.name, sql, parameters });
}
async select(sql, parameters) {
return await invoke('plugin:rusqlite|select', { name: this.name, sql, parameters });
}
async batch(sql) {
return await invoke('plugin:rusqlite|batch', { name: this.name, sql });
}
async close() {
return await invoke('plugin:rusqlite|close', { name: this.name });
}
}

export { Rusqlite as default };
2 changes: 1 addition & 1 deletion examples/rusqlite-demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Tauri + React + TS</title>
<title>Tauri + React + TS + Rusqlite</title>
</head>

<body>
Expand Down
34 changes: 34 additions & 0 deletions examples/rusqlite-demo/jsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"compilerOptions": {
"moduleResolution": "Node",
"target": "ESNext",
"module": "ESNext",
/**
* svelte-preprocess cannot figure out whether you have
* a value or a type, so tell TypeScript to enforce using
* `import type` instead of `import` for Types.
*/
"importsNotUsedAsValues": "error",
"isolatedModules": true,
"resolveJsonModule": true,
/**
* To have warnings / errors of the Svelte compiler at the
* correct position, enable source maps by default.
*/
"sourceMap": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"baseUrl": ".",
/**
* Typecheck JS in `.svelte` and `.js` files by default.
* Disable this if you'd like to use dynamic types.
*/
"checkJs": true
},
/**
* Use global.d.ts instead of compilerOptions.types
* to avoid limiting type declarations.
*/
"include": ["src/**/*.d.ts", "src/**/*.js", "src/**/*.svelte"]
}
11 changes: 6 additions & 5 deletions examples/rusqlite-demo/package.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
{
"name": "rusqlite-demo",
"private": true,
"version": "0.0.0",
"version": "0.1.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "tsc && vite build",
"build": "vite build",
"preview": "vite preview",
"tauri": "tauri"
},
"dependencies": {
"@tauri-apps/api": "^2.0.0",
"@tauri-apps/plugin-fs": "^2.2.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"@tauri-apps/api": "^1.5.2",
"tauri-plugin-rusqlite-api": "file:../../"
},
"devDependencies": {
"@tauri-apps/cli": "^2.0.0",
"@types/react": "^18.2.15",
"@types/react-dom": "^18.2.7",
"@vitejs/plugin-react": "^4.2.1",
"typescript": "^5.0.2",
"vite": "^5.0.0",
"@tauri-apps/cli": "^1.5.8"
"vite": "^6.0.0"
}
}
18 changes: 9 additions & 9 deletions examples/rusqlite-demo/src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ authors = ["you"]
license = ""
repository = ""
edition = "2021"
rust-version = "1.77.2"

[lib]
name = "tauri_app_lib"
crate-type = ["staticlib", "cdylib", "rlib"]

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[build-dependencies]
tauri-build = { version = "1.5", features = [] }
tauri-build = { version = "2.0.5", default-features = false , features = [] }

[dependencies]
tauri = { version = "1.5", features = [ "path-all", "fs-all", "shell-open"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
tauri = { version = "2", features = [] }
tauri-plugin-fs = "2"
tauri-plugin-rusqlite = { path = "../../../" }

[features]
# this feature is used for production builds or when `devPath` points to the filesystem
# DO NOT REMOVE!!
custom-protocol = ["tauri/custom-protocol"]
serde_json = "1.0"
17 changes: 17 additions & 0 deletions examples/rusqlite-demo/src-tauri/capabilities/default.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"$schema": "../gen/schemas/desktop-schema.json",
"identifier": "default",
"description": "enables the default permissions",
"windows": [
"main"
],
"permissions": [
"core:default",
"rusqlite:default",
"fs:default",
{
"identifier": "fs:scope",
"allow": [{ "path": "$APPDATA" }, { "path": "$APPDATA/**" }]
}
]
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"default":{"identifier":"default","description":"enables the default permissions","local":true,"windows":["main"],"permissions":["core:default","rusqlite:default","fs:default",{"identifier":"fs:scope","allow":[{"path":"$APPDATA"},{"path":"$APPDATA/**"}]}]}}
Loading