Reusing db connection in lambda with Drizzle
I'm using rds mysql community as my DB and have been running into a connection limit problem when using server actions in Nextjs with prisma to interact with it(first image is the number of connections when I was burst testing), after searching a bit through the sst discord saw that someone recommended drizzle for better perfomance. When I looked through their docs I saw they mentioned a way to reuse the db connection: https://orm.drizzle.team/docs/perf-serverless
But through their example I found it hard to understand how it's being shared and if that would help with my connection limit problem
My connection looks like this:
And this is an example server action
Is there anything else I need to do so it can reuse the connection? Because just letting it like this isn't really working as you can see in the second image.
Drizzle ORM - next gen TypeScript ORM
Drizzle ORM is a lightweight and performant TypeScript ORM with developer experience in mind.
2 Replies
I've tried something closer to their example modifying the config like this:
And the action like this:
But had no success with the db connection limit still being reached
Also tried something more like this sst guide but no luck again
Guide: https://sst.dev/examples/how-to-use-mongodb-atlas-in-your-serverless-app.html
Code for the config:
SST
How to use MongoDB Atlas in your serverless app
In this example we will look at how to use MongoDB Atlas in your serverless app on AWS using SST. We'll be using the Api construct to create a simple API that gets a list of users.