drift_crdt 1.0.0 copy "drift_crdt: ^1.0.0" to clipboard
drift_crdt: ^1.0.0 copied to clipboard

A Flutter-only implementation of a drift CRDT database, based on the `sqlite_crdt` package and `sqflite`.

drift_crdt #

drift_crdt contains a CRDT drift database implementation based on the sqflite package. This package is a plugin for Drift by Simon Binder and is based on Simon Binder's drift_sqflite package.

For more information on drift, see its documentation.

Usage #

The CrdtQueryExecutor class can be passed to the constructor of your drift database class to make it use sqflite.

@DriftDatabase(tables: [Todos, Categories])
class MyDatabase extends _$MyDatabase {
  // we tell the database where to store the data with this constructor
  MyDatabase() : super(_openConnection());

  // you should bump this number whenever you change or add a table definition.
  // Migrations are covered later in the documentation.
  @override
  int get schemaVersion => 1;
}

QueryExecutor _openConnection() {
  return CrdtQueryExecutor.inDatabaseFolder(path: 'db.sqlite');
}

CRDT specific features #

Use CrdtQueryExecutor.getLastModified to get the last modified timestamp of the database. See CrdtQueryExecutor.getLastModified for more information.

  final changeset = await (db.executor as CrdtQueryExecutor).getCLastModified();

Use CrdtQueryExecutor.getChangeset to get the changeset of the database. See CrdtQueryExecutor.getChangeset for more information.

  final changeset = await (db.executor as CrdtQueryExecutor).getChangeset();

Use 'CrdtQueryExecutor.merge' to merge a changeset into the database. See CrdtQueryExecutor.merge for more information.

  await (db.executor as CrdtQueryExecutor).merge(changeset);

Serialization into JSON #

I am using the json_annotation package to serialize the changesets into and from JSON in my own project. You can see an example of such in the test suite of this package.

Note: The drift_crdt package is an alternative to the standard approach suggested in the drift documentation (which consists of a NativeDatabase instead of CrdtQueryExecutor).

5
likes
0
pub points
47%
popularity

Publisher

verified publisherjanezstupar.com

A Flutter-only implementation of a drift CRDT database, based on the `sqlite_crdt` package and `sqflite`.

Homepage
Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

drift, flutter, json_annotation, json_serializable, path, sqflite, synchroflite

More

Packages that depend on drift_crdt