Transactions in nextjs 15 + Vercel with neon serverless driver
Ohio,
We use neon (paid) and drizzle in our deployed next 15 app deployed on vercel. Ive read the other posts pertaining to transactions and want some clarification:
In the following docs: https://github.com/neondatabase/serverless?tab=readme-ov-file#transaction it explains to either use the
Pool
or Client
when you want interactive transactions. My question is simply, do the Pool or Client methods have to be used from an vercel fn (what the examples in GitHub show)? Or can it also be used from a server action or API route as long as you manage the connection properly? We tend to use server actions for any mutations we perform in our APP that we don't need in our API. So when I say server action I mean just a fn:
And also, is this how a connection should look via drizzle-orm for transactions local to the server action/api route? For example if we're in a nextjs api route, do we need to give it any websocket configuration?
Any insight is greatly appreciated!!GitHub
GitHub - neondatabase/serverless: Connect to Neon PostgreSQL from s...
Connect to Neon PostgreSQL from serverless/worker/edge functions - neondatabase/serverless
2 Replies
genetic-orange•3w ago
You can absolutely use them from server actions yes!
And yes, the structure of your server actions looks good 🙂
absent-sapphireOP•2w ago
Ok cool, good to know, appreciate the response. Another question would be knowing when I would need to provide a websocket? In those docs for nodejs it says >v21, and in vercel I can see we're at v22. So I guess for route methods that are node I shouldn't need to provide a websocket to neon (which is great)