Skip to content

Let yaak-models compile for wasm32-unknown-unknown - #556

Merged
gschier merged 3 commits into
mainfrom
claude/wasm-ready-models
Aug 15, 2026
Merged

Let yaak-models compile for wasm32-unknown-unknown#556
gschier merged 3 commits into
mainfrom
claude/wasm-ready-models

Conversation

@gschier

@gschier gschier commented Aug 15, 2026

Copy link
Copy Markdown
Member

Groundwork for running the real model layer (SQLite included) in a browser tab for web.yaak.app.

  • rusqlite 0.32 → 0.38, the first release with a wasm32 target (r2d2_sqlite 0.32, libsqlite3-sys 0.36 in lockstep); sea-query 0.32 → 1.0 so upstream sea-query-rusqlite 0.8 pairs the two. The only 1.0 change that reaches us is ExprTrait needing to be in scope — one import per file that builds a where-clause
  • SqlitePool / SqliteConn seam in yaak-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 via Transaction::new_unchecked), so the nested connect() pattern the model layer relies on works on both targets. r2d2 becomes a native-only dependency
  • getrandom/uuid js features on wasm; the migrator's Instant timer cfg'd out there

No query or model logic changes. Native tests pass; CLI and app compile.

Verified end to end: yaak-models runs its 70 migrations, list_workspaces bootstrap and upsert_http_request in a browser tab against an IndexedDB-backed VFS, persists across reload, and nested connections (including a read inside an open with_tx) work. The wasm crate that does that is the next PR.

Building for wasm32 needs a clang with a WebAssembly backend (sqlite-wasm-rs compiles sqlite3.c at build time). Apple clang has none; Homebrew LLVM works via CC_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.

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-apps

greptile-apps Bot commented Aug 15, 2026

Copy link
Copy Markdown

Greptile Summary

The PR makes the database and model crates compatible with wasm32-unknown-unknown while retaining native r2d2 pooling.

  • Introduces target-specific SqlitePool and SqliteConn implementations.
  • Uses a shared single SQLite connection on wasm and native r2d2 pools elsewhere.
  • Updates SQLite and SeaQuery dependencies and adapts query imports.
  • Configures browser-compatible randomness and migration timing.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Important Files Changed

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]
Loading

Reviews (2): Last reviewed commit: "Bump sea-query to 1.0 and drop the vendo..." | Re-trigger Greptile

Comment thread crates/common/yaak-database/src/pool.rs Outdated
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.
@gschier

gschier commented Aug 15, 2026

Copy link
Copy Markdown
Member Author

@greptile-apps

@gschier
gschier merged commit 32e92d4 into main Aug 15, 2026
7 checks passed
@gschier
gschier deleted the claude/wasm-ready-models branch August 15, 2026 21:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant