Skip to content

[miniflare] Use workerd's built-in D1 for local D1 databases - #16955

Draft
ry wants to merge 1 commit into
mainfrom
ry/miniflare-workerd-d1
Draft

ry wants to merge 1 commit into
mainfrom
ry/miniflare-workerd-d1

Conversation

@ry

@ry ry commented Nov 16, 2026

Copy link
Copy Markdown
Member

This is part of the effort to merge celld into workerd, after KV (#16684). Over in workerd, cloudflare/workerd#8486 (landed) adds D1 as a bundled Worker, /workerd/d1.js: each database is a SQLite-backed Durable Object, behind the existing D1 binding, serving both the query() RPC and HTTP protocols, including PRAGMA miniflare_d1_export for wrangler d1 export --local.

This PR switches Miniflare's local D1 over to it:

  • Local D1 bindings go to a d1:workerd service running /workerd/d1.js, with {"database": "<id>"} in their props.
  • Existing local databases keep their data: workerd's D1 keeps Miniflare's uniqueKey (miniflare-D1DatabaseObject) and disk, and a database written by the previous Miniflare reads back unchanged.
  • Miniflare's D1 object and its helpers (database.worker.ts, schemas.ts, export.ts, dumpSql.ts) are removed: source +105 −869.
  • The entry worker, used by the local explorer and shared storage for a database named at runtime, forwards to workerd's D1 through the debug port, as KV's does.

Differences: meta.served_by is "workerd", and errors thrown by query() are named Error rather than D1_ERROR; naming them D1_ERROR doubles the prefix (D1_ERROR: D1_ERROR: ...) for callers without enhanced_error_serialization. Three regression tests about failures writing the session bookmark are removed, since bookmarks no longer write.

Draft: this waits for a workerd release that includes #8486. The generated workerd.ts is deliberately not regenerated here; it will be regenerated against that release (it needs Worker.Module.bundled), and until then the D1 tests fail. Against a local workerd build with #8486 and regenerated types, the D1 and local explorer tests pass (337 tests).

  • Tests
    • Tests included/updated
  • Public documentation
    • Documentation not necessary because: local behaviour only; the changeset notes the differences.

Local D1 bindings now go to workerd's D1 Worker, the bundled module
/workerd/d1.js, with {"database": "<id>"} in their props. Its Durable
Objects keep Miniflare's uniqueKey (miniflare-D1DatabaseObject) and
disk, so existing local databases are the same files; a database
written by the previous Miniflare reads back unchanged.

Miniflare's own D1 object (database.worker.ts) and its helpers are
removed. The entry worker, used by the local explorer and shared
storage to reach a database named at runtime, now forwards to workerd's
D1 through the debug port, as the KV entry worker does.

Tests: served_by is "workerd"; query() errors are named Error, not
D1_ERROR. Removed are three regression tests for failures writing the
session bookmark, which no longer writes. PRAGMA miniflare_d1_export,
for wrangler d1 export --local, is answered by workerd's D1, and the
export tests pass against it.

Needs a workerd release with workerd#8486, and generated/workerd.ts
regenerated from it so the config can carry Worker.Module.bundled;
until then the D1 tests fail.
@changeset-bot

changeset-bot Bot commented Nov 16, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 9b1ac99

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 8 packages
Name Type
miniflare Minor
@cloudflare/deploy-helpers Patch
@cloudflare/pages-shared Patch
@cloudflare/remote-bindings Patch
@cloudflare/runtime-types Patch
@cloudflare/vite-plugin Patch
@cloudflare/vitest-plugin Patch
wrangler Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

{
name: D1_WORKERD_SERVICE_NAME,
worker: {
compatibilityDate: "2026-01-01",

@ask-bonk ask-bonk Bot Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The checked-in generated binding does not contain a bundled union member (or an _initBundled method). serializeConfig encodes modules by calling _init${capitalized}, so a worker with a local D1 binding currently throws TypeError: anyStruct._initBundled is not a function during startup. Please regenerate workerd.ts from the workerd release that introduces Worker.Module.bundled before merging.

@ask-bonk

ask-bonk Bot commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

I'm Bonk, and I've done a quick review of your PR.

Summary: Replaces Miniflare’s D1 implementation with workerd’s bundled D1 worker.

  1. P1: Posted 1 actionable inline finding.

github run

@pkg-pr-new

pkg-pr-new Bot commented Nov 16, 2026

Copy link
Copy Markdown
@cloudflare/autoconfig

npm i https://pkg.pr.new/@cloudflare/autoconfig@16955

@cloudflare/build-output-utils

npm i https://pkg.pr.new/@cloudflare/build-output-utils@16955

@cloudflare/codemods

npm i https://pkg.pr.new/@cloudflare/codemods@16955

@cloudflare/config

npm i https://pkg.pr.new/@cloudflare/config@16955

@cloudflare/containers-shared

npm i https://pkg.pr.new/@cloudflare/containers-shared@16955

create-cloudflare

npm i https://pkg.pr.new/create-cloudflare@16955

@cloudflare/deploy-helpers

npm i https://pkg.pr.new/@cloudflare/deploy-helpers@16955

@cloudflare/kv-asset-handler

npm i https://pkg.pr.new/@cloudflare/kv-asset-handler@16955

miniflare

npm i https://pkg.pr.new/miniflare@16955

@cloudflare/pages-functions

npm i https://pkg.pr.new/@cloudflare/pages-functions@16955

@cloudflare/pages-shared

npm i https://pkg.pr.new/@cloudflare/pages-shared@16955

@cloudflare/runtime-types

npm i https://pkg.pr.new/@cloudflare/runtime-types@16955

@cloudflare/unenv-preset

npm i https://pkg.pr.new/@cloudflare/unenv-preset@16955

@cloudflare/vite-plugin

npm i https://pkg.pr.new/@cloudflare/vite-plugin@16955

@cloudflare/vitest-plugin

npm i https://pkg.pr.new/@cloudflare/vitest-plugin@16955

@cloudflare/workers-auth

npm i https://pkg.pr.new/@cloudflare/workers-auth@16955

@cloudflare/workers-editor-shared

npm i https://pkg.pr.new/@cloudflare/workers-editor-shared@16955

@cloudflare/workers-utils

npm i https://pkg.pr.new/@cloudflare/workers-utils@16955

wrangler

npm i https://pkg.pr.new/wrangler@16955

commit: 9b1ac99

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Untriaged

Development

Successfully merging this pull request may close these issues.

1 participant