Pure-Nix CR-SQLite extension for conflict-free replicated databases. Just Works™ everywhere - Mac, Linux, Pi, Docker, Vercel, etc.
CR-SQLite is a run-time loadable extension for SQLite that enables Conflict-free Replicated Data Types (CRDTs). It allows you to create tables that can be replicated across multiple devices/servers and automatically merge changes without conflicts.
This package provides pre-built CR-SQLite extensions via Nix, eliminating the need to build from source.
npm install @effect-native/libcrsqlimport { pathToCRSQLiteExtension } from '@effect-native/libcrsql';
import Database from 'better-sqlite3';
const db = new Database(':memory:');
db.loadExtension(pathToCRSQLiteExtension);
// Convert table to conflict-free replicated relation
db.exec(`
CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT);
SELECT crsql_as_crr('users');
`);
// Insert data - changes are automatically tracked
db.exec(`INSERT INTO users (name) VALUES ('Alice')`);
// Get changes for synchronization
const changes = db.prepare(`SELECT * FROM crsql_changes`).all();
console.log('Changes to sync:', changes);Path to the CR-SQLite extension file. Use this with your SQLite library's loadExtension() method.
import { pathToCRSQLiteExtension } from '@effect-native/libcrsql';
console.log(pathToCRSQLiteExtension); // /path/to/crsqlite-darwin-aarch64.dylibFunction that returns the path to the CR-SQLite extension.
import { getExtensionPath } from '@effect-native/libcrsql';
const extensionPath = getExtensionPath();npx libcrsql-extension-path
# /path/to/crsqlite-darwin-aarch64.dylib- ✅ macOS (Intel & Apple Silicon)
- ✅ Linux (x86_64 & ARM64)
- ✅ Docker containers
- ✅ Vercel, Netlify, Railway
- ✅ Raspberry Pi 4+
- ✅ AWS Lambda (with custom runtime)
Works with any SQLite library that supports loading extensions:
import Database from 'better-sqlite3';
import { pathToCRSQLiteExtension } from '@effect-native/libcrsql';
const db = new Database('my-app.db');
db.loadExtension(pathToCRSQLiteExtension);import sqlite3 from 'sqlite3';
import { pathToCRSQLiteExtension } from '@effect-native/libcrsql';
const db = new sqlite3.Database('my-app.db');
db.loadExtension(pathToCRSQLiteExtension);import { Database } from 'bun:sqlite';
import { pathToCRSQLiteExtension } from '@effect-native/libcrsql';
const db = new Database('my-app.db');
db.loadExtension(pathToCRSQLiteExtension);This package is for Node.js/Bun server environments only. For React Native, use:
Once loaded, CR-SQLite provides these functions:
crsql_as_crr(table_name)- Convert table to conflict-free replicated relationcrsql_version()- Get CR-SQLite versioncrsql_changes- Virtual table containing changes for synccrsql_begin_alter(table_name)- Begin schema changescrsql_commit_alter(table_name)- Commit schema changes
See CR-SQLite Documentation for complete API reference.
- Nix package manager
- Node.js 16+
# Build CR-SQLite extensions for all platforms
npm run bundle-lib
# Build production package
npm run build-production
# Run tests
npm test
npm run test:docker# Check what platforms are available
npm list @effect-native/libcrsql
ls node_modules/@effect-native/libcrsql/lib/
# Get extension path for debugging
npx libcrsql-extension-path- Fork the repository
- Create your feature branch:
git checkout -b my-feature - Make your changes and run tests:
npm test - Submit a pull request
MIT
- CR-SQLite - The upstream CR-SQLite project
- @effect-native/libsqlite - Nix-built SQLite library
- vlcn.io - CR-SQLite documentation and tools