Repository navigation
Add optional initialization hook for static extensions - #96
akpor-kofi wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Thanks for the contribution!
I'd prefer a setup where loading statically linked extensions would be similar to what we do for the existing PowerSync extension, which is exposed through a powersync_init_static function exported from the WebAssembly module.
I'm not sure why we're not just calling powersync_init_static() in main (that would probably work too), but it should be consistent. So given that you need to fork these build scripts either way, how about you statically link the extensions you need and add them to powersync_exported_functions.json?
I would be happy with a PR for @powersync/web that could take an array of additional initialization functions to call when opening connections, which would then load them in addition to the core extension. That shouldn't need any wa-sqlite changes.
|
Thanks, that makes sense. I'll follow the existing I'll open a PR for |
Summary
Add an optional
SQLITE_WASM_EXTRA_INITcallback after successfulsqlite3_initialize(). This lets custom builds register statically linked extensions before JavaScript opens databases, using the existingCFILES_EXTRAandWASQLITE_EXTRA_DEFINESoptions. The default build has no extra callback.Document a complete
decimal.cauto-registration example and the need to deploy matching generated JavaScript/WASM pairs.Validation
Built the same hook in the PowerSync fork with Emscripten 4.0.9 and SQLite 3.53.0. Through PowerSync's real browser worker, Chrome and WebKit executed 10,000-row exact decimal sums, scalar/window probes, persisted reopen, and offline reads. Chrome IndexedDB/OPFS also passed freeze/wake. The generic hook itself uses only SQLite initialization and auto-extension APIs; no PowerSync dependency is added.
Scratch checks are not committed. Reproduction recipe: https://github.com/akpor-kofi/sqlite-decimal-rn
Changelog / Operational Notes
One optional compile-time callback and documentation. Custom builders add their own C source files and define the callback symbol. No change to default exports, adapters, package dependencies, database schemas, environment variables, permissions, background jobs, or provider integrations.