Modular vfs support #55
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.
Follows #54 (includes the patch)
Fixes #33
Following the aforementioned PR, the updated wa-sqlite implementation allows for usage of multiple VFS implementations. In order to support this in the JS stack, this PR provides some minor extensions to the API allowing for specifying of custom wasm initializer.
Public API
The changes are done in such a way that they don't break the existing public API:
The existing public API usage:
The update (allowing for more modular usage of VFS adapters):
Other consumers of
initWasm(e.g.createDbProviderinbrowserdbpackage) accepts the custom initializer (defaulting to the defaultinitWasm):Caching
Finally, the caching is changed a bit. The existing impl uses a single JS glue code (asyncify build), corresponding WASM binary and
IDBBatchAtomicVFS. To that end,crsqlite-wasm(initWasm) caches the initialised and wrapped sqlite API.In this case, however, we can't cache every result of
createWasmInitializer(config)(() => wasmUrl)all the same as different consumers might initialise with different builds (or different VFS adapters), so the caching is extended like so:const apiCache = new Map<string, SQLite3>()instead oflet api: SQLite3 | nullinitWasmwill create a new WASM <-> JS instance)initWasmis cached using"default"as cache keyTODO
In the React package, the
init()function accepts the custom initializer, but that bit in unreachable from the end caller, this could be updated, but I didn't jump through React hoops there at this moment