First off, shoutout to all RW contributors. Y’all have a community post or guide for just about every problem I encountered that I couldn’t reason through.
I saw Danny’s older post starting a couple years back about connection pooling, but I am getting some clarification from the RW community here between Data Proxy, Accelerate, and Pulse as well as help with my first foray into connection pooling.
I knew from our last busy season that I might need to look into connection pooling from a few times I hit connection limits (I have been using Redwood on Vercel and Netlify since v1 now).
I started by perusing the Connection Pooling Guide a month or so ago here: [Connection Pooling | RedwoodJS Docs](https://Connection Pooling)
However, I noticed the Prisma site seemed to be updating information on the Data Proxy and sure enough I see Prisma on the last Redwood Partner Talks with Accelerate and Pulse.
Am I mistaken in saying that Accelerate will be what the original Data Proxy was for connection pooling and then Pulse will be real-time events triggered by the db?
So to get as far as I did let’s walkthrough what I already did to help other catch up:
I dove in with a v6.0 Redwood project (need Prisma v5) using the [Prisma Accelerator Docs] (Getting started with Accelerate)
I decided to dive on in so let’s catch people up to where I got to with Accelerate.
I needed to sign up for Prisma’s Cloud Platform with Github:
Prisma Cloud Platform
You’ll be shuttled to the dashboard for the Cloud Platform:
Create a “New Cloud Project” on the Dashboard:
Enable Accelerate:
You’ll need your old DB connection string, and to choose a location close to your DB:
Click Generate API Key:
Copy the new connection string, this will be your project’s new DATABASE_URL.
This will be used to update your .env file. Your DATABASE_URL is now the accelerate URL generated, and the DIRECT_DATABASE_URL is the old connection string that was DATABASE_URL:
# .env
DATABASE_URL="prisma://accelerate.prisma-data.net/?api_key=__API_KEY__"
DIRECT_DATABASE_URL="postgresql://user:password@host:port/db_name?schema=public"
You’ll also need to update the schema.prisma file to have a “directUrl” so that some of the Prisma functionality can still work not through the proxy:
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
directUrl = env("DIRECT_DATABASE_URL")
}
Instead of the suggested npm use yarn to add the Prisma Client Extension:
yarn add @prisma/extension-accelerate
then:
yarn rw prisma generate --accelerate
***I Initially had this wrong as ‘npx prisma generate’ like prisma docs show
After that I needed to updated the db.js file in api/src/lib/db.js.
This is where I had some trouble. I couldn’t get logging working.
My code before has this:
export const db = new PrismaClient({
log: emitLogLevels(['info', 'warn', 'error']),
})
I was able to get Accelerate working without logging by changing the db line to:
export const db = new PrismaClient().$extends(withAccelerate())
However, logging seems to be breaking if I do:
export const db = new PrismaClient({
log: emitLogLevels(['info', 'warn', 'error']),
}).$extends(withAccelerate())
With the following error:
Is the logging here technically a middleware? Prisma gives this heads-up as part of the Accelerate Docs:
“If you are using Prisma Middleware in your application, make sure they are added before any Prisma Client extensions (like Accelerate). For example:”
const prisma = new PrismaClient().$use(middleware).$extends(withAccelerate())
Anyways thought I’d share where I got to with Accelerate and what looks to be the new Prisma Connection Pooling
Btw: I am on Redwood 6.0.0-rc.662 and Prisma 5.0.0. I know Prisma has a 5.1 that I can upgrade to, but wanted to see where I got with what’s just on v6.0 baked -in.