Class PowerSyncDatabase
public class PowerSyncDatabase : IPowerSyncDatabase, ICloseableAsync
- Inheritance
-
PowerSyncDatabase
- Implements
- Inherited Members
Constructors
Fields
Properties
Methods
- Close()
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.
- DisconnectAndClear(bool)
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.
- GetClientId()
Get an unique client id for this database.
The id is not reset when the database is cleared, only when the database is deleted.
- GetCrudBatch(int)
Get a batch of crud data to upload.
Returns null if there is no data to upload.
Use this from the UploadData(IPowerSyncDatabase) callback.
Once the data have been successfully uploaded, call Complete(string?) before requesting the next batch.
Use
limitto specify the maximum number of updates to return in a single batch.This method does include transaction ids in the result, but does not group data by transaction. One batch may contain data from multiple transactions, and a single transaction may be split over multiple batches.
- GetNextCrudTransaction()
Get the next recorded transaction to upload.
Returns null if there is no data to upload.
Use this from the UploadData(IPowerSyncDatabase) callback.
Once the data have been successfully uploaded, call Complete(string?) before requesting the next transaction.
Unlike GetCrudBatch(int), this only returns data from a single transaction at a time. All data for the transaction is loaded into memory.
- GetUploadQueueStats(bool)
Get upload queue size estimate and count.
- Init()
Wait for initialization to complete. While initializing is automatic, this helps to catch and report initialization errors.
- OnChange(SQLWatchOptions?)
Emits an event whenever any of the tables in Tables are modified.
- SyncStream(string, Dictionary<string, object>?)
Create a sync stream to query its status or to subscribe to it.
Sync streams are currently in alpha.
- UpdateSchema(Schema)
Replace the schema with a new version. This is for advanced use cases - typically the schema should just be specified once in the constructor. Cannot be used while connected - this should only be called before Connect(IPowerSyncBackendConnector, PowerSyncConnectionOptions?).
- WaitForFirstSync(PrioritySyncRequest?)
Wait for the first sync operation to complete.
- WaitForReady()
Resolves once initialization is completed.
- WaitForStatus(Func<SyncStatus, bool>, CancellationToken?)
Waits for the first sync status for which the
predicatecallback returns true.
- Watch<T>(string, object?[]?, SQLWatchOptions?)
Executes a read query every time the source tables are modified.
The query's source tables are resolved automatically (or taken from Tables when provided), and are re-resolved whenever the schema changes, so watches keep working across UpdateSchema(Schema) calls.