Let yaak-models compile for wasm32-unknown-unknown - #556
Merged
Conversation
Bump rusqlite to 0.38, the first release with a wasm32 target, and remove the two things in the model layer that assumed a native host: - The connection pool. r2d2 is thread-based all the way down, so a small SqlitePool/SqliteConn seam replaces it in signatures. Natively these are type aliases for the r2d2 types; on wasm, a single checked-out connection. - A migration timer using Instant, which has no wasm implementation. sea-query-rusqlite is vendored (60 lines): no upstream release pairs sea-query 0.32 with rusqlite >= 0.38, and this avoids a sea-query 1.0 bump. No query or model code changes. Verified: yaak-models builds for wasm32 and runs its migrations in a browser tab; native tests pass; CLI and app compile.
Greptile SummaryThe PR makes the database and model crates compatible with
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains.
|
| Filename | Overview |
|---|---|
| crates/common/yaak-database/src/pool.rs | Adds the target-specific pool abstraction and resolves the previously reported wasm nested-checkout failure by returning shared connection handles. |
| crates/yaak-models/src/query_manager.rs | Migrates QueryManager to the pool abstraction and opens transactions from immutable connection references. |
| crates/yaak-models/src/lib.rs | Centralizes target-specific file and in-memory pool creation while preserving native connection initialization. |
| crates/yaak-models/src/migrate.rs | Adapts migration transactions to shared connection handles and disables unavailable monotonic timing on wasm. |
| crates/common/yaak-database/Cargo.toml | Moves thread-based pooling to native-only dependencies and enables browser randomness support on wasm. |
| Cargo.lock | Records the coordinated SQLite, pooling, wasm VFS, and SeaQuery dependency updates. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[yaak-models query layer] --> B[SqlitePool seam]
B -->|Native| C[r2d2 connection pool]
B -->|wasm32| D[Shared Rc SQLite connection]
C --> E[SQLite database]
D --> F[Browser-registered SQLite VFS]
Reviews (2): Last reviewed commit: "Bump sea-query to 1.0 and drop the vendo..." | Re-trigger Greptile
Review caught that the model layer nests connections — a helper holding one calls another that asks for its own — which r2d2 absorbs natively but a single-slot pool would refuse, and QueryManager::connect turns that into a panic. The only reason the pool lent exclusively was to offer &mut for opening transactions. Transaction::new_unchecked takes &Connection and is exactly what transaction_with_behavior calls, so use it at both sites and drop DerefMut from the seam. The wasm SqliteConn is then a shared handle and nested get() is free. Verified in a tab: connect() while another is held, and a read from a fresh connect() inside an open with_tx, both work.
The vendored sea-query-rusqlite existed only to pair sea-query 0.32 with rusqlite 0.38. Taking sea-query 1.0 lets upstream 0.8 do that instead. The 1.0 change that reaches us is ExprTrait: comparison and null-check methods moved onto a trait that has to be in scope, so `.eq()` otherwise resolves to PartialEq. One import per file that builds a where-clause; no other changes. 1.0 also stops boxing String/Bytes/chrono values inside sea_query::Value, which is what the vendored binder's box_to_sql! dance was for.
Member
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Groundwork for running the real model layer (SQLite included) in a browser tab for web.yaak.app.
r2d2_sqlite0.32,libsqlite3-sys0.36 in lockstep); sea-query 0.32 → 1.0 so upstreamsea-query-rusqlite0.8 pairs the two. The only 1.0 change that reaches us isExprTraitneeding to be in scope — one import per file that builds a where-clauseSqlitePool/SqliteConnseam inyaak-database. r2d2 is thread-based and cannot run on wasm; natively these are type aliases for the r2d2 types, on wasm a shared handle to a single connection. The pool never hands out&mut(transactions open viaTransaction::new_unchecked), so the nestedconnect()pattern the model layer relies on works on both targets. r2d2 becomes a native-only dependencygetrandom/uuidjsfeatures on wasm; the migrator'sInstanttimer cfg'd out thereNo query or model logic changes. Native tests pass; CLI and app compile.
Verified end to end:
yaak-modelsruns its 70 migrations,list_workspacesbootstrap andupsert_http_requestin a browser tab against an IndexedDB-backed VFS, persists across reload, and nested connections (including a read inside an openwith_tx) work. The wasm crate that does that is the next PR.Building for wasm32 needs a clang with a WebAssembly backend (
sqlite-wasm-rscompiles sqlite3.c at build time). Apple clang has none; Homebrew LLVM works viaCC_wasm32_unknown_unknown=/opt/homebrew/opt/llvm/bin/clang AR_wasm32_unknown_unknown=/opt/homebrew/opt/llvm/bin/llvm-ar. No CI job for the wasm target yet.