vlcn-io / js

Components to build apps in JavaScript atop cr-sqlite
MIT License
51 stars 6 forks source link

How to load extensions in the browser? #51

Closed AlexErrant closed 3 months ago

AlexErrant commented 4 months ago

I only see references to loadExtension in NodeJS code. If I wanted to load sqlean in the browser, is that currently unsupported?

Would a workaround be to compile the extension into wa-sqlite, as I assume you've done with cr-sqlite here? https://github.com/vlcn-io/wa-sqlite

tantaman commented 3 months ago

Currently you need to compile extensions into the WASM binary itself.

I had experimented with WASM dynamic modules a ways back but they're not ready for prime time. The issue is that they require the host module (SQLite in this case) to export all symbols required by the extension being loaded.

In other words, if you try to use sqlean as a runtime loadable extension in the browser, it would only work if SQLite already exports all symbols that sqlean requires.

i talked with the Emscripten devs about that a few days ago. They explained that one major limitation with dlopen() is that the loading module must provide any and all exported symbols for the dll. If a module only relies on sqlite3 APIs which have already been exported, it "should work," but as soon as they rely on anything else, whether it be non-exports sqlite3 APIs or system-level APIs which are not linked in to/exported from sqlite3.wasm, it won't work. - https://sqlite.org/forum/forumpost/adac7712d623f8b1