Skip to content

Commit a46ef3f

Browse files
committed
feat: refactor to separate pure Rust
1 parent 2fb37b9 commit a46ef3f

32 files changed

Lines changed: 2432 additions & 781 deletions

Cargo.lock

Lines changed: 535 additions & 411 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ resolver = "3"
33
members = [
44
"crates/sqlx-sqlite-conn-mgr",
55
"crates/sqlx-sqlite-observer",
6+
"crates/sqlx-sqlite-toolkit",
67
]
78

89
[package]
@@ -33,6 +34,15 @@ sqlx = { version = "0.8.6", features = ["sqlite", "json", "time", "runtime-tokio
3334
# Connection manager
3435
sqlx-sqlite-conn-mgr = { path = "crates/sqlx-sqlite-conn-mgr" }
3536

37+
# Toolkit (high-level API — builders, transactions, decoding)
38+
sqlx-sqlite-toolkit = { path = "crates/sqlx-sqlite-toolkit", features = ["observer"] }
39+
40+
# Observer types (for payload conversion)
41+
sqlx-sqlite-observer = { path = "crates/sqlx-sqlite-observer", features = ["conn-mgr"] }
42+
43+
# Async stream support for observer subscriptions
44+
futures = "0.3"
45+
3646
[build-dependencies]
3747
tauri-plugin = { version = "2.5.1", features = ["build"] }
3848

README.md

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,50 @@ SQLite database interface for Tauri applications using
2121
* **Type Safety**: Full TypeScript bindings
2222
* **Migration Support**: SQLx's migration framework
2323
* **Resource Management**: Proper cleanup on application exit
24+
* **Optional Change Notifications**: SQLite hooks for reactive change notifications
2425

2526
## Architecture
2627

28+
The plugin is built from three standalone Rust crates, each usable independently
29+
without Tauri:
30+
31+
```text
32+
┌───────────────────────────────────────────────────────────────┐
33+
│ tauri-plugin-sqlite (src/) │
34+
│ Tauri commands, state management, permissions │
35+
├───────────────────────────────────────────────────────────────┤
36+
│ sqlx-sqlite-toolkit (crate) │
37+
│ DatabaseWrapper, builders, transactions │
38+
│ JSON decoding, optional observer integration │
39+
├───────────────────────────────────────────────────────────────┤
40+
│ sqlx-sqlite-conn-mgr (crate) │ sqlx-sqlite-observer (crate) │
41+
│ Connection pools, │ Change notifications │
42+
│ single writer, │ via SQLite hooks │
43+
│ WAL mode, attached │ broadcast streams │
44+
│ databases │ (optional) │
45+
└───────────────────────────────┴───────────────────────────────┘
46+
```
47+
48+
* **[`sqlx-sqlite-conn-mgr`](crates/sqlx-sqlite-conn-mgr/)** — Low-level connection
49+
management: read pool, exclusive writer, WAL mode, attached databases
50+
* **[`sqlx-sqlite-observer`](crates/sqlx-sqlite-observer/)** — Reactive change
51+
notifications using SQLite's native preupdate/commit/rollback hooks
52+
* **[`sqlx-sqlite-toolkit`](crates/sqlx-sqlite-toolkit/)** — High-level API:
53+
`DatabaseWrapper`, builder-pattern queries, interruptible transactions, JSON
54+
type decoding. Optionally integrates the observer behind a feature flag.
55+
* **`tauri-plugin-sqlite` (this package)** — Thin Tauri layer: IPC commands, path
56+
resolution, state management, permissions
57+
58+
### Query Routing
59+
2760
| Operation Type | Method | Pool Used | Concurrency |
2861
| -------------------- | --------------- | ---------------- | ------------------- |
2962
| SELECT (multiple) | `fetchAll()` | Read pool | Multiple concurrent |
3063
| SELECT (single) | `fetchOne()` | Read pool | Multiple concurrent |
3164
| INSERT/UPDATE/DELETE | `execute()` | Write connection | Serialized |
3265
| DDL (CREATE, etc.) | `execute()` | Write connection | Serialized |
3366

34-
See [`crates/sqlx-sqlite-conn-mgr/README.md`](crates/sqlx-sqlite-conn-mgr/README.md) for
35-
connection manager internals.
67+
See individual crate READMEs for detailed API documentation.
3668

3769
## Installation
3870

api-iife.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ fn main() {
1111
"close",
1212
"close_all",
1313
"remove",
14+
"get_migration_events",
15+
"observe",
16+
"subscribe",
17+
"unsubscribe",
18+
"unobserve",
1419
])
1520
.build();
1621
}

crates/sqlx-sqlite-observer/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ keywords = ["sqlite", "sqlx", "reactive", "observer", "database"]
1313
categories = ["database", "asynchronous"]
1414

1515
[features]
16-
conn-mgr = ["dep:sqlx-sqlite-conn-mgr"]
1716
# Bundle SQLite by default - preupdate hooks require SQLITE_ENABLE_PREUPDATE_HOOK
1817
# which most system SQLite libraries don't have enabled.
1918
default = ["bundled"]
2019
bundled = ["libsqlite3-sys/bundled"]
20+
conn-mgr = ["dep:sqlx-sqlite-conn-mgr"]
2121

2222
[dependencies]
2323
tokio = { version = "1.49.0", features = ["sync"] }
@@ -29,7 +29,7 @@ regex = "1.12.3"
2929
sqlx = { version = "0.8.6", features = ["sqlite", "runtime-tokio"], default-features = false }
3030
# Required for preupdate_hook - SQLite must be compiled with SQLITE_ENABLE_PREUPDATE_HOOK
3131
libsqlite3-sys = { version = "0.30.1", features = ["preupdate_hook"] }
32-
sqlx-sqlite-conn-mgr = { version = "0.8.6", optional = true }
32+
sqlx-sqlite-conn-mgr = { path = "../sqlx-sqlite-conn-mgr", version = "0.8.6", optional = true }
3333

3434
[dev-dependencies]
3535
tokio = { version = "1.49.0", features = ["full", "macros"] }

crates/sqlx-sqlite-observer/README.md

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -62,19 +62,19 @@ The library uses SQLite's native hooks for transaction-safe change tracking:
6262
│ (captures data) │ │ (Vec<Event>) │ │ │
6363
└─────────────────┘ └────────┬────────┘ └─────────────────┘
6464
│ ▲
65-
┌────────────┼────────────┐
66-
│ │
67-
┌─────▼────┐ ┌────▼─────┐
68-
│ COMMIT │ │ ROLLBACK │
69-
└─────┬────┘ └────┬─────┘
70-
│ │
71-
▼ ▼
72-
on_commit() on_rollback()
73-
│ │
74-
│ buffer.clear()
75-
│ (discard)
76-
77-
└───────────────────────────────────┘
65+
┌────────────|
66+
│ │
67+
┌─────▼────┐ ┌────▼─────┐
68+
│ COMMIT │ │ ROLLBACK │
69+
└─────┬────┘ └────┬─────┘
70+
│ │
71+
▼ ▼
72+
on_commit() on_rollback()
73+
│ │
74+
│ buffer.clear()
75+
│ (discard)
76+
77+
└───────────────────────────────────┘
7878
change_tx.send()
7979
(publish)
8080
```
@@ -283,6 +283,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
283283
let config = ObserverConfig::new()
284284
.with_tables(["users"])
285285
.with_capture_values(false);
286+
286287
let observer = SqliteObserver::new(
287288
SqlitePool::connect("sqlite:mydb.db").await?,
288289
config,
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
[package]
2+
name = "sqlx-sqlite-toolkit"
3+
# Sync major.minor with major.minor of SQLx crate
4+
version = "0.8.6"
5+
license = "MIT"
6+
edition = "2024"
7+
rust-version = "1.89"
8+
9+
[features]
10+
default = []
11+
observer = ["dep:sqlx-sqlite-observer"]
12+
13+
[dependencies]
14+
sqlx-sqlite-conn-mgr = { path = "../sqlx-sqlite-conn-mgr" }
15+
sqlx-sqlite-observer = { path = "../sqlx-sqlite-observer", features = ["conn-mgr"], optional = true }
16+
sqlx = { version = "0.8.6", features = ["sqlite", "json", "time", "runtime-tokio"] }
17+
serde = { version = "1.0", features = ["derive"] }
18+
serde_json = "1.0"
19+
thiserror = "2.0"
20+
indexmap = { version = "2.12", features = ["serde"] }
21+
base64 = "0.22"
22+
time = "0.3"
23+
uuid = { version = "1.11", features = ["v4"] }
24+
tokio = { version = "1.48.0", features = ["sync", "rt"] }
25+
tracing = { version = "0.1", default-features = false, features = ["std", "release_max_level_off"] }
26+
27+
[dev-dependencies]
28+
tempfile = "3.23.0"
29+
tokio = { version = "1.48.0", features = ["rt-multi-thread", "macros"] }

0 commit comments

Comments
 (0)