Skip to content

eelco2k/isar_crdt

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 CrdtBaseObject
  • 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 CrdtBaseObject {}
  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 dir = await getApplicationDocumentsDirectory();
  final isar = await Isar.open(
      [CarModelSchema, CrdtEntrySchema],
      dir: dir.path,
    );


  final changesSync = IsarCrdt(
    store: IsarMasterCrdtStore(
      isar.crdtEntrys,
      nodeId: "", // change to your own nodeId
      builder: () => CrdtEntry(),
      sidGenerator: () => uuid.v4(),
    ),
  );
  isar.setCrdt(changesSync);
  1. don't forget to import the packages as they are required as the example shown here above
import 'package:uuid/uuid.dart';
import 'package:isar/isar.dart';
import 'package:isar_crdt/isar_crdt.dart';
import 'package:path_provider/path_provider.dart';

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.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Dart 100.0%