Usage Examples
Code snippets and guidelines for common scenarios
Using transactions to group changes
Use writeTransaction
to group statements that can write to the database.
Subscribe to changes in data
Use the watch
method 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. 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 the hasSynced
property and register a listener to indicate to the user whether the initial sync is in progress.
For async use cases, use waitForFirstSync
method which is a suspense function that resolves once the first full sync has completed.
Using logging to troubleshoot issues
You can include your own Logger that must conform to the Kermit Logger as shown here.
If you don’t supply a Logger then a default Kermit Logger is created with settings to only show Warnings
in release and Verbose
in debug as follows:
You are able to use the Logger anywhere in your code as follows to debug: