Registry / database / replic-sqlite

replic-sqlite

JSON →
library0.4.0jsnpmunverified

Replic-sqlite adds multi-writer, conflict-free replication to SQLite via CRDT patches, using only ~800 lines of code. Version 0.4.0 is actively developed and already used in production. Key differentiators: extremely lightweight, no leader bottleneck, protocol-agnostic transport, selective per-table replication, crash-safe, and supports rolling schema upgrades. Compared to libSQL, Turso, cr-sqlite, or dqlite, it is purely embedded (no separate process) and relies on CRDT for eventual consistency without strong ordering.

database
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Module is ESM-only; no CommonJS export.

import { ReplicSQLite } from 'replic-sqlite'

Server factory is exported from a subpath; not at package root.

import { createServer } from 'replic-sqlite/server'

Default export provides a pre-configured instance; named export ReplicSQLite is the class.

import Replic from 'replic-sqlite'

Shows how to set up a replic-sqlite server and client with WebSocket transport for multi-writer replication.

import { ReplicSQLite } from 'replic-sqlite'; import { createServer } from 'replic-sqlite/server'; import Database from 'better-sqlite3'; const db = new Database(':memory:'); db.exec(`CREATE TABLE IF NOT EXISTS todos (id TEXT PRIMARY KEY, task TEXT, done INTEGER)`); db.exec(`CREATE TABLE IF NOT EXISTS todos_patches (id TEXT PRIMARY KEY, patch BLOB)`); const replic = new ReplicSQLite({ db, secret: process.env.SECRET ?? 'changeme' }); // Create a WebSocket server that handles sync const server = createServer({ replic, port: 8080 }); server.start(); console.log('Replic server running on ws://localhost:8080'); // In another process, connect a client import WebSocket from 'ws'; const ws = new WebSocket('ws://localhost:8080'); const replicClient = new ReplicSQLite({ db: new Database(':memory:'), secret: 'changeme' }); replicClient.connect(ws);
Debug
Known footguns
breakingIn v0.4.0, the table enumeration pattern changed: all tables to be replicated MUST have a corresponding `_patches` table. Tables without a patches table are silently ignored.
breakingThe 'createServer' function moved from 'replic-sqlite' to 'replic-sqlite/server' in v0.4.0. Old imports break.
deprecatedThe option 'syncInterval' (used in constructor) is deprecated in v0.4.0 and will be removed in v0.5.0. Use 'syncIntervalMs' instead.
gotchaDefault export `Replic` is a pre-configured instance, but its internal database connection uses a fixed file path. Overriding the database path may cause silent failure.
gotchaThe 'secret' option must be identical on all replicas; mismatched secrets will cause silent disconnect without error.
Upgrade
Version history

Breaking-change detection hasn't run for this library yet.

Audit
Security & dependencies

CVE tracking and dependency tree are planned for a later release.

Agent activity
0 hits · last 30 days

No traffic data recorded yet.

Resources