feat(db-d1-sqlite): http transport for D1 via Cloudflare REST API by JarrodMFlesch · Pull Request #16269 · payloadcms/payload · GitHub
Skip to content

feat(db-d1-sqlite): http transport for D1 via Cloudflare REST API#16269

Draft
JarrodMFlesch wants to merge 2 commits intomainfrom
http-d1
Draft

feat(db-d1-sqlite): http transport for D1 via Cloudflare REST API#16269
JarrodMFlesch wants to merge 2 commits intomainfrom
http-d1

Conversation

@JarrodMFlesch
Copy link
Copy Markdown
Contributor

Summary

Adds an optional http configuration to @payloadcms/db-d1-sqlite so D1 can be used from runtimes without a Workers binding (for example Node or Vercel) by calling Cloudflare’s D1 HTTP API. The adapter accepts either a Workers binding or http credentials, validates that they are not combined, and documents that read-replica session mode is Workers-only.

Implements a small REST client (prepare, batch, exec, and query) plus Vitest coverage with mocked fetch. Because dropDatabase in @payloadcms/drizzle/sqlite expects a libsql-style client.execute API, connect wires a shim that maps execute / executeMultiple onto D1’s prepare().all() and exec, which fixes PAYLOAD_DROP_DATABASE and other code paths that assumed a libsql client.

Adds an integration test under test/d1-http that runs against a real D1 database when CLOUDFLARE_ACCOUNT_ID, CLOUDFLARE_D1_DATABASE_ID, and CLOUDFLARE_API_TOKEN are set, and skips otherwise. README updates describe Workers vs HTTP usage and environment variables.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 13, 2026

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