Coder Social home page Coder Social logo

cachapa / sql_crdt Goto Github PK

View Code? Open in Web Editor NEW
51.0 3.0 3.0 141 KB

Dart implementation of Conflict-free Replicated Data Types (CRDTs) using SQL databases

Home Page: https://pub.dev/packages/sql_crdt

License: Apache License 2.0

Dart 100.00%
crdt database flutter sql sqlite sqlite3 dart postgres postgresql

sql_crdt's Introduction

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 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.

Notes

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, and modified.
  • Deleted records aren't actually removed but rather flagged in the is_deleted column.
  • A reactive watch method to subscribe to database queries.
  • Convenience methods getChangeset and merge inherited from the crdt package 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.

API

The API is intentionally kept simple with a few methods:

  • execute to run non-select SQL queries, e.g. inserts, updates, etc.
  • query to perform a one-time query.
  • watch to receive query results whenever the database changes.
  • getChangeset to generate a serializable changeset of the local database.
  • merge to apply a remote changeset to the local database.
  • transaction a blocking mechanism that avoids running simultaneous transactions in async code.

Check the examples in sqlite_crdt and postgres_crdt for more details.

Features and bugs

Please file feature requests and bugs in the issue tracker.

sql_crdt's People

Contributors

cachapa avatar janezstupar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

sql_crdt's Issues

Conflict resolution for multiple changed attributes on a single entity

Thanks for this rather straightforward looking package!

I have one question about following use case:

entity: id, name, color, category
node1: ch1: changes color and name
node2: ch2: changes category and name

changes on node1 and node2 happen on the same state, means none of those changes is more "correct" than the other.

ch2 arrives at server first, then ch1. Would it work in Last-Write-Wins fashion? Would it retain color and category changes without conflict?
How does the server decide, which change to apply first?

Thanks!

README request

Hello, I am guessing that hlc is hybrid-logical clocks. Can you add a footnote to your readme that unpacks this a bit?

"HLCs use a combination of system timestamp and logical timestamp to have versions as date-time, which can be ordered." I would also be curious to know what data primitive the underlying postgres/sqlite uses to store these.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.