Skip to content

feat(core): sqlite driver for durable object storage - #41659

Merged
kitlangton merged 3 commits into
v2from
durable-object-sqlite
Aug 11, 2026
Merged

feat(core): sqlite driver for durable object storage#41659
kitlangton merged 3 commits into
v2from
durable-object-sqlite

Conversation

@kitlangton

@kitlangton kitlangton commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

What

  • Adds a SqlClient driver over injected Cloudflare Durable Object storage.
  • Exports Database.layerFromClient, the database service layer over an injected SqlClient — for runtimes that receive database storage instead of opening a filesystem path. The SqlClient and Global requirements stay visible in the layer type and the caller composes standard Layer.provide; any client provided still goes through the pragma guards and migrations.
  • Tests the driver, transaction behavior, and full schema boot hermetically on Bun without requiring workerd.

Why

Running the OpenCode server embedded in edge and Durable Object runtimes requires database access over injected storage rather than a filesystem path. The new seam is runtime-neutral, and the Durable Object driver remains inert unless a runtime explicitly composes it.

How

  • sqlite.workerd.ts adapts storage.sql.exec to Effect SQL, normalizes blob results, and maps Durable Object transactions to withTransaction. Nested transactions fail with SqlError because Durable Object SQLite does not support savepoints.
  • SQLite adapter capability flags prevent unsupported tuning and foreign-key pragmas while preserving existing Bun and Node behavior.
  • Database.layer() now composes over Database.layerFromClient, preserving its existing Global.Service path resolution.
  • Schema bootstrap treats unprefixed tables as OpenCode-owned and ignores underscore-prefixed tables reserved for embedders sharing the database.

Testing

  • bunx tsgo --noEmit in packages/core
  • bun test test/sqlite-workerd.test.ts
  • bun test test/sqlite-workerd.test.ts test/database-migration.test.ts
  • bun run test in packages/core (1,641 passed, 16 skipped)

Severability

The co-tenancy policy is isolated in fix(core): schema bootstrap ignores co-tenant tables. Reviewers can drop that commit without affecting the Durable Object driver or Database.layerFromClient seam.

@kitlangton

Copy link
Copy Markdown
Contributor Author

Implementation and verification are complete; ready for review.

@kitlangton
kitlangton force-pushed the durable-object-sqlite branch from 4d57e54 to 97732ec Compare August 11, 2026 19:30
@kitlangton
kitlangton merged commit c5704d3 into v2 Aug 11, 2026
10 checks passed
@kitlangton
kitlangton deleted the durable-object-sqlite branch August 11, 2026 19:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant