PowerSyncDatabase
Experimental Alpha
PowerSyncDatabase class for managing database connections and sync implementations. This extends the WebPowerSyncDatabase to provide platform-specific implementations for Capacitor environments (iOS and Android).
Extends
PowerSyncDatabase
Constructors
new PowerSyncDatabase()
new PowerSyncDatabase(options): PowerSyncDatabase
Alpha Experimental
Parameters
| Parameter | Type |
|---|---|
options | WebPowerSyncDatabaseOptionsWithAdapter |
Returns
Inherited from
WebPowerSyncDatabase.constructor
new PowerSyncDatabase()
new PowerSyncDatabase(options): PowerSyncDatabase
Alpha Experimental
Parameters
| Parameter | Type |
|---|---|
options | WebPowerSyncDatabaseOptionsWithOpenFactory |
Returns
Inherited from
WebPowerSyncDatabase.constructor
new PowerSyncDatabase()
new PowerSyncDatabase(options): PowerSyncDatabase
Alpha Experimental
Parameters
| Parameter | Type |
|---|---|
options | WebPowerSyncDatabaseOptionsWithSettings |
Returns
Inherited from
WebPowerSyncDatabase.constructor
new PowerSyncDatabase()
new PowerSyncDatabase(options): PowerSyncDatabase
Alpha Experimental
Parameters
| Parameter | Type |
|---|---|
options | WebPowerSyncDatabaseOptions |
Returns
Inherited from
WebPowerSyncDatabase.constructor
Properties
Accessors
connected
Get Signature
get connected(): boolean
Alpha
Whether a connection to the PowerSync service is currently open.
Returns
boolean
Inherited from
WebPowerSyncDatabase.connected
connecting
Get Signature
get connecting(): boolean
Alpha Experimental
Returns
boolean
Inherited from
WebPowerSyncDatabase.connecting
connectionOptions
Get Signature
get connectionOptions(): null | InternalConnectionOptions
Alpha
The resolved connection options used to connect to the PowerSync service.
Returns
null | InternalConnectionOptions
The resolved connection options used to connect to the PowerSync service or null if connect() has not been called.
Inherited from
WebPowerSyncDatabase.connectionOptions
connector
Get Signature
get connector(): null | PowerSyncBackendConnector
Alpha
The connector used to connect to the PowerSync service.
Returns
null | PowerSyncBackendConnector
The connector used to connect to the PowerSync service or null if connect() has not been called.
Inherited from
WebPowerSyncDatabase.connector
database
Get Signature
get database(): DBAdapter
Alpha
The underlying database.
For the most part, behavior is the same whether querying on the underlying database, or on AbstractPowerSyncDatabase.
Returns
DBAdapter
Inherited from
WebPowerSyncDatabase.database
schema
Get Signature
get schema(): Schema<{}>
Alpha
Schema used for the local database.
Returns
Schema<{}>
Inherited from
WebPowerSyncDatabase.schema
syncStreamImplementation
Get Signature
get syncStreamImplementation(): null | StreamingSyncImplementation
Alpha Experimental
Returns
null | StreamingSyncImplementation
Inherited from
WebPowerSyncDatabase.syncStreamImplementation
Methods
_initialize()
_initialize(): Promise<void>
Alpha
Returns
Promise<void>
Inherited from
WebPowerSyncDatabase._initialize
close()
close(options?): Promise<void>
Alpha
Parameters
| Parameter | Type |
|---|---|
options? | PowerSyncCloseOptions |
Returns
Promise<void>
Inherited from
WebPowerSyncDatabase.close
connect()
connect(connector, options?): Promise<void>
Alpha
Parameters
| Parameter | Type |
|---|---|
connector | PowerSyncBackendConnector |
options? | PowerSyncConnectionOptions |
Returns
Promise<void>
Overrides
WebPowerSyncDatabase.connect
customQuery()
customQuery<RowType>(query): Query<RowType>
Alpha
Type Parameters
| Type Parameter |
|---|
RowType |
Parameters
| Parameter | Type |
|---|---|
query | WatchCompatibleQuery<RowType[]> |
Returns
Query<RowType>
Example
// Potentially a query from an ORM like Drizzle
const query = db.select().from(lists);
const watchedTodos = powersync.customQuery(query)
.watch()
// OR use .differentialWatch() for fine-grained watches.
Inherited from
WebPowerSyncDatabase.customQuery
disconnect()
disconnect(): Promise<void>
Alpha
Returns
Promise<void>
Inherited from
WebPowerSyncDatabase.disconnect
disconnectAndClear()
disconnectAndClear(options?): Promise<void>
Alpha
Parameters
| Parameter | Type |
|---|---|
options? | DisconnectAndClearOptions |
Returns
Promise<void>
Inherited from
WebPowerSyncDatabase.disconnectAndClear
dispose()
dispose(): void
Alpha
Returns
void
Deprecated
Use AbstractPowerSyncDatabase#close instead. Clears all listeners registered by AbstractPowerSyncDatabase#registerListener.
Inherited from
WebPowerSyncDatabase.dispose
execute()
execute(sql, parameters?): Promise<QueryResult>
Alpha
Parameters
| Parameter | Type | Description |
|---|---|---|
sql | string | The SQL query to execute |
parameters? | any[] | Optional array of parameters to bind to the query |
Returns
Promise<QueryResult>
The query result as an object with structured key-value pairs
Inherited from
WebPowerSyncDatabase.execute
executeBatch()
executeBatch(sql, parameters?): Promise<QueryResult>
Alpha
Parameters
| Parameter | Type | Description |
|---|---|---|
sql | string | The SQL query to execute |
parameters? | any[][] | Optional 2D array of parameter sets, where each inner array is a set of parameters for one execution |
Returns
Promise<QueryResult>
The query result
Inherited from
WebPowerSyncDatabase.executeBatch
executeRaw()
executeRaw(sql, parameters?): Promise<any[][]>
Alpha
Parameters
| Parameter | Type | Description |
|---|---|---|
sql | string | The SQL query to execute |
parameters? | any[] | Optional array of parameters to bind to the query |
Returns
Promise<any[][]>
The raw query result from the underlying database as a nested array of raw values, where each row is represented as an array of column values without field names.
Inherited from
WebPowerSyncDatabase.executeRaw
get()
get<T>(sql, parameters?): Promise<T>
Alpha
Type Parameters
| Type Parameter |
|---|
T |
Parameters
| Parameter | Type | Description |
|---|---|---|
sql | string | The SQL query to execute |
parameters? | any[] | Optional array of parameters to bind to the query |
Returns
Promise<T>
The first result matching the query
Throws
Error if no rows are returned
Inherited from
WebPowerSyncDatabase.get
getAll()
getAll<T>(sql, parameters?): Promise<T[]>
Alpha
Type Parameters
| Type Parameter |
|---|
T |
Parameters
| Parameter | Type | Description |
|---|---|---|
sql | string | The SQL query to execute |
parameters? | any[] | Optional array of parameters to bind to the query |
Returns
Promise<T[]>
An array of results
Inherited from
WebPowerSyncDatabase.getAll
getClientId()
getClientId(): Promise<string>
Alpha
Returns
Promise<string>
A unique identifier for the database instance
Inherited from
WebPowerSyncDatabase.getClientId
getCrudBatch()
getCrudBatch(limit?): Promise<null | CrudBatch>
Alpha
Parameters
| Parameter | Type | Description |
|---|---|---|
limit? | number | Maximum number of CRUD entries to include in the batch |
Returns
Promise<null | CrudBatch>
A batch of CRUD operations to upload, or null if there are none
Inherited from
WebPowerSyncDatabase.getCrudBatch
getCrudTransactions()
getCrudTransactions(): AsyncIterable<CrudTransaction, null>
Alpha
Returns
AsyncIterable<CrudTransaction, null>
Inherited from
WebPowerSyncDatabase.getCrudTransactions
getNextCrudTransaction()
getNextCrudTransaction(): Promise<null | CrudTransaction>
Alpha
Returns
Promise<null | CrudTransaction>
A transaction of CRUD operations to upload, or null if there are none
Inherited from
WebPowerSyncDatabase.getNextCrudTransaction
getOptional()
getOptional<T>(sql, parameters?): Promise<null | T>
Alpha
Type Parameters
| Type Parameter |
|---|
T |
Parameters
| Parameter | Type | Description |
|---|---|---|
sql | string | The SQL query to execute |
parameters? | any[] | Optional array of parameters to bind to the query |
Returns
Promise<null | T>
The first result if found, or null if no results are returned
Inherited from
WebPowerSyncDatabase.getOptional
getUploadQueueStats()
getUploadQueueStats(includeSize?): Promise<UploadQueueStats>
Alpha
Parameters
| Parameter | Type |
|---|---|
includeSize? | boolean |
Returns
Promise<UploadQueueStats>
Inherited from
WebPowerSyncDatabase.getUploadQueueStats
init()
init(): Promise<void>
Alpha
Returns
Promise<void>
Inherited from
WebPowerSyncDatabase.init
iterateAsyncListeners()
iterateAsyncListeners(cb): Promise<void>
Alpha Experimental
Parameters
| Parameter | Type |
|---|---|
cb | (listener) => Promise<any> |
Returns
Promise<void>
Inherited from
WebPowerSyncDatabase.iterateAsyncListeners
iterateListeners()
iterateListeners(cb): void
Alpha Experimental
Parameters
| Parameter | Type |
|---|---|
cb | (listener) => any |
Returns
void