@copypatch/storage-sqlite
v2.0.0
Published
SQLite persistence adapter for CopyPatch
Maintainers
Readme
@copypatch/storage-sqlite
SQLite persistence for CopyPatch v2. The adapter implements the asynchronous
CopyPatchPersistence contract while using transactional, synchronous SQLite
operations internally.
Install
pnpm add @copypatch/core @copypatch/storage-sqlite better-sqlite3Node.js 20 or newer is required.
Usage
import { createSQLitePersistence } from '@copypatch/storage-sqlite';
const persistence = createSQLitePersistence('./data/copypatch.sqlite');
await persistence.migrate();
try {
const snapshot = await persistence.readPublished('en');
console.log(snapshot);
} finally {
persistence.close();
}The factory also accepts { filename, busyTimeoutMs }. Call migrate() before
the first operation on a new database. Migrations are versioned and idempotent.
Content mutations use atomic compare-and-swap checks against both published and draft revisions. Sessions and rate limits are stored in SQLite so they survive process restarts. Session callers must pass cryptographic token hashes; the adapter never accepts or derives raw session tokens.
Exports
createSQLitePersistence(filenameOrOptions)SQLitePersistenceSQLitePersistenceOptions
CopyPatch is ESM-only. See the CopyPatch repository for complete API documentation and examples.
