A great place to start are the NextJS docs on databases here.
“Let’s examine best practices for using databases in a serverless environment.” -Vercel
A must read on limiting connections here.
“A module for managing MySQL connections at serverless scale.”
serverless-mysql is a wrapper for the mysql module that adds connection management, async/await support and monitoring of number of connections.
“A wrapper for Doug Wilson’s amazing mysql Node.js module. Normally, using the mysql module with Node apps would be just fine. However, serverless functions (like AWS Lambda, Google Cloud Functions, and Azure Functions) scale almost infinitely by creating separate instances for each concurrent user. This is a MAJOR PROBLEM for RDBS solutions like MySQL, because available connections can be quickly maxed out by competing functions. Not anymore.”
The vercel “with-mysql” example uses prisma or planetscale or something, not what I was looking for.
Build from scratch.
I followed this post a bit here.
npm install mysql
npm install serverless-mysql