Skip to main content

Using Transactions to Group Changes

Read and write transactions present a context where multiple changes can be made then finally committed to the DB or rolled back. This ensures that either all the changes get persisted, or no change is made to the DB (in the case of a rollback or exception).The writeTransaction(callback) method combines all writes into a single transaction, only committing to persistent storage once.
Also see readTransaction(callback)

Listen for Changes in Data

Use watch to watch for changes to the dependent tables of any SQL query.

Insert, Update, and Delete Data in the Local Database

Use execute to run INSERT, UPDATE or DELETE queries.

Send Changes in Local Data to Your Backend Service

Override uploadData to send local updates to your backend service.

Accessing PowerSync Connection Status Information

Use SyncStatus and register an event listener with statusStream to listen for status changes to your PowerSync instance.

Wait for the Initial Sync to Complete

Use the hasSynced property (available since version 1.5.1 of the SDK) and register a listener to indicate to the user whether the initial sync is in progress.
For async use cases, see the waitForFirstSync method which returns a promise that resolves once the first full sync has completed.

Report Sync Download Progress

You can show users a progress bar when data downloads using the downloadProgress property from the SyncStatus class. downloadProgress.downloadedFraction gives you a value from 0.0 to 1.0 representing the total sync progress. This is especially useful for long-running initial syncs.As an example, this widget renders a progress bar when a download is active:
Also see: