Instantiate a connection with PlanetScale in Cloudflare Workers
Hey,
What would be the right way to instantiate a database connection with PlanetScale in Cloudflare workers and reuse it across different handlers?
We cannot instantiate it outside the handler because we have no access to the environment variables :
So, we need to create a function where we can pass the env object as a parameter to access the environment variables:
And then use it in different handlers:
I wonder if this is a safe way to instantiate a connection and reuse it across different handlers with Cloudflare Workers?
1 Reply
It's fine I guess. You can also have some sort of singleton pattern for that