Sync / foldkit-durable
On Cloudflare D1 (d1: true)
Cloudflare D1 speaks SQLite without explicit SQL transactions, PRAGMA user_version, or VACUUM. Pass d1: true to foldkit-durable/core with @effect/sql-d1:
ts
import * as D1Client from '@effect/sql-d1/D1Client'
import { Layer } from 'effect'
import { ActorId, Journal, OpId } from 'foldkit-durable/core'
const Todos = Journal.define<Operation, Snapshot, Principal>('app/Todos')
const live = Todos.layer({
...TodoSync.journalContract(),
opId: operation => OpId.make(operation.opId),
actorId: (principal: Principal) => ActorId.make(principal.actorId),
d1: true,
}).pipe(
Layer.provide(D1Client.layer({ db: env.DB })),
)How D1 mode behaves:
- Schema versions live in a
durable_metatable instead ofPRAGMA user_versionusing idempotent migrations. - Concurrent appends retry on uniqueness conflicts, re-reading the cursor and re-running
validate,authorize,reduce, andjudgeover the latest committed snapshot so appends stay gap-free. appendAllcommits each operation sequentially rather than in a single multi-statement transaction.- Snapshot reads replay only up to their target cursor and reject inconsistent mid-compaction reads.
vacuumsucceeds as a no-op since D1 manages compaction and storage automatically.- Route appends through a single Durable Object writer for exact read-your-commit consistency.
journal.storesaysserializableper statement here (isolates: 'statement'): D1 runs one statement or batch at a time, butvalidateandauthorizeread in one round trip and the append lands in another, and nothing holds the snapshot still between them, so a rule judged from that read is not held. Over SQLite it saysserializableper transaction (appends commit as if one at a time). Its fields are those ofStoreCapabilitiesin@doeixd/metakit/store(name,isolation,isolates,parentRowLock).
Journal.make (the Node file entrypoint) refuses d1: true; use foldkit-durable/core with D1Client instead.