@@ -267,7 +267,7 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncDB
267
267
/**
268
268
* Wait for the first sync operation to complete.
269
269
*
270
- * @argument request Either an abort signal (after which the promise will complete regardless of
270
+ * @param request Either an abort signal (after which the promise will complete regardless of
271
271
* whether a full sync was completed) or an object providing an abort signal and a priority target.
272
272
* When a priority target is set, the promise may complete when all buckets with the given (or higher)
273
273
* priorities have been synchronized. This can be earlier than a complete sync.
@@ -540,7 +540,7 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncDB
540
540
}
541
541
542
542
/**
543
- * Get a batch of crud data to upload.
543
+ * Get a batch of CRUD data to upload.
544
544
*
545
545
* Returns null if there is no data to upload.
546
546
*
@@ -555,6 +555,9 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncDB
555
555
* This method does include transaction ids in the result, but does not group
556
556
* data by transaction. One batch may contain data from multiple transactions,
557
557
* and a single transaction may be split over multiple batches.
558
+ *
559
+ * @param limit Maximum number of CRUD entries to include in the batch
560
+ * @returns A batch of CRUD operations to upload, or null if there are none
558
561
*/
559
562
async getCrudBatch ( limit : number = DEFAULT_CRUD_BATCH_LIMIT ) : Promise < CrudBatch | null > {
560
563
const result = await this . getAll < CrudEntryJSON > (
@@ -591,6 +594,8 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncDB
591
594
*
592
595
* Unlike {@link getCrudBatch}, this only returns data from a single transaction at a time.
593
596
* All data for the transaction is loaded into memory.
597
+ *
598
+ * @returns A transaction of CRUD operations to upload, or null if there are none
594
599
*/
595
600
async getNextCrudTransaction ( ) : Promise < CrudTransaction | null > {
596
601
return await this . readTransaction ( async ( tx ) => {
@@ -628,6 +633,8 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncDB
628
633
* Get an unique client id for this database.
629
634
*
630
635
* The id is not reset when the database is cleared, only when the database is deleted.
636
+ *
637
+ * @returns A unique identifier for the database instance
631
638
*/
632
639
async getClientId ( ) : Promise < string > {
633
640
return this . bucketStorageAdapter . getClientId ( ) ;
@@ -652,14 +659,27 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncDB
652
659
}
653
660
654
661
/**
655
- * Execute a write (INSERT/UPDATE/DELETE) query
662
+ * Execute a SQL write (INSERT/UPDATE/DELETE) query
656
663
* and optionally return results.
664
+ *
665
+ * @param sql The SQL query to execute
666
+ * @param parameters Optional array of parameters to bind to the query
667
+ * @returns The query result as an object with structured key-value pairs
657
668
*/
658
669
async execute ( sql : string , parameters ?: any [ ] ) {
659
670
await this . waitForReady ( ) ;
660
671
return this . database . execute ( sql , parameters ) ;
661
672
}
662
673
674
+ /**
675
+ * Execute a SQL write (INSERT/UPDATE/DELETE) query directly on the database without any PowerSync processing.
676
+ * This bypasses certain PowerSync abstractions and is useful for accessing the raw database results.
677
+ *
678
+ * @param sql The SQL query to execute
679
+ * @param parameters Optional array of parameters to bind to the query
680
+ * @returns The raw query result from the underlying database as a nested array of raw values, where each row is
681
+ * represented as an array of column values without field names.
682
+ */
663
683
async executeRaw ( sql : string , parameters ?: any [ ] ) {
664
684
await this . waitForReady ( ) ;
665
685
return this . database . executeRaw ( sql , parameters ) ;
@@ -669,6 +689,10 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncDB
669
689
* Execute a write query (INSERT/UPDATE/DELETE) multiple times with each parameter set
670
690
* and optionally return results.
671
691
* This is faster than executing separately with each parameter set.
692
+ *
693
+ * @param sql The SQL query to execute
694
+ * @param parameters Optional 2D array of parameter sets, where each inner array is a set of parameters for one execution
695
+ * @returns The query result
672
696
*/
673
697
async executeBatch ( sql : string , parameters ?: any [ ] [ ] ) {
674
698
await this . waitForReady ( ) ;
@@ -677,6 +701,10 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncDB
677
701
678
702
/**
679
703
* Execute a read-only query and return results.
704
+ *
705
+ * @param sql The SQL query to execute
706
+ * @param parameters Optional array of parameters to bind to the query
707
+ * @returns An array of results
680
708
*/
681
709
async getAll < T > ( sql : string , parameters ?: any [ ] ) : Promise < T [ ] > {
682
710
await this . waitForReady ( ) ;
@@ -685,6 +713,10 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncDB
685
713
686
714
/**
687
715
* Execute a read-only query and return the first result, or null if the ResultSet is empty.
716
+ *
717
+ * @param sql The SQL query to execute
718
+ * @param parameters Optional array of parameters to bind to the query
719
+ * @returns The first result if found, or null if no results are returned
688
720
*/
689
721
async getOptional < T > ( sql : string , parameters ?: any [ ] ) : Promise < T | null > {
690
722
await this . waitForReady ( ) ;
@@ -693,6 +725,11 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncDB
693
725
694
726
/**
695
727
* Execute a read-only query and return the first result, error if the ResultSet is empty.
728
+ *
729
+ * @param sql The SQL query to execute
730
+ * @param parameters Optional array of parameters to bind to the query
731
+ * @returns The first result matching the query
732
+ * @throws Error if no rows are returned
696
733
*/
697
734
async get < T > ( sql : string , parameters ?: any [ ] ) : Promise < T > {
698
735
await this . waitForReady ( ) ;
@@ -724,6 +761,11 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncDB
724
761
* Open a read-only transaction.
725
762
* Read transactions can run concurrently to a write transaction.
726
763
* Changes from any write transaction are not visible to read transactions started before it.
764
+ *
765
+ * @param callback Function to execute within the transaction
766
+ * @param lockTimeout Time in milliseconds to wait for a lock before throwing an error
767
+ * @returns The result of the callback
768
+ * @throws Error if the lock cannot be obtained within the timeout period
727
769
*/
728
770
async readTransaction < T > (
729
771
callback : ( tx : Transaction ) => Promise < T > ,
@@ -744,6 +786,11 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncDB
744
786
* Open a read-write transaction.
745
787
* This takes a global lock - only one write transaction can execute against the database at a time.
746
788
* Statements within the transaction must be done on the provided {@link Transaction} interface.
789
+ *
790
+ * @param callback Function to execute within the transaction
791
+ * @param lockTimeout Time in milliseconds to wait for a lock before throwing an error
792
+ * @returns The result of the callback
793
+ * @throws Error if the lock cannot be obtained within the timeout period
747
794
*/
748
795
async writeTransaction < T > (
749
796
callback : ( tx : Transaction ) => Promise < T > ,
@@ -818,6 +865,11 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncDB
818
865
* Source tables are automatically detected using `EXPLAIN QUERY PLAN`.
819
866
*
820
867
* Note that the `onChange` callback member of the handler is required.
868
+ *
869
+ * @param sql The SQL query to execute
870
+ * @param parameters Optional array of parameters to bind to the query
871
+ * @param handler Callbacks for handling results and errors
872
+ * @param options Options for configuring watch behavior
821
873
*/
822
874
watchWithCallback ( sql : string , parameters ?: any [ ] , handler ?: WatchHandler , options ?: SQLWatchOptions ) : void {
823
875
const { onResult, onError = ( e : Error ) => this . options . logger ?. error ( e ) } = handler ?? { } ;
@@ -863,6 +915,11 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncDB
863
915
* Execute a read query every time the source tables are modified.
864
916
* Use {@link SQLWatchOptions.throttleMs} to specify the minimum interval between queries.
865
917
* Source tables are automatically detected using `EXPLAIN QUERY PLAN`.
918
+ *
919
+ * @param sql The SQL query to execute
920
+ * @param parameters Optional array of parameters to bind to the query
921
+ * @param options Options for configuring watch behavior
922
+ * @returns An AsyncIterable that yields QueryResults whenever the data changes
866
923
*/
867
924
watchWithAsyncGenerator ( sql : string , parameters ?: any [ ] , options ?: SQLWatchOptions ) : AsyncIterable < QueryResult > {
868
925
return new EventIterator < QueryResult > ( ( eventOptions ) => {
@@ -883,6 +940,16 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncDB
883
940
} ) ;
884
941
}
885
942
943
+ /**
944
+ * Resolves the list of tables that are used in a SQL query.
945
+ * If tables are specified in the options, those are used directly.
946
+ * Otherwise, analyzes the query using EXPLAIN to determine which tables are accessed.
947
+ *
948
+ * @param sql The SQL query to analyze
949
+ * @param parameters Optional parameters for the SQL query
950
+ * @param options Optional watch options that may contain explicit table list
951
+ * @returns Array of table names that the query depends on
952
+ */
886
953
async resolveTables ( sql : string , parameters ?: any [ ] , options ?: SQLWatchOptions ) : Promise < string [ ] > {
887
954
const resolvedTables = options ?. tables ? [ ...options . tables ] : [ ] ;
888
955
if ( ! options ?. tables ) {
@@ -955,7 +1022,9 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncDB
955
1022
*
956
1023
* Note that the `onChange` callback member of the handler is required.
957
1024
*
958
- * Returns dispose function to stop watching.
1025
+ * @param handler Callbacks for handling change events and errors
1026
+ * @param options Options for configuring watch behavior
1027
+ * @returns A dispose function to stop watching for changes
959
1028
*/
960
1029
onChangeWithCallback ( handler ?: WatchOnChangeHandler , options ?: SQLWatchOptions ) : ( ) => void {
961
1030
const { onChange, onError = ( e : Error ) => this . options . logger ?. error ( e ) } = handler ?? { } ;
@@ -1008,8 +1077,11 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncDB
1008
1077
*
1009
1078
* This is preferred over {@link watchWithAsyncGenerator} when multiple queries need to be performed
1010
1079
* together when data is changed.
1080
+ *
1081
+ * Note: do not declare this as `async *onChange` as it will not work in React Native.
1011
1082
*
1012
- * Note, do not declare this as `async *onChange` as it will not work in React Native
1083
+ * @param options Options for configuring watch behavior
1084
+ * @returns An AsyncIterable that yields change events whenever the specified tables change
1013
1085
*/
1014
1086
onChangeWithAsyncGenerator ( options ?: SQLWatchOptions ) : AsyncIterable < WatchOnChangeEvent > {
1015
1087
const resolvedOptions = options ?? { } ;
0 commit comments