Skip to content

Commit 773f263

Browse files
committed
Add PowerSyncDatabase.getClientId().
1 parent 7755700 commit 773f263

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

packages/powersync/lib/src/database/powersync_db_mixin.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,13 @@ mixin PowerSyncDatabaseMixin implements SqliteConnection {
287287
return database.isolateConnectionFactory();
288288
}
289289

290+
/// Get an unique id for this client.
291+
/// This id is only reset when the database is deleted.
292+
Future<String> getClientId() async {
293+
final row = await get('SELECT powersync_client_id() as client_id');
294+
return row['client_id'] as String;
295+
}
296+
290297
/// Get upload queue size estimate and count.
291298
Future<UploadQueueStats> getUploadQueueStats(
292299
{bool includeSize = false}) async {

packages/powersync/test/powersync_shared_test.dart

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import 'package:sqlite_async/mutex.dart';
22
import 'package:test/test.dart';
3+
import 'package:uuid/parsing.dart';
4+
import 'package:uuid/v4.dart';
35
import 'utils/test_utils_impl.dart';
46

57
final testUtils = TestUtils();
@@ -79,5 +81,13 @@ void main() {
7981
await db.execute('PRAGMA wal_checkpoint(TRUNCATE)');
8082
await db.execute('VACUUM');
8183
});
84+
85+
test('should have a client id', () async {
86+
final db = await testUtils.setupPowerSync(path: path);
87+
88+
final id = await db.getClientId();
89+
// Check that it is a valid uuid
90+
final _uuid = UuidParsing.parseAsByteList(id);
91+
});
8292
});
8393
}

0 commit comments

Comments
 (0)