I don't know how Drizzle works internally, but D1 doesn't have the concept of a long-lived connectio

I don't know how Drizzle works internally, but D1 doesn't have the concept of a long-lived connection like a traditional database. Every query you do sends a request to the database using connections managed by the runtime.
Our recommendation is to always use the fresh
env.{DATABASE_BINDING}
you get in each request, otherwise you will definitely hit issues at some point.

This is what their example is doing as well: https://orm.drizzle.team/docs/connect-cloudflare-d1#step-2---initialize-the-driver-and-make-a-query
Looking at https://github.com/drizzle-team/drizzle-orm/blob/main/drizzle-orm/src/d1/driver.ts#L39 it's not doing expensive stuff, so just create it per request.
Was this page helpful?