OffSync
Local-first SQLite extension for seamless, conflict-free data sync and real-time collaboration across devices
SQLite Sync
SQLite Sync is a cross-platform extension that adds built-in offline support and automatic synchronization to standard SQLite databases, enabling a true local-first experience with zero latency. Applications can operate fully offline, with each device maintaining its own copy of the database When reconnected, all changes are seamlessly synchronized across devices. Developers can continue using the familiar simplicity and performance of SQLite while easily building distributed, collaborative applications without complex infrastructure.
Reliable Sync, Even Without the Internet
SQLite Sync is powered by CRDTs (Conflict-free Replicated Data Types), a class of algorithms designed for real-time collaboration and distributed systems. CRDTs ensure that changes made on different devices are merged automatically and without conflicts, even when made offline. This means no data loss, no overwrites, and no need for manual conflict resolution. Whether it's a multi-user app or a fleet of devices operating in the field, SQLite Sync keeps everything consistent and in sync automatically.
What Makes SQLite-Sync Special
-- 1. Load the extension
.load ./cloudsync
-- 2. Enable sync on your table
SELECT cloudsync_init('my_data');
-- 3. (Optional) Connect to the cloud and start syncing
SELECT cloudsync_network_sync();
<Sample Code>
The CRDT engine guarantess to merge changes from all connected
clients automatically and conflict-free.
-- Create your sync-enabled table
CREATE TABLE IF NOT EXISTS my_data (
id TEXT PRIMARY KEY NOT NULL,
value TEXT NOT NULL,
created_at TEXT DEFAULT CURRENT_TIMESTAMP
);
-- Enable sync tracking
SELECT cloudsync_init('my_data');
-- Insert local changes (even offline)
INSERT INTO my_data (id, value)
VALUES (cloudsync_uuid(), 'Hello from device A');
-- Later, sync with the cloud (better to be executed in a separate db connection)
SELECT cloudsync_network_init('sqlitecloud://your-project.sqlite.cloud/database.sqlite');
SELECT cloudsync_network_set_apikey('your-api-key');
SELECT cloudsync_network_sync();