feat: enabling OPFS for client-wasm #300
Open
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.
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 WASMinitSqlite3function is within the context of the client and passes the path as thelocateFilearg into thesqlite3InitModulethat already exists within the original clientcreateClientas we would normally. However, under the hood, we've changed two lines within the custom client, basically using thissqlite3.oo1.OpfsDbinstead of thissqlite3.oo1.DBProblems and reasons for this approach
assets/sqlite3.wasmpath (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-wasmneeds the declared and initialisedsqlite3WASM file within thewasm.jsfile that declares the client and then directly referencessqlite3and uses it after it's been initialisedlocateFilein 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-experimentaldependencies files)browser.runtime.getURLopfs-proxyone, no matter what I triedlibsql-wasm-experimentalmodule 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 themopfsDbrather than justDBDBDBtoopfsDblibsql-wasm-experimentalshows, 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.syncbeing disabledWhy this is important for the broader LibSQL project
Next Steps