Skip to content

Commit 88521ea

Browse files
Merge branch '159-database-and-sync-version-apis' into 'main'
Add getters for Sync protocol, database version See merge request objectbox/objectbox-dart!117
2 parents 419ce2c + d8743be commit 88521ea

File tree

4 files changed

+21
-1
lines changed

4 files changed

+21
-1
lines changed

objectbox/lib/src/native/store.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,13 @@ class Store implements Finalizable {
498498
detach: this, externalSize: 200 * 1024);
499499
}
500500

501+
/// Returns the version and features of the platform-specific ObjectBox
502+
/// database library.
503+
///
504+
/// The format may change in any future release, only use this for
505+
/// informational purposes.
506+
static String databaseVersion() => dartStringFromC(C.version_core_string());
507+
501508
/// Returns if an open store (i.e. opened before and not yet closed) was found
502509
/// for the given [directoryPath].
503510
///

objectbox/lib/src/native/sync.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,13 @@ class SyncClient {
238238
/// Returns if this sync client is closed and can no longer be used.
239239
bool isClosed() => _cSync.address == 0;
240240

241+
/// Returns the protocol version this client uses.
242+
static int protocolVersion() => C.sync_protocol_version();
243+
244+
/// Returns the protocol version of the server after a connection is
245+
/// established (or attempted), zero otherwise.
246+
int protocolVersionServer() => C.sync_protocol_version_server(_ptr);
247+
241248
/// Gets the current sync client state.
242249
SyncState state() {
243250
final state = C.sync_state(_ptr);

objectbox_test/test/basics_test.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import 'dart:ffi' as ffi;
22

33
import 'package:objectbox/internal.dart';
4+
import 'package:objectbox/objectbox.dart';
45
import 'package:objectbox/src/native/bindings/bindings.dart';
56
import 'package:objectbox/src/native/bindings/helpers.dart';
67
import 'package:objectbox/src/native/version.dart';
@@ -14,7 +15,8 @@ void main() {
1415
expect(atLeastDart("999.0.0"), false);
1516
});
1617

17-
print("Testing basics of ObjectBox using C lib V${libraryVersion()}");
18+
print("Testing basics of ObjectBox using C lib V${libraryVersion()} "
19+
"with database version ${Store.databaseVersion()}");
1820

1921
// Prior to Dart 2.6, the exception wasn't accessible and may have crashed.
2022
// Similarly, this occured in Fluter for Linux (desktop).

objectbox_test/test/sync_test.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ void main() {
9999

100100
if (Sync.isAvailable()) {
101101
// TESTS to run when SYNC is available
102+
print("Testing Sync with protocol version ${SyncClient.protocolVersion()}");
102103

103104
test('SyncClient lifecycle', () {
104105
expect(store.syncClient(), isNull);
@@ -210,6 +211,9 @@ void main() {
210211
SyncClient c = createClient(store);
211212
expect(c.isClosed(), isFalse);
212213

214+
expect(SyncClient.protocolVersion(), greaterThanOrEqualTo(7));
215+
expect(c.protocolVersionServer(), 0);
216+
213217
c.setCredentials(SyncCredentials.none());
214218
c.setCredentials(SyncCredentials.googleAuthString('secret'));
215219
c.setCredentials(SyncCredentials.sharedSecretString('secret'));

0 commit comments

Comments
 (0)