Enumerations
Classes
Interfaces
AbstractQueryProcessorOptions<Data, Settings>
Internal
Extended by
Type Parameters
Properties
AbstractStreamingSyncImplementationOptions
Internal
Extends
Extended by
Properties
AdditionalConnectionOptions
Internal
Extended by
Properties
| Property | Type | Description |
|---|
crudUploadThrottleMs? | number | Backend Connector CRUD operations are throttled to occur at most every crudUploadThrottleMs milliseconds. |
retryDelayMs? | number | Delay for retrying sync streaming operations from the PowerSync backend after an error occurs. |
ArrayQueryDefinition<RowType>
Options for building a query with AbstractPowerSyncDatabase#query.
This query will be executed with AbstractPowerSyncDatabase#getAll.
Type Parameters
| Type Parameter | Default type |
|---|
RowType | unknown |
Properties
| Property | Type | Description |
|---|
mapper? | (row: Record<string, unknown>) => RowType | Maps the raw SQLite row to a custom typed object. Example mapper: (row) => ({ ...row, created_at: new Date(row.created_at as string), }) |
parameters? | readonly Readonly<QueryParam>[] | - |
sql | string | - |
AsyncDatabaseConnection<Config>
Internal
An async Database connection which provides basic async SQL methods.
This is usually a proxied through a web worker.
Type Parameters
Methods
close()
Returns
Promise<void>
execute()
execute(sql, params?): Promise<ProxiedQueryResult>
Parameters
| Parameter | Type |
|---|
sql | string |
params? | any[] |
Returns
Promise<ProxiedQueryResult>
executeBatch()
executeBatch(sql, params?): Promise<ProxiedQueryResult>
Parameters
| Parameter | Type |
|---|
sql | string |
params? | any[] |
Returns
Promise<ProxiedQueryResult>
executeRaw()
executeRaw(sql, params?): Promise<any[][]>
Parameters
| Parameter | Type |
|---|
sql | string |
params? | any[] |
Returns
Promise<any[][]>
getConfig()
getConfig(): Promise<Config>
Returns
Promise<Config>
init()
Returns
Promise<void>
isAutoCommit()
isAutoCommit(): Promise<boolean>
Checks if the database connection is in autocommit mode.
Returns
Promise<boolean>
true if in autocommit mode, false if in a transaction
markHold()
markHold(): Promise<string>
Marks the connection as in-use by a certain actor.
Returns
Promise<string>
A hold ID which can be used to release the hold.
registerOnTableChange()
registerOnTableChange(callback): Promise<() => void>
Parameters
Returns
Promise<() => void>
releaseHold()
releaseHold(holdId): Promise<void>
Releases a hold on the connection.
Parameters
| Parameter | Type | Description |
|---|
holdId | string | The hold ID to release. |
Returns
Promise<void>
BaseConnectionOptions
Internal
Extended by
Properties
| Property | Type | Description |
|---|
appMetadata? | Record<string, string> | A set of metadata to be included in service logs. |
clientImplementation? | SyncClientImplementation | Whether to use a JavaScript implementation to handle received sync lines from the sync service, or whether this work should be offloaded to the PowerSync core extension. This defaults to the JavaScript implementation (SyncClientImplementation.JAVASCRIPT) since the (SyncClientImplementation.RUST) implementation is experimental at the moment. |
connectionMethod? | SyncStreamConnectionMethod | The connection method to use when streaming updates from the PowerSync backend instance. Defaults to a HTTP streaming connection. |
fetchStrategy? | FetchStrategy | The fetch strategy to use when streaming updates from the PowerSync backend instance. |
includeDefaultStreams? | boolean | Whether to include streams that have auto_subscribe: true in their definition. This defaults to true. |
params? | Record<string, JSONValue> | These parameters are passed to the sync rules, and will be available under theuser_parameters object. |
serializedSchema? | any | The serialized schema - mainly used to forward information about raw tables to the sync client. |
BaseObserverInterface<T>
Extended by
Type Parameters
Methods
registerListener()
registerListener(listener): () => void
Parameters
| Parameter | Type |
|---|
listener | Partial<T> |
Returns
Function
Returns
void
BasePowerSyncDatabaseOptions
Internal
Extends
Extended by
Properties
| Property | Type | Description | Inherited from |
|---|
crudUploadThrottleMs? | number | Backend Connector CRUD operations are throttled to occur at most every crudUploadThrottleMs milliseconds. | AdditionalConnectionOptions.crudUploadThrottleMs |
logger? | ILogger | - | - |
retryDelay? | number | Deprecated Use retryDelayMs instead as this will be removed in future releases. | - |
retryDelayMs? | number | Delay for retrying sync streaming operations from the PowerSync backend after an error occurs. | AdditionalConnectionOptions.retryDelayMs |
schema | Schema | Schema used for the local database. | - |
BaseTriggerDiffRecord<TOperationId>
Experimental
Diffs created by TriggerManager#createDiffTrigger are stored in a temporary table.
This is the base record structure for all diff records.
Extended by
Type Parameters
| Type Parameter | Default type | Description |
|---|
TOperationId extends string | number | number | The type for operation_id. Defaults to number as returned by default SQLite database queries. Use string for full 64-bit precision when using { castOperationIdAsText: true } option. |
Properties
| Property | Type | Description |
|---|
id | string | Experimental The modified row's id column value. |
operation | DiffTriggerOperation | Experimental The operation performed which created this record. |
operation_id | TOperationId | Experimental Auto-incrementing primary key for the operation. Defaults to number as returned by database queries (wa-sqlite returns lower 32 bits). Can be string for full 64-bit precision when using { castOperationIdAsText: true } option. |
timestamp | string | Experimental Time the change operation was recorded. This is in ISO 8601 format, e.g. 2023-10-01T12:00:00.000Z. |
BatchedUpdateNotification
Properties
BucketChecksum
Properties
| Property | Type | Description |
|---|
bucket | string | - |
checksum | number | 32-bit unsigned hash. |
count? | number | Count of operations - informational only. |
priority? | number | - |
subscriptions? | any | The JavaScript client does not use this field, which is why it's defined to be any. We rely on the structure of this interface to pass custom BucketChecksums to the Rust client in unit tests, which so all fields need to be present. |
BucketDescription
Properties
| Property | Type |
|---|
name | string |
priority | number |
BucketRequest
Properties
| Property | Type | Description |
|---|
after | string | Base-10 number. Sync all data from this bucket with op_id > after. |
name | string | - |
BucketState
Properties
| Property | Type |
|---|
bucket | string |
op_id | string |
BucketStorageAdapter
Extends
Properties
Methods
control()
control(op, payload): Promise<string>
Invokes the powersync_control function for the sync client.
Parameters
Returns
Promise<string>
getBucketOperationProgress()
getBucketOperationProgress(): Promise<BucketOperationProgress>
Returns
Promise<BucketOperationProgress>
getBucketStates()
getBucketStates(): Promise<BucketState[]>
Returns
Promise<BucketState[]>
getClientId()
getClientId(): Promise<string>
Get an unique client id.
Returns
Promise<string>
getCrudBatch()
getCrudBatch(limit?): Promise<null | CrudBatch>
Parameters
| Parameter | Type |
|---|
limit? | number |
Returns
Promise<null | CrudBatch>
getMaxOpId()
Returns
string
hasCompletedSync()
hasCompletedSync(): Promise<boolean>
Returns
Promise<boolean>
hasCrud()
hasCrud(): Promise<boolean>
Returns
Promise<boolean>
hasMigratedSubkeys()
hasMigratedSubkeys(): Promise<boolean>
Returns
Promise<boolean>
init()
Returns
Promise<void>
migrateToFixedSubkeys()
migrateToFixedSubkeys(): Promise<void>
Returns
Promise<void>
nextCrudItem()
nextCrudItem(): Promise<undefined | CrudEntry>
Returns
Promise<undefined | CrudEntry>
registerListener()
registerListener(listener): () => void
Parameters
Returns
Function
Returns
void
Inherited from
BaseObserverInterface.registerListener
removeBuckets()
removeBuckets(buckets): Promise<void>
Parameters
| Parameter | Type |
|---|
buckets | string[] |
Returns
Promise<void>
saveSyncData()
saveSyncData(batch, fixedKeyFormat?): Promise<void>
Parameters
Returns
Promise<void>
setTargetCheckpoint()
setTargetCheckpoint(checkpoint): Promise<void>
Parameters
Returns
Promise<void>
startSession()
Returns
void
syncLocalDatabase()
syncLocalDatabase(checkpoint, priority?): Promise<{
checkpointValid: boolean;
failures: any[];
ready: boolean;
}>
Parameters
Returns
Promise<{
checkpointValid: boolean;
failures: any[];
ready: boolean;
}>
updateLocalTarget()
updateLocalTarget(cb): Promise<boolean>
Parameters
| Parameter | Type |
|---|
cb | () => Promise<string> |
Returns
Promise<boolean>
BucketStorageListener
Extends
Indexable
[key: string]: undefined | (...event) => any
Properties
| Property | Type |
|---|
crudUpdate | () => void |
Checkpoint
Properties
| Property | Type |
|---|
buckets | BucketChecksum[] |
last_op_id | string |
streams? | any[] |
write_checkpoint? | string |
ChecksumCache
Properties
| Property | Type |
|---|
checksums | Map<string, { checksum: BucketChecksum; last_op_id: string; }> |
lastOpId | string |
ColumnOptions
Properties
CompilableQuery<T>
Type Parameters
Methods
compile()
Returns
CompiledQuery
execute()
Returns
Promise<T[]>
CompilableQueryWatchHandler<T>
Type Parameters
Properties
| Property | Type |
|---|
onError? | (error: Error) => void |
onResult | (results: T[]) => void |
CompiledQuery
Properties
| Property | Modifier | Type |
|---|
parameters | readonly | readonly unknown[] |
sql | readonly | string |
ConnectionManagerListener
Internal
Extends
Indexable
[key: string]: undefined | (...event) => any
Properties
ConnectionManagerOptions
Internal
Properties
| Property | Type |
|---|
logger | ILogger |
Methods
createSyncImplementation()
createSyncImplementation(connector, options): Promise<ConnectionManagerSyncImplementationResult>
Parameters
Returns
Promise<ConnectionManagerSyncImplementationResult>
ConnectionManagerSyncImplementationResult
Internal
Properties
| Property | Type | Description |
|---|
onDispose | () => void | Promise<void> | Additional cleanup function which is called after the sync stream implementation is disposed. |
sync | StreamingSyncImplementation | - |
ContinueCheckpointRequest
For sync2.json
Properties
| Property | Type | Description |
|---|
buckets | BucketRequest[] | Existing bucket states. Only these buckets are synchronized. |
checkpoint_token | string | - |
limit? | number | - |
ControlledExecutorOptions
Properties
| Property | Type | Description |
|---|
throttleEnabled? | boolean | If throttling is enabled, it ensures only one task runs at a time, and only one additional task can be scheduled to run after the current task completes. The pending task will be overwritten by the latest task. Enabled by default. |
CreateDiffTriggerOptions
Experimental
Options for TriggerManager#createDiffTrigger.
Extends
BaseCreateDiffTriggerOptions
Properties
| Property | Type | Description | Inherited from |
|---|
columns? | string[] | Experimental Columns to track and report changes for. Defaults to all columns in the source table. Use an empty array to track only the ID and operation. | BaseCreateDiffTriggerOptions.columns |
destination | string | Experimental Destination table to send changes to. This table is created internally as a SQLite temporary table. This table will be dropped once the trigger is removed. | - |
hooks? | TriggerCreationHooks | Experimental Hooks which allow execution during the trigger creation process. | BaseCreateDiffTriggerOptions.hooks |
source | string | Experimental PowerSync source table/view to trigger and track changes from. This should be present in the PowerSync database's schema. | BaseCreateDiffTriggerOptions.source |
when | Partial<Record<DiffTriggerOperation, string>> | Experimental Condition to filter when the triggers should fire. This corresponds to a SQLite WHEN clause in the trigger body. This is useful for only triggering on specific conditions. For example, you can use it to only trigger on certain values in the NEW row. Note that for PowerSync the row data is stored in a JSON column named data. The row id is available in the id column. NB! The WHEN clauses here are added directly to the SQLite trigger creation SQL. Any user input strings here should be sanitized externally. The when string template function performs some basic sanitization, extra external sanitization is recommended. Example { * 'INSERT': sanitizeSQLjson_extract(NEW.data, '$.list_id') = ${sanitizeUUID(list.id)}, * 'INSERT': TRUE, * 'UPDATE': sanitizeSQLNEW.id = 'abcd' AND json_extract(NEW.data, '$.status') = 'active', * 'DELETE': sanitizeSQLjson_extract(OLD.data, '$.list_id') = 'abcd' * } | BaseCreateDiffTriggerOptions.when |
CreateLoggerOptions
Properties
| Property | Type |
|---|
logLevel? | ILogLevel |
CreateSyncImplementationOptions
Internal
The subset of AbstractStreamingSyncImplementationOptions managed by the connection manager.
Extends
Properties
CrudRequest
For crud.json
Properties
CrudResponse
Properties
| Property | Type | Description |
|---|
checkpoint? | string | A sync response with a checkpoint >= this checkpoint would contain all the changes in this request. Any earlier checkpoint may or may not contain these changes. May be empty when the request contains no ops. |
DataStreamListener<Data>
Extends
Type Parameters
| Type Parameter | Default type |
|---|
Data extends any | any |
Indexable
[key: string]: undefined | (...event) => any
Properties
| Property | Type |
|---|
closed | () => void |
data | (data: Data) => Promise<void> |
error | (error: Error) => void |
highWater | () => Promise<void> |
lowWater | () => Promise<void> |
DBAdapter
Extends
Properties
| Property | Type | Description |
|---|
close | () => void | Promise<void> | - |
execute | (query: string, params?: any[]) => Promise<QueryResult> | - |
executeBatch | (query: string, params?: any[][]) => Promise<QueryResult> | - |
executeRaw | (query: string, params?: any[]) => Promise<any[][]> | - |
name | string | - |
readLock | <T>(fn: (tx) => Promise<T>, options?: DBLockOptions) => Promise<T> | - |
readTransaction | <T>(fn: (tx) => Promise<T>, options?: DBLockOptions) => Promise<T> | - |
refreshSchema | () => Promise<void> | This method refreshes the schema information across all connections. This is for advanced use cases, and should generally not be needed. |
writeLock | <T>(fn: (tx) => Promise<T>, options?: DBLockOptions) => Promise<T> | - |
writeTransaction | <T>(fn: (tx) => Promise<T>, options?: DBLockOptions) => Promise<T> | - |
Methods
get()
get<T>(sql, parameters?): Promise<T>
Execute a read-only query and return the first result, error if the ResultSet is empty.
Type Parameters
Parameters
| Parameter | Type |
|---|
sql | string |
parameters? | any[] |
Returns
Promise<T>
Inherited from
DBGetUtils.get
getAll()
getAll<T>(sql, parameters?): Promise<T[]>
Execute a read-only query and return results.
Type Parameters
Parameters
| Parameter | Type |
|---|
sql | string |
parameters? | any[] |
Returns
Promise<T[]>
Inherited from
DBGetUtils.getAll
getOptional()
getOptional<T>(sql, parameters?): Promise<null | T>
Execute a read-only query and return the first result, or null if the ResultSet is empty.
Type Parameters
Parameters
| Parameter | Type |
|---|
sql | string |
parameters? | any[] |
Returns
Promise<null | T>
Inherited from
DBGetUtils.getOptional
registerListener()
registerListener(listener): () => void
Parameters
Returns
Function
Returns
void
Inherited from
BaseObserverInterface.registerListener
DBAdapterListener
Extends
Indexable
[key: string]: undefined | (...event) => any
Properties
| Property | Type | Description |
|---|
tablesUpdated | (updateNotification: | BatchedUpdateNotification | UpdateNotification) => void | Listener for table updates. Allows for single table updates in order to maintain API compatibility without the need for a major version bump The DB adapter can also batch update notifications if supported. |
DBGetUtils
Extended by
Methods
get()
get<T>(sql, parameters?): Promise<T>
Execute a read-only query and return the first result, error if the ResultSet is empty.
Type Parameters
Parameters
| Parameter | Type |
|---|
sql | string |
parameters? | any[] |
Returns
Promise<T>
getAll()
getAll<T>(sql, parameters?): Promise<T[]>
Execute a read-only query and return results.
Type Parameters
Parameters
| Parameter | Type |
|---|
sql | string |
parameters? | any[] |
Returns
Promise<T[]>
getOptional()
getOptional<T>(sql, parameters?): Promise<null | T>
Execute a read-only query and return the first result, or null if the ResultSet is empty.
Type Parameters
Parameters
| Parameter | Type |
|---|
sql | string |
parameters? | any[] |
Returns
Promise<null | T>
DBLockOptions
Properties
| Property | Type |
|---|
timeoutMs? | number |
DifferentialQueryProcessorOptions<RowType>
Internal
Extends
Type Parameters
Properties
DifferentialWatchedQueryComparator<RowType>
Row comparator for differentially watched queries which keys and compares items in the result set.
Type Parameters
Properties
| Property | Type | Description |
|---|
compareBy | (item: RowType) => string | Generates a token for comparing items with matching keys. |
keyBy | (item: RowType) => string | Generates a unique key for the item. |
DifferentialWatchedQueryListener<RowType>
Extends
Type Parameters
Indexable
[key: string]: undefined | (...event) => any
Properties
DifferentialWatchedQueryOptions<RowType>
Options for building a differential watched query with the Query builder.
Extends
Extended by
Type Parameters
Properties
| Property | Type | Default value | Description | Inherited from |
|---|
placeholderData? | RowType[] | undefined | Initial result data which is presented while the initial loading is executing. | - |
reportFetching? | boolean | undefined | If true (default) the watched query will update its state to report on the fetching state of the query. Setting to false reduces the number of state changes if the fetch status is not relevant to the consumer. | WatchedQueryOptions.reportFetching |
rowComparator? | DifferentialWatchedQueryComparator<RowType> | DEFAULT_ROW_COMPARATOR | Row comparator used to identify and compare rows in the result set. If not provided, the default comparator will be used which keys items by their id property if available, otherwise it uses JSON stringification of the entire item for keying and comparison. | - |
throttleMs? | number | undefined | The minimum interval between queries. | WatchedQueryOptions.throttleMs |
triggerOnTables? | string[] | undefined | By default, watched queries requery the database on any change to any dependent table of the query. Supplying an override here can be used to limit the tables which trigger querying the database. | WatchedQueryOptions.triggerOnTables |
DifferentialWatchedQuerySettings<RowType>
Settings for differential incremental watched queries using.
Extends
Type Parameters
Properties
| Property | Type | Default value | Description | Inherited from |
|---|
placeholderData? | RowType[] | undefined | Initial result data which is presented while the initial loading is executing. | DifferentialWatchedQueryOptions.placeholderData |
query | WatchCompatibleQuery<RowType[]> | undefined | The query here must return an array of items that can be differentiated. | - |
reportFetching? | boolean | undefined | If true (default) the watched query will update its state to report on the fetching state of the query. Setting to false reduces the number of state changes if the fetch status is not relevant to the consumer. | DifferentialWatchedQueryOptions.reportFetching |
rowComparator? | DifferentialWatchedQueryComparator<RowType> | DEFAULT_ROW_COMPARATOR | Row comparator used to identify and compare rows in the result set. If not provided, the default comparator will be used which keys items by their id property if available, otherwise it uses JSON stringification of the entire item for keying and comparison. | DifferentialWatchedQueryOptions.rowComparator |
throttleMs? | number | undefined | The minimum interval between queries. | DifferentialWatchedQueryOptions.throttleMs |
triggerOnTables? | string[] | undefined | By default, watched queries requery the database on any change to any dependent table of the query. Supplying an override here can be used to limit the tables which trigger querying the database. | DifferentialWatchedQueryOptions.triggerOnTables |
DisconnectAndClearOptions
Properties
| Property | Type | Description |
|---|
clearLocal? | boolean | When set to false, data in local-only tables is preserved. |
Disposable
Extended by
Properties
| Property | Type |
|---|
dispose | () => void | Promise<void> |
IndexColumnOptions
Properties
| Property | Type |
|---|
ascending? | boolean |
name | string |
IndexOptions
Properties
InternalConnectionOptions
Internal
Extends
Properties
InternalSubscriptionAdapter
Methods
firstStatusMatching()
firstStatusMatching(predicate, abort?): Promise<void>
Parameters
| Parameter | Type |
|---|
predicate | (status) => any |
abort? | AbortSignal |
Returns
Promise<void>
resolveOfflineSyncStatus()
resolveOfflineSyncStatus(): Promise<void>
Returns
Promise<void>
rustSubscriptionsCommand()
rustSubscriptionsCommand(payload): Promise<void>
Parameters
Returns
Promise<void>
LinkQueryOptions<Data, Settings>
Internal
Type Parameters
Properties
| Property | Type |
|---|
abortSignal | AbortSignal |
settings | Settings |
LockContext
Extends
Extended by
Properties
| Property | Type | Description |
|---|
execute | (query: string, params?: any[]) => Promise<QueryResult> | Execute a single write statement. |
executeRaw | (query: string, params?: any[]) => Promise<any[][]> | Execute a single write statement and return raw results. Unlike execute, which returns an object with structured key-value pairs, executeRaw returns a nested array of raw values, where each row is represented as an array of column values without field names. Example result: [ [ '1', 'list 1', '33', 'Post content', '1' ] ] Where as execute's rows._array would have been: [ { id: '33', name: 'list 1', content: 'Post content', list_id: '1' } ] |
Methods
get()
get<T>(sql, parameters?): Promise<T>
Execute a read-only query and return the first result, error if the ResultSet is empty.
Type Parameters
Parameters
| Parameter | Type |
|---|
sql | string |
parameters? | any[] |
Returns
Promise<T>
Inherited from
DBGetUtils.get
getAll()
getAll<T>(sql, parameters?): Promise<T[]>
Execute a read-only query and return results.
Type Parameters
Parameters
| Parameter | Type |
|---|
sql | string |
parameters? | any[] |
Returns
Promise<T[]>
Inherited from
DBGetUtils.getAll
getOptional()
getOptional<T>(sql, parameters?): Promise<null | T>
Execute a read-only query and return the first result, or null if the ResultSet is empty.
Type Parameters
Parameters
| Parameter | Type |
|---|
sql | string |
parameters? | any[] |
Returns
Promise<null | T>
Inherited from
DBGetUtils.getOptional
LockOptions<T>
Abstract Lock to be implemented by various JS environments
Type Parameters
Properties
| Property | Type |
|---|
callback | () => Promise<T> |
signal? | AbortSignal |
type | LockType |
OnChangeQueryProcessorOptions<Data>
Internal
Extends
Type Parameters
Properties
OplogEntryJSON
Properties
| Property | Type |
|---|
checksum | number |
data? | string |
object_id? | string |
object_type? | string |
op | string |
op_id | string |
subkey? | string |
ParsedQuery
Properties
| Property | Type |
|---|
parameters | any[] |
sqlStatement | string |
PowerSyncBackendConnector
Properties
| Property | Type | Description |
|---|
fetchCredentials | () => Promise<null | PowerSyncCredentials> | Allows the PowerSync client to retrieve an authentication token from your backend which is used to authenticate against the PowerSync service. This should always fetch a fresh set of credentials - don't use cached values. Return null if the user is not signed in. Throw an error if credentials cannot be fetched due to a network error or other temporary error. This token is kept for the duration of a sync connection. |
uploadData | (database: AbstractPowerSyncDatabase) => Promise<void> | Upload local changes to the app backend. Use AbstractPowerSyncDatabase.getCrudBatch to get a batch of changes to upload. Any thrown errors will result in a retry after the configured wait period (default: 5 seconds). |
PowerSyncCloseOptions
Properties
| Property | Type | Description |
|---|
disconnect? | boolean | Disconnect the sync stream client if connected. This is usually true, but can be false for Web when using multiple tabs and a shared sync provider. |
PowerSyncCredentials
Properties
| Property | Type |
|---|
endpoint | string |
expiresAt? | Date |
token | string |
PowerSyncDatabaseOptions
Internal
Extends
Properties
PowerSyncDatabaseOptionsWithDBAdapter
Internal
Extends
Properties
PowerSyncDatabaseOptionsWithOpenFactory
Internal
Extends
Properties
PowerSyncDatabaseOptionsWithSettings
Internal
Extends
Properties
PowerSyncDBListener
Extends
Indexable
[key: string]: undefined | (...event) => any
Properties
PowerSyncOpenFactoryOptions
Extends
Extended by
Properties
| Property | Type | Description | Overrides | Inherited from |
|---|
crudUploadThrottleMs? | number | Backend Connector CRUD operations are throttled to occur at most every crudUploadThrottleMs milliseconds. | - | Partial.crudUploadThrottleMs |
database? | | SQLOpenOptions | DBAdapter | SQLOpenFactory | Source for a SQLite database connection. This can be either: - A DBAdapter if providing an instantiated SQLite connection - A SQLOpenFactory which will be used to open a SQLite connection - SQLOpenOptions for opening a SQLite connection with a default SQLOpenFactory | - | Partial.database |
dbFilename | string | Filename for the database. | - | SQLOpenOptions.dbFilename |
dbLocation? | string | Directory where the database file is located. When set, the directory must exist when the database is opened, it will not be created automatically. | - | SQLOpenOptions.dbLocation |
debugMode? | boolean | Enable debugMode to log queries to the performance timeline. Defaults to false. To enable in development builds, use: debugMode: process.env.NODE_ENV !== 'production' | - | SQLOpenOptions.debugMode |
logger? | ILogger | - | - | Partial.logger |
retryDelay? | number | Deprecated Use retryDelayMs instead as this will be removed in future releases. | - | Partial.retryDelay |
retryDelayMs? | number | Delay for retrying sync streaming operations from the PowerSync backend after an error occurs. | - | Partial.retryDelayMs |
schema | Schema | Schema used for the local database. | Partial.schema | - |
ProgressWithOperations
Information about a progressing download made by the PowerSync SDK.
To obtain these values, use SyncProgress, available through
SyncStatus#downloadProgress.
Properties
| Property | Type | Description |
|---|
downloadedFraction | number | Relative progress, as downloadedOperations of totalOperations. This will be a number between 0.0 and 1.0 (inclusive). When this number reaches 1.0, all changes have been received from the sync service. Actually applying these changes happens before the downloadProgress field is cleared from SyncStatus, so progress can stay at 1.0 for a short while before completing. |
downloadedOperations | number | The amount of operations that have already been downloaded. |
totalOperations | number | The total amount of operations to download for the current sync iteration to complete. |
Query<RowType>
Type Parameters
Methods
differentialWatch()
differentialWatch(options?): DifferentialWatchedQuery<RowType>
Creates a WatchedQuery which watches and emits results of the linked query.
This query method watches for changes in the underlying SQLite tables and runs the query on each table change.
The difference between the current and previous result set is computed.
The watched query will not emit changes if the result set is identical to the previous result set.
If the result set is different, the watched query will emit the new result set and emit a detailed diff of the changes via the onData and onDiff listeners.
The deep differentiation allows maintaining result set object references between result emissions.
The DifferentialWatchedQuery#state data array will contain the previous row references for unchanged rows.
Parameters
Returns
DifferentialWatchedQuery<RowType>
Example
const watchedLists = powerSync.query({sql: 'SELECT * FROM lists'})
.differentialWatch();
const disposeListener = watchedLists.registerListener({
onData: (lists) => {
console.log('The latest result set for the query is', lists);
},
onDiff: (diff) => {
console.log('The lists result set has changed since the last emission', diff.added, diff.removed, diff.updated, diff.all)
}
})
watch()
watch(options?): StandardWatchedQuery<readonly Readonly<RowType>[]>
Creates a WatchedQuery which watches and emits results of the linked query.
By default the returned watched query will emit changes whenever a change to the underlying SQLite tables is made.
These changes might not be relevant to the query, but the query will emit a new result set.
A StandardWatchedQueryOptions#comparator can be provided to limit the data emissions. The watched query will still
query the underlying DB on underlying table changes, but the result will only be emitted if the comparator detects a change in the results.
The comparator in this method is optimized and returns early as soon as it detects a change. Each data emission will correlate to a change in the result set,
but note that the result set will not maintain internal object references to the previous result set. If internal object references are needed,
consider using Query#differentialWatch instead.
Parameters
Returns
StandardWatchedQuery<readonly Readonly<RowType>[]>
RequiredAdditionalConnectionOptions
Internal
Extends
Extended by
Properties
| Property | Type | Description | Inherited from |
|---|
crudUploadThrottleMs | number | Backend Connector CRUD operations are throttled to occur at most every crudUploadThrottleMs milliseconds. | Required.crudUploadThrottleMs |
retryDelayMs | number | Delay for retrying sync streaming operations from the PowerSync backend after an error occurs. | Required.retryDelayMs |
subscriptions | SubscribedStream[] | - | - |
ResolvedWASQLiteOpenFactoryOptions
Extends
Extended by
Properties
ResolvedWebSQLOpenOptions
Extends