abstract AbstractPowerSyncDatabase
Extends
Extended by
Constructors
new AbstractPowerSyncDatabase()
new AbstractPowerSyncDatabase(options): AbstractPowerSyncDatabase
Parameters
| Parameter | Type |
|---|---|
options | PowerSyncDatabaseOptionsWithDBAdapter |
Returns
Overrides
new AbstractPowerSyncDatabase()
new AbstractPowerSyncDatabase(options): AbstractPowerSyncDatabase
Parameters
| Parameter | Type |
|---|---|
options | PowerSyncDatabaseOptionsWithOpenFactory |
Returns
Overrides
BaseObserver<PowerSyncDBListener>.constructor
new AbstractPowerSyncDatabase()
new AbstractPowerSyncDatabase(options): AbstractPowerSyncDatabase
Parameters
| Parameter | Type |
|---|---|
options | PowerSyncDatabaseOptionsWithSettings |
Returns
Overrides
BaseObserver<PowerSyncDBListener>.constructor
new AbstractPowerSyncDatabase()
new AbstractPowerSyncDatabase(options): AbstractPowerSyncDatabase
Parameters
| Parameter | Type |
|---|---|
options | PowerSyncDatabaseOptions |
Returns
Overrides
BaseObserver<PowerSyncDBListener>.constructor
Properties
| Property | Modifier | Type | Description |
|---|---|---|---|
closed | public | boolean | Returns true if the connection is closed. |
currentStatus | public | SyncStatus | Current connection status. |
logger | public | ILogger | - |
ready | public | boolean | - |
sdkVersion | public | string | - |
triggers | readonly | TriggerManager | Experimental Allows creating SQLite triggers which can be used to track various operations on SQLite tables. |
Accessors
connected
Get Signature
get connected(): boolean
Whether a connection to the PowerSync service is currently open.
Returns
boolean
connecting
Get Signature
get connecting(): boolean
Returns
boolean
connectionOptions
Get Signature
get connectionOptions():
| null
| InternalConnectionOptions
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.
connector
Get Signature
get connector():
| null
| PowerSyncBackendConnector
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.
database
Get Signature
get database(): DBAdapter
The underlying database.
For the most part, behavior is the same whether querying on the underlying database, or on AbstractPowerSyncDatabase.
Returns
schema
Get Signature
get schema(): Schema<{}>
Schema used for the local database.
Returns
Schema<{}>
syncStreamImplementation
Get Signature
get syncStreamImplementation():
| null
| StreamingSyncImplementation
Returns
| null
| StreamingSyncImplementation
Methods
_initialize()
abstract _initialize(): Promise<void>
Allows for extended implementations to execute custom initialization logic as part of the total init process
Returns
Promise<void>
close()
close(options?): Promise<void>
Close the database, releasing resources.
Also disconnects any active connection.
Once close is called, this connection cannot be used again - a new one must be constructed.
Parameters
| Parameter | Type |
|---|---|
options? | PowerSyncCloseOptions |
Returns
Promise<void>
connect()
connect(connector, options?): Promise<void>
Connects to stream of events from the PowerSync instance.
Parameters
| Parameter | Type |
|---|---|
connector | PowerSyncBackendConnector |
options? | PowerSyncConnectionOptions |
Returns
Promise<void>
customQuery()
customQuery<RowType>(query): Query<RowType>
Allows building a WatchedQuery using an existing WatchCompatibleQuery. The watched query will use the provided WatchCompatibleQuery.execute method to query results.
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.
disconnect()
disconnect(): Promise<void>
Close the sync connection.
Use connect to connect again.
Returns
Promise<void>
disconnectAndClear()
disconnectAndClear(options?): Promise<void>
Disconnect and clear the database. Use this when logging out. The database can still be queried after this is called, but the tables would be empty.
To preserve data in local-only tables, set clearLocal to false.
Parameters
| Parameter | Type |
|---|---|
options? | DisconnectAndClearOptions |
Returns
Promise<void>
dispose()
dispose(): void
Returns
void
Deprecated
Use AbstractPowerSyncDatabase#close instead. Clears all listeners registered by AbstractPowerSyncDatabase#registerListener.
Overrides
execute()
execute(sql, parameters?): Promise<QueryResult>
Execute a SQL write (INSERT/UPDATE/DELETE) query and optionally return results.
When using the default client-side JSON-based view system,
the returned result's rowsAffected may be 0 for successful UPDATE and DELETE statements.
Use a RETURNING clause and inspect result.rows when you need to confirm which rows changed.
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
executeBatch()
executeBatch(sql, parameters?): Promise<QueryResult>
Execute a write query (INSERT/UPDATE/DELETE) multiple times with each parameter set and optionally return results. This is faster than executing separately with each parameter set.
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
executeRaw()
executeRaw(sql, parameters?): Promise<any[][]>
Execute a SQL write (INSERT/UPDATE/DELETE) query directly on the database without any PowerSync processing. This bypasses certain PowerSync abstractions and is useful for accessing the raw database results.
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.
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
| 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
getAll()
getAll<T>(sql, parameters?): Promise<T[]>
Execute a read-only query and return results.
Type Parameters
| Type Parameter |
|---|
T |