Using transactions to group changes
UsewriteTransaction
to group statements that can write to the database.
Subscribe to changes in data
Use thewatch
method to watch for changes to the dependent tables of any SQL query.
Insert, update, and delete data in the local database
Useexecute
to run INSERT, UPDATE or DELETE queries.
Send changes in local data to your backend service
OverrideuploadData
to send local updates to your backend service. If you are using Supabase, see SupabaseConnector.kt for a complete implementation.
Accessing PowerSync connection status information
Wait for the initial sync to complete
Use thehasSynced
property and register a listener to indicate to the user whether the initial sync is in progress.
waitForFirstSync
method which is a suspense function that resolves once the first full sync has completed.
Report sync download progress
You can show users a progress bar when data downloads using thesyncStatus.downloadProgress
property. This is especially useful for long-running initial syncs. downloadProgress.downloadedFraction
gives a value from 0.0 to 1.0 representing the total sync progress.
Example (Compose):