Skip to content

Conversation

simolus3
Copy link
Contributor

@simolus3 simolus3 commented Sep 8, 2025

This adds support for sync streams through the syncStream() method on PowerSyncDatabase.

  • I've renamed the sync client from SyncStream to StreamingSyncClient to avoid ambiguity.
  • Similar to the Dart and JS implementations, we need to keep track of active subscriptions while we're connected. For Kotlin, a MutableStateFlow that the Rust client subscribes to is a perfect fit for that.
  • I've refactored SyncStatusData into an abstract class so that it can have internal fields (such as the one tracking internal Rust stream information).

Otherwise, the implementation is fairly straightforward: Calling db.syncStream(stream, params) returns a pending stream object. Calling subscribe on that will:

  • Call powersync_control to update the subscription in the database.
  • If this is the first subscription on that stream, update a flow tracking the sync stream subscription. The Rust client will listen on that, do a diff, and reconnect if necessary.
  • If we're not connected, update the offline sync status because status information about sync streams is included even while offline (necessary so that clients can selectively unsubscribe from streams even without connecting).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant