cr-sqlite
Convergent, Replicated SQLite. Multi-writer and CRDT support for SQLite
What is cr-sqlite?
Convergent, Replicated SQLite. Multi-writer and CRDT support for SQLite
Overview of cr-sqlite
What it is
cr-sqlite is a run-time loadable extension for SQLite and libSQL. It allows merging different SQLite databases that have taken independent writes, adding multi-master replication and partition tolerance via conflict free replicated data types (CRDTs) and/or causally ordered event logs.
Key features
- Upgrades existing tables to conflict free replicated relations (CRRs) using the
crsql_as_crrfunction - Provides a
crsql_changesvirtual table to fetch and apply changesets between databases - Supports altering CRR table definitions with
crsql_begin_alterandcrsql_commit_alter - Pre-built binaries are available in the releases section for loading into SQLite from any language with SQLite bindings
- A WASM build is available for browser use
Use cases
- Syncing data between devices
- Implementing realtime collaboration
- Offline editing
- Being resilient to network conditions
- Enabling instantaneous interactions
Getting started
Load the extension, create tables, upgrade them to CRRs, insert data, and query or merge changes. Example from the README:
.load crsqlite
create table foo (a primary key not null, b);
select crsql_as_crr('foo');
insert into foo (a,b) values (1,2);
select "table", "pk", "cid", "val", "col_version", "db_version", "site_id", "cl", "seq" from crsql_changes;
-- Merge changes from a peer
insert into crsql_changes ("table", "pk", "cid", "val", "col_version", "db_version", "site_id", "cl", "seq") values (...);
For full documentation, see the repository README.
License and pricing
License: MIT. The project is open source with no stated pricing.
Based on the project's public README and repository metadata.