Skip to content

Commit 6d9583f

Browse files
committed
Add client_id to sync stream request.
1 parent 0c59ccb commit 6d9583f

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

packages/powersync/lib/src/bucket_storage.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ class BucketStorage {
4040
];
4141
}
4242

43+
Future<String> getClientId() async {
44+
final rows = await select('SELECT powersync_client_id() as client_id');
45+
return rows.first['client_id'] as String;
46+
}
47+
4348
Future<void> streamOp(String op) async {
4449
await writeTransaction((tx) async {
4550
await tx.execute(

packages/powersync/lib/src/streaming_sync.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ class StreamingSyncImplementation {
245245
{AbortController? abortController}) async {
246246
adapter.startSession();
247247
final bucketEntries = await adapter.getBucketStates();
248+
final clientId = await adapter.getClientId();
248249

249250
Map<String, String> initialBucketStates = {};
250251

@@ -262,8 +263,8 @@ class StreamingSyncImplementation {
262263
Checkpoint? appliedCheckpoint;
263264
var bucketSet = Set<String>.from(initialBucketStates.keys);
264265

265-
var requestStream =
266-
streamingSyncRequest(StreamingSyncRequest(buckets, syncParameters));
266+
var requestStream = streamingSyncRequest(
267+
StreamingSyncRequest(buckets, syncParameters, clientId));
267268

268269
var merged = addBroadcast(requestStream, _localPingController.stream);
269270

packages/powersync/lib/src/sync_types.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,15 +112,17 @@ Object? parseStreamingSyncLine(Map<String, dynamic> line) {
112112
class StreamingSyncRequest {
113113
List<BucketRequest> buckets;
114114
bool includeChecksum = true;
115+
String clientId;
115116
Map<String, dynamic>? parameters;
116117

117-
StreamingSyncRequest(this.buckets, this.parameters);
118+
StreamingSyncRequest(this.buckets, this.parameters, this.clientId);
118119

119120
Map<String, dynamic> toJson() {
120121
final Map<String, dynamic> json = {
121122
'buckets': buckets,
122123
'include_checksum': includeChecksum,
123124
'raw_data': true,
125+
'client_id': clientId
124126
};
125127

126128
if (parameters != null) {

0 commit comments

Comments
 (0)