This project aims to extend the functionality of the Isar database to allow remote synchronization (isar/isar#2).
The remote synchronization is achieved by generating HLC (Hybrid Logical Clock) per field that act as a version number for the current value. This allows two versions of an object to be merged consistently while also retaining the newer version of each field.
- collection classes
- embedded classes
- primitive types
- Lists
import 'package:isar_crdt/isar_crdt.dart'; // <--
import 'package:isar/isar.dart';
part 'test_class.isar_crdt.g.dart'; // <--
part 'test_class.isar.g.dart'; // <-- instead of test_class.g.dart
@crdtCollection // <--
@collection
class TestClass extends _TestClassCrdt {
...
}
...
// Create/update object
await isar.writeTxn(() {
return isar.testClass.put(obj);
});
// Merge object from a remote node
await isar.writeTxn(() {
return isar.testClass.merge(obj);
});
isar.testClass
return IsarCrdtCollection
(instead of IsarCollection
) that abstract all the HLC handling logic.
to generate globally unique IDs for isar objects the following limitations are recommended to avoid ID collisions.
4,294,967,295
objects per Isar collection.4,294,967,295
nodes or users.