Skip to content

feat(walletkit-db): enable persistent storage for WASM builds#252

Closed
Dzejkop wants to merge 1 commit intofix/walletkit-db-wasm-ffifrom
feat/walletkit-db-wasm-storage
Closed

feat(walletkit-db): enable persistent storage for WASM builds#252
Dzejkop wants to merge 1 commit intofix/walletkit-db-wasm-ffifrom
feat/walletkit-db-wasm-storage

Conversation

@Dzejkop
Copy link
Copy Markdown
Contributor

@Dzejkop Dzejkop commented Feb 26, 2026

Summary

Adds an optional wasm-storage feature to walletkit-db that enables persistent storage backends for WASM builds, building on top of the FFI fixes in #251.

What changed

  • walletkit-db/Cargo.toml: Added wasm-storage feature flag gating the sqlite-wasm-vfs dependency
  • walletkit-db/src/wasm_storage.rs: New module exposing two persistent VFS backends:
    • install_opfs_sahpool() — OPFS-backed, full durability (Dedicated Worker only)
    • install_relaxed_idb() — IndexedDB-backed, relaxed durability (any context)
  • walletkit-db/src/lib.rs: Conditionally includes wasm_storage module when wasm32 + wasm-storage

How it works

By default, sqlite-wasm-rs uses an in-memory VFS that loses all data on page reload. The sqlite-wasm-vfs companion crate provides two persistent alternatives:

MemoryVFS (default) OPFS sahpool IndexedDB relaxed-idb
Storage RAM OPFS IndexedDB
Contexts All Dedicated Worker All
Full durability
Relaxed durability

Usage:

// Call once before opening any database:
walletkit_db::wasm_storage::install_opfs_sahpool(None).await?;
// — or —
walletkit_db::wasm_storage::install_relaxed_idb(None).await?;

// Then open databases as usual — they will be persisted:
let conn = Connection::open(Path::new("app.db"), false)?;

Validation

  • cargo check -p walletkit-db --target wasm32-unknown-unknown (without feature)
  • cargo check -p walletkit-db --target wasm32-unknown-unknown --features wasm-storage (with feature)
  • cargo check -p walletkit-db (native, unchanged)

Note

CI workflow change to add the --features wasm-storage compile check was prepared but couldn't be pushed due to token scope limitations (workflow scope required). The CI diff is:

- name: Run WASM compile check (with wasm-storage)
  run: cargo check -p walletkit-db --target wasm32-unknown-unknown --features wasm-storage

Add optional `wasm-storage` feature that brings in `sqlite-wasm-vfs` to
enable persistent storage backends for WASM builds:

- OPFS (sahpool): full durability, requires Dedicated Worker context
- IndexedDB (relaxed-idb): relaxed durability, works in any context

The feature exposes a `wasm_storage` module with `install_opfs_sahpool()`
and `install_relaxed_idb()` async functions. Calling either one before
opening a database registers the persistent VFS as the default, making
`Connection::open` persist data transparently.

Without the feature flag, WASM builds continue to use the in-memory VFS.

Note: CI workflow change for wasm-storage compile check is not included
due to token scope limitations — should be added separately.

Co-authored-by: otto@toolsforhumanity.com
@Dzejkop
Copy link
Copy Markdown
Contributor Author

Dzejkop commented Feb 26, 2026

Superseded — taking a different approach: removing the storage feature gate entirely instead of adding a new wasm-storage feature.

@Dzejkop Dzejkop closed this Feb 26, 2026
@paolodamico paolodamico deleted the feat/walletkit-db-wasm-storage branch March 11, 2026 18:05
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