cloudflare-docs icon indicating copy to clipboard operation
cloudflare-docs copied to clipboard

[D1] Deploying SveltKit on Cloudflare Pages using a D1 is unclear

Open ocolot opened this issue 1 year ago • 1 comments

Which Cloudflare product does this pertain to?

D1

Existing documentation URL(s)

  • https://developers.cloudflare.com/d1/examples/d1-and-sveltekit/
  • https://developers.cloudflare.com/pages/functions/bindings/#d1-databases

What changes are you suggesting?

Provide a working example. The deployment works fine, but I can't get the local database binding to be accessible on platform.env.DB. Especially, the --d1 NORTHWIND_DB=xxxx-xxxx-xxxx-xxxx-xxxx that does not appear in the command line doc if I am not mistaken.

How the D1 database is deployed locally should be clarified, the differences between wrangler and wrangler pages in local, what DB is used (confusing flags with opposite defaults, sometimes --remote, sometimes --local).

Additional information

No response

ocolot avatar Jan 31 '24 11:01 ocolot

Will look into this, thanks!

Maddy-Cloudflare avatar Jan 31 '24 11:01 Maddy-Cloudflare

Hi. I'm currently using hooks and a custom Vite plugin to shim Cloudflare KV, D1, and R2 on SvelteKit projects for local development. It lets me simulate the production Cloudflare environment without having to go through extra steps to perform a production build and bind the services locally via wrangler.

I've created a demo project here which anyone can use. I hope someone else might find it useful as it has made the development experience with my teams so much easier.

This solution utilizes the same submodules Miniflare uses directly and the local counterparts of each service is accessible to the developer. For example, the D1 (SQlite3) local counterpart is an actual SQLite3 database you can open with any DBMS. The same goes for KV and R2 in which they're just subdirectories of the project that the developer can access and inspect directly.

johnrcui avatar Mar 03 '24 23:03 johnrcui