© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Drizzle TeamDT
Drizzle Team•3y ago•
2 replies
lutefd

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:
const connection = await mysql.createConnection({
  host: env.MYSQL_HOST,
  user: env.MYSQL_USER,
  port: 3306,
  password: env.MYSQL_PASSWORD,
  database: env.MYSQL_DATABASE,
});

export const db = drizzle(connection, {
  schema: myschema,
  mode: "default",
});
const connection = await mysql.createConnection({
  host: env.MYSQL_HOST,
  user: env.MYSQL_USER,
  port: 3306,
  password: env.MYSQL_PASSWORD,
  database: env.MYSQL_DATABASE,
});

export const db = drizzle(connection, {
  schema: myschema,
  mode: "default",
});

And this is an example server action
"use server";

import { db } from "@/server/db";

export const getPosts = async () => {
  const posts = await db.query.posts.findMany();
  return posts;
};
"use server";

import { db } from "@/server/db";

export const getPosts = async () => {
  const posts = await db.query.posts.findMany();
  return posts;
};

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.
image.png
image.png
Drizzle ORM - next gen TypeScript ORM
Drizzle ORM is a lightweight and performant TypeScript ORM with developer experience in mind.
Drizzle TeamJoin
The official Discord for all Drizzle related projects, such as Drizzle ORM, Drizzle Kit, Drizzle Studio and more!
11,879Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

Connection management with Drizzle
Drizzle TeamDTDrizzle Team / help
12mo ago
[Error] Using Drizzle with Neon DB
Drizzle TeamDTDrizzle Team / help
3y ago
db variable bug in drizzle runner
Drizzle TeamDTDrizzle Team / help
2y ago
DB connections hangs after successful execution in Lambda locally
Drizzle TeamDTDrizzle Team / help
3y ago