Skip to content

Latest commit

 

History

History
81 lines (65 loc) · 1.98 KB

README.md

File metadata and controls

81 lines (65 loc) · 1.98 KB

Isar Crdt

addon to add crdt capabilities to isar

Features

  • Pure Dart
  • Save changes on collection

Getting started

1. Add to pubspec.yaml

dependencies:
  isar_crdt: ^0.0.1

Usage

  1. extend your models with CrdtBaseObject
  • add toJson function and add all the fields you want to sync (include id and sid)
  1. Create a model to store the crdt changes and extends with ChangesyncBaseModel
  • no need to add anything
// models
@collection
class CarModel extends CrdtBaseObject {
  Id id = Isar.autoIncrement;
  late String make;
  late String year;

  @override
  Map<String, dynamic> toJson() {
    return {
      "id": id,
      "sid": sid,
      "make": make,
      "year": year,
    };
  }
}

@collection
class CrdtEntry extends ChangesyncBaseModel {}
  1. add the models including the crdt model to the isar instance
  2. create a changesync instance and add it to the isar instance
  final isar = await Isar.open(
      [CarModelSchema, CrdtEntrySchema],
    );


  final changesSync = IsarCrdt(
    store: IsarMasterCrdtStore(
      isar.crdtEntrys,
      builder: () => CrdtEntry(),
      sidGenerator: () => uuid.v4(),
    ),
  );
  isar.setCrdt(changesSync);

Additional information

TODO: Tell users more about the package: where to find more information, how to contribute to the package, how to file issues, what response they can expect from the package authors, and more.