@@ -476,8 +476,8 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncDB
476476 }
477477
478478 /**
479- * Execute a write query (INSERT/UPDATE/DELETE) multiple times with each parameter set
480- * and optionally return results.
479+ * Execute a write query (INSERT/UPDATE/DELETE) multiple times with each parameter set
480+ * and optionally return results.
481481 * This is faster than executing separately with each parameter set.
482482 */
483483 async executeBatch ( sql : string , parameters ?: any [ ] [ ] ) {
@@ -637,13 +637,24 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncDB
637637
638638 ( async ( ) => {
639639 try {
640- // Fetch initial data
641- onResult ( await this . executeReadOnly ( sql , parameters ) ) ;
642-
643640 const resolvedTables = await this . resolveTables ( sql , parameters , options ) ;
644641
642+ // Fetch initial data
643+ const result = await this . executeReadOnly ( sql , parameters ) ;
644+ onResult ( result ) ;
645+
645646 this . onChangeWithCallback (
646- { onChange : async ( ) => onResult ( await this . executeReadOnly ( sql , parameters ) ) , onError } ,
647+ {
648+ onChange : async ( ) => {
649+ try {
650+ const result = await this . executeReadOnly ( sql , parameters ) ;
651+ onResult ( result ) ;
652+ } catch ( error ) {
653+ onError ?.( error ) ;
654+ }
655+ } ,
656+ onError
657+ } ,
647658 {
648659 ...( options ?? { } ) ,
649660 tables : resolvedTables
@@ -663,11 +674,11 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncDB
663674 watchWithAsyncGenerator ( sql : string , parameters ?: any [ ] , options ?: SQLWatchOptions ) : AsyncIterable < QueryResult > {
664675 return new EventIterator < QueryResult > ( ( eventOptions ) => {
665676 ( async ( ) => {
677+ const resolvedTables = await this . resolveTables ( sql , parameters , options ) ;
678+
666679 // Fetch initial data
667680 eventOptions . push ( await this . executeReadOnly ( sql , parameters ) ) ;
668681
669- const resolvedTables = await this . resolveTables ( sql , parameters , options ) ;
670-
671682 for await ( const event of this . onChangeWithAsyncGenerator ( {
672683 ...( options ?? { } ) ,
673684 tables : resolvedTables
0 commit comments