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.Subscribe to 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.Report sync download progress
You can show users a progress bar when data downloads using thedownloadProgress
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: