cloudflare / cloudflare-docs

Cloudflare’s documentation
https://developers.cloudflare.com
Creative Commons Attribution 4.0 International
2.7k stars 2.76k forks source link

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

Open ocolot opened 5 months ago

ocolot commented 5 months ago

Which Cloudflare product does this pertain to?

D1

Existing documentation URL(s)

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

Maddy-Cloudflare commented 5 months ago

Will look into this, thanks!

johnrcui commented 4 months ago

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.