feat(walletkit-db): enable persistent storage for WASM builds#252
Closed
Dzejkop wants to merge 1 commit intofix/walletkit-db-wasm-ffifrom
Closed
feat(walletkit-db): enable persistent storage for WASM builds#252Dzejkop wants to merge 1 commit intofix/walletkit-db-wasm-ffifrom
Dzejkop wants to merge 1 commit intofix/walletkit-db-wasm-ffifrom
Conversation
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
Contributor
Author
|
Superseded — taking a different approach: removing the |
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.
Summary
Adds an optional
wasm-storagefeature towalletkit-dbthat enables persistent storage backends for WASM builds, building on top of the FFI fixes in #251.What changed
walletkit-db/Cargo.toml: Addedwasm-storagefeature flag gating thesqlite-wasm-vfsdependencywalletkit-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 includeswasm_storagemodule whenwasm32 + wasm-storageHow it works
By default,
sqlite-wasm-rsuses an in-memory VFS that loses all data on page reload. Thesqlite-wasm-vfscompanion crate provides two persistent alternatives:Usage:
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-storagecompile check was prepared but couldn't be pushed due to token scope limitations (workflowscope required). The CI diff is: