SvelteKit (Vite) + D1 + Prisma Local development
I have a SvelteKit app that I'm developing with a D1 database accessed through Prisma.
I'm trying to run the Vite development server locally and have it connect to D1 locally.
My app works when deployed to workers (with experimental assets enabled), and can read/write from the D1 database via Prisma.
The code to initialize my database connection is:
Running locally, I typically run
vite dev --host
Is there a way to get vite dev
running so that it can access a local D1 Instance provided by Wrangler?
If not, is there a way to get that running so that my local dev environment could write to a real/hosted D1 instance that I specify?
Let me know if there's other info that could be helpful1 Reply
I have solved this issue, but to help anyone else who comes across this:
In your svelte.config.js file, be sure to reference the configuration in your wrangler.json/toml:
The bindings are not then available through
$end/dynamic/private
locally, they're only available in the context of a request. For example for a D1 database called DB, it would be accessible in the context of a request/hook as event.platform?.env.DB