Using one drizzle connection per request (Cloudflare + postgres)
When connecting to Drizzle postgres (Neon) through a cloudflare worker. I always get this error on first load.
I think it's due to the
db
being shared between requests.
What are some ideas to have one instance per worker?
My workaround is exporting this, but this means every single call to db.xxxx()
will call the drizzle function.
Will this create a bunch of connections?
1 Reply
This is how I'm setting up drizzle for my Cloudflare Pages project:
I think you have to use the
@neondatabase/serverless
client so that your queries are transmitted over fetch
.