@sqlite-sync/core 0.4.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +81 -0
  2. package/package.json +1 -1
package/README.md ADDED
@@ -0,0 +1,81 @@
1
+ # @sqlite-sync/core
2
+
3
+ Core sync engine for [sqlite-sync](https://github.com/krolebord-dev/sqlite-sync) — a local-first SQLite sync engine for web apps, with reactive queries, offline persistence, and CRDT-based replication.
4
+
5
+ This package provides:
6
+
7
+ - `createSyncedDb()` for client orchestration (worker attach, snapshot hydration, sync state).
8
+ - The schema builder (`createSyncDbSchema`) and migrations (`createMigrations`).
9
+ - Live query primitives (`db.createLiveQuery(...)`), typed through [Kysely](https://kysely.dev/).
10
+ - CRDT primitives with Last-Write-Wins per-field replication and HLC timestamps.
11
+ - The worker runtime (`@sqlite-sync/core/worker`) and server protocol types (`@sqlite-sync/core/server`).
12
+
13
+ ## Install
14
+
15
+ ```bash
16
+ pnpm add @sqlite-sync/core kysely
17
+ ```
18
+
19
+ For React bindings, add [`@sqlite-sync/react`](https://www.npmjs.com/package/@sqlite-sync/react).
20
+
21
+ ## Quick start
22
+
23
+ ```ts
24
+ import { createMigrations, createSyncDbSchema, createSyncedDb } from "@sqlite-sync/core";
25
+
26
+ type Todo = {
27
+ id: string;
28
+ title: string;
29
+ completed: boolean;
30
+ tombstone?: boolean;
31
+ };
32
+
33
+ const migrations = createMigrations((b) => ({
34
+ 0: [
35
+ b.createTable("_todo", (t) =>
36
+ t
37
+ .addColumn("id", "text", (col) => col.primaryKey().notNull())
38
+ .addColumn("title", "text", (col) => col.notNull())
39
+ .addColumn("completed", "boolean", (col) => col.notNull().defaultTo(false))
40
+ .addColumn("tombstone", "boolean", (col) => col.notNull().defaultTo(false)),
41
+ ),
42
+ ],
43
+ }));
44
+
45
+ export const syncDbSchema = createSyncDbSchema({ migrations })
46
+ .addTable<Todo>()
47
+ .withConfig({ baseTableName: "_todo", crdtTableName: "todo" })
48
+ .build();
49
+
50
+ const worker = new Worker(new URL("./db-worker.ts", import.meta.url), { type: "module" });
51
+
52
+ export const db = await createSyncedDb({
53
+ dbId: "app-db",
54
+ worker,
55
+ workerProps: undefined,
56
+ syncDbSchema,
57
+ });
58
+ ```
59
+
60
+ Start the worker (remote sync optional):
61
+
62
+ ```ts
63
+ // db-worker.ts
64
+ import { startDbWorker } from "@sqlite-sync/core/worker";
65
+ import { syncDbSchema } from "./db-schema";
66
+
67
+ await startDbWorker({ syncDbSchema });
68
+ ```
69
+
70
+ ## Requirements
71
+
72
+ - Browser: Web Workers + Web Locks + an OPFS-capable SQLite WASM environment.
73
+ - Peer dependency: `kysely` (`^0.28.0 || ^0.29.0`).
74
+
75
+ ## Documentation
76
+
77
+ See the [full documentation](https://github.com/krolebord-dev/sqlite-sync/blob/main/docs.md) and the [project README](https://github.com/krolebord-dev/sqlite-sync) for guides, recovery/storage versioning, and the Cloudflare sync backend.
78
+
79
+ ## License
80
+
81
+ MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sqlite-sync/core",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
4
4
  "description": "SQLite synchronization library with CRDT support",
5
5
  "type": "module",
6
6
  "license": "MIT",