Dart implementation of Conflict-free Replicated Data Types (CRDTs) using SQL databases.
This project is heavily influenced by James Long's talk CRTDs for Mortals and includes a Dart-native implementation of Hybrid Local Clocks (HLC) based on the paper Logical Physical Clocks and Consistent Snapshots in Globally Distributed Databases.
sql_crdt is based on crdt and the learnings from Libra, StoryArk and tudo.
This package is abstract and implements the base functionality for CRDTs backed by a relational database. Check sqlite_crdt and postgres_crdt for usable implementations.
See also tudo for a real-world FOSS implementation.
This package is compatible with crdt_sync, a turnkey approach for real-time network synchronization of CRDT nodes.
sql_crdt is not an ORM. The API is essentially that of a plain old SQL database with a few behavioural changes:
- Every table gets 3 columns automatically added:
is_deleted,hlc, andmodified. - Deleted records aren't actually removed but rather flagged in the
is_deletedcolumn. - A reactive
watchmethod to subscribe to database queries. - Convenience methods
getChangesetandmergeinherited from thecrdtpackage to sync with remote nodes.
⚠ Because deleted records are only flagged as deleted, they may need to be sanitized in order to be compliant with GDPR and similar legislation.
The API is intentionally kept simple with a few methods:
executeto run non-select SQL queries, e.g. inserts, updates, etc.queryto perform a one-time query.watchto receive query results whenever the database changes.getChangesetto generate a serializable changeset of the local database.mergeto apply a remote changeset to the local database.transactiona blocking mechanism that avoids running simultaneous transactions in async code.
Check the examples in sqlite_crdt and postgres_crdt for more details.
Please file feature requests and bugs in the issue tracker.