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).

# Conflicts:
#	core/src/commonMain/kotlin/com/powersync/bucket/BucketStorage.kt
#	core/src/commonMain/kotlin/com/powersync/bucket/BucketStorageImpl.kt
Copy link
Contributor

@stevensJourney stevensJourney left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Happy with this from my side 😄 🚀

@simolus3 simolus3 merged commit d6002ca into main Sep 30, 2025
8 checks passed
@simolus3 simolus3 deleted the sync-streams branch September 30, 2025 08:02
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.

2 participants