N
Neon13mo ago
other-emerald

Nextjs server actions: best way to connect?

Hi, sorry for this question as I'm a complete beginner. As I was going through the docs, I noticed there's nothing about setting up a global variable to initiate a connection pool (like you would with PrismaClient()) and then reusing it throughout your logic. Do I need to use const sql = neon(process.env.DATABASE_URL) in every server action where I want to interact with the database? It seems to me this would open a new connection each time, so I’m wondering if there’s a better way to handle this.
1 Reply
xenophobic-harlequin
xenophobic-harlequin13mo ago
GitHub
GitHub - leerob/next-saas-starter: Get started quickly with Next.js...
Get started quickly with Next.js, Postgres, Stripe, and shadcn/ui. - leerob/next-saas-starter
GitHub
next-saas-starter/lib/db/drizzle.ts at 8a275038ea1175ba4befe37d4f27...
Get started quickly with Next.js, Postgres, Stripe, and shadcn/ui. - leerob/next-saas-starter

Did you find this page helpful?