@@ -476,8 +476,8 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncDB
476
476
}
477
477
478
478
/**
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.
481
481
* This is faster than executing separately with each parameter set.
482
482
*/
483
483
async executeBatch ( sql : string , parameters ?: any [ ] [ ] ) {
@@ -637,13 +637,24 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncDB
637
637
638
638
( async ( ) => {
639
639
try {
640
- // Fetch initial data
641
- onResult ( await this . executeReadOnly ( sql , parameters ) ) ;
642
-
643
640
const resolvedTables = await this . resolveTables ( sql , parameters , options ) ;
644
641
642
+ // Fetch initial data
643
+ const result = await this . executeReadOnly ( sql , parameters ) ;
644
+ onResult ( result ) ;
645
+
645
646
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
+ } ,
647
658
{
648
659
...( options ?? { } ) ,
649
660
tables : resolvedTables
@@ -663,11 +674,11 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncDB
663
674
watchWithAsyncGenerator ( sql : string , parameters ?: any [ ] , options ?: SQLWatchOptions ) : AsyncIterable < QueryResult > {
664
675
return new EventIterator < QueryResult > ( ( eventOptions ) => {
665
676
( async ( ) => {
677
+ const resolvedTables = await this . resolveTables ( sql , parameters , options ) ;
678
+
666
679
// Fetch initial data
667
680
eventOptions . push ( await this . executeReadOnly ( sql , parameters ) ) ;
668
681
669
- const resolvedTables = await this . resolveTables ( sql , parameters , options ) ;
670
-
671
682
for await ( const event of this . onChangeWithAsyncGenerator ( {
672
683
...( options ?? { } ) ,
673
684
tables : resolvedTables
0 commit comments