@@ -12,25 +12,13 @@ export async function _openDB(
1212 options : { useWebWorker : boolean } = { useWebWorker : true }
1313) : Promise < DBFunctionsInterface > {
1414 const { default : moduleFactory } = await import ( '@journeyapps/wa-sqlite/dist/wa-sqlite-async.mjs' ) ;
15- const module = await moduleFactory ( {
16- locateFile ( path : string ) {
17- if ( path . includes ( 'wa-sqlite-async' ) ) {
18- return new URL ( '@journeyapps/wa-sqlite/dist/wa-sqlite-async.wasm' , import . meta. url ) . href ;
19- } else if ( path . includes ( 'libpowersync' ) ) {
20- return new URL ( '@journeyapps/wa-sqlite/dist/libpowersync-async.wasm' , import . meta. url ) . href ;
21- }
22- return path ;
23- }
24- } ) ;
15+ const module = await moduleFactory ( ) ;
2516 const sqlite3 = SQLite . Factory ( module ) ;
2617
27- const extScope : any = { } ;
28- // This needs improvements in production with Vite
29- await module . loadDynamicLibrary ( 'libpowersync-async.wasm' , { loadAsync : true } , extScope ) ;
30-
31- // This calls sqlite3_auto_extension(sqlite3_powersync_init).
32- // For generic extensions, we'd need to call sqlite3_auto_extension directly.
33- extScope . powersync_init_static ( ) ;
18+ /**
19+ * Register the PowerSync core SQLite extension
20+ */
21+ module . ccall ( 'setup_powersync' , 'int' , [ ] ) ;
3422
3523 const { IDBBatchAtomicVFS } = await import ( '@journeyapps/wa-sqlite/src/examples/IDBBatchAtomicVFS.js' ) ;
3624 // @ts -ignore TODO update types
@@ -55,7 +43,10 @@ export async function _openDB(
5543 Array . from ( listeners . values ( ) ) . forEach ( ( l ) => l ( event ) ) ;
5644 }
5745
58- sqlite3 . register_table_onchange_hook ( db , ( opType : number , tableName : string , rowId : number ) => {
46+ sqlite3 . update_hook ( db , ( updateType : number , dbName : string | null , tableName : string | null ) => {
47+ if ( ! tableName ) {
48+ return ;
49+ }
5950 updatedTables . add ( tableName ) ;
6051 if ( updateTimer == null ) {
6152 updateTimer = setTimeout ( fireUpdates , 0 ) ;
0 commit comments