-
Notifications
You must be signed in to change notification settings - Fork 54
feat: enabling OPFS for client-wasm #300
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Gallevy
commented
Mar 29, 2025
I'm also interesting in something similar, I'll also add that client-wasm only works in memory in browsers is somewhat lacking documentation/explanation as well. Thanks for the PR. I would love to see this gaining popularity
DougAnderson444
commented
Apr 13, 2025
There is some prior art here for sqlite in opfs: https://github.com/Spxg/sqlite-wasm-rs/blob/master/sqlite-wasm-rs/src/vfs/sahpool.rs
imdoge
commented
Jul 28, 2025
https://github.com/rhashimoto/wa-sqlite
seems OPFSAdaptiveVFS is based on OPFS's VFS
This is not a finished PR, it's to start a discussion so I can better understand how codeowners would want this work done, if at all
What and why I've done this
How this works
browser.runtime.getURL('assets/sqlite3.wasm)
to get the location of the sqlite WASMinitSqlite3
function is within the context of the client and passes the path as thelocateFile
arg into thesqlite3InitModule
that already exists within the original clientcreateClient
as we would normally. However, under the hood, we've changed two lines within the custom client, basically using thissqlite3.oo1.OpfsDb
instead of thissqlite3.oo1.DB
Problems and reasons for this approach
assets/sqlite3.wasm
path (yes, it's possible to bundle the WASM file as a string, even if it is very inefficient, but I believe I ended up with CSP restrictions set by the browser that cannot be overridden)@libsql/client-wasm
needs the declared and initialisedsqlite3
WASM file within thewasm.js
file that declares the client and then directly referencessqlite3
and uses it after it's been initialisedlocateFile
in it's params along with the url to import the location of the wasm file (even though this is not directly within the wasm client and is in thelibsql-wasm-experimental
dependencies files)browser.runtime.getURL
opfs-proxy
one, no matter what I triedlibsql-wasm-experimental
module directly into my code, as this means the web workers are technically my bundled code and the browser will let them run without issue when the module, that's also now within my code, tries to call themopfsDb
rather than justDB
DB
DB
toopfsDb
libsql-wasm-experimental
shows, this is just regularsqlite-wasm
, OPFS works like a charm, the only issue I could really see was that obviously none of the turso functionality was actually available, e.g.sync
being disabledWhy this is important for the broader LibSQL project
Next Steps