P
Prisma6mo ago
Sid

Prisma Accelerate for local NextJS development

I'm looking the example repo here: https://github.com/prisma/prisma-examples/tree/latest/accelerate/nextjs-starter And trying to see how I should set this up for offline local development. I like there's no conditional imports, and would like to keep it that way. My question is what should be the DATABASE_URL when using Accelerate in local development?
GitHub
prisma-examples/accelerate/nextjs-starter at latest · prisma/prism...
🚀 Ready-to-run Prisma example projects. Contribute to prisma/prisma-examples development by creating an account on GitHub.
2 Replies
Prisma AI Help
Prisma AI Help6mo ago
You selected the bot's instantaneous insights. Let me compile your answer right away! For local development with Next.js and Prisma Accelerate, you should not use a prisma:// Accelerate connection string as your DATABASE_URL. Accelerate does not work with a local database. Instead, set your DATABASE_URL to your local database connection string (e.g., for PostgreSQL: postgres://username:password@localhost:5432/dbname). You can still use the Accelerate client extension in your code—this will not provide Accelerate’s pooling/caching locally, but it allows you to avoid conditional imports and keep your code consistent between local and production environments. Example .env for local development:
DATABASE_URL="postgres://username:password@127.0.0.1:5432/localdb"
DATABASE_URL="postgres://username:password@127.0.0.1:5432/localdb"
And in your code:
import { PrismaClient } from '@prisma/client'
import { withAccelerate } from '@prisma/extension-accelerate'

const prisma = new PrismaClient().$extends(withAccelerate())
import { PrismaClient } from '@prisma/client'
import { withAccelerate } from '@prisma/extension-accelerate'

const prisma = new PrismaClient().$extends(withAccelerate())
This setup means that, locally, Prisma Client will connect directly to your local database, and the Accelerate extension will be loaded but not active. When you switch to production and use a prisma:// connection string, Accelerate will be enabled automatically—no code changes needed. Summary:
- Use a standard local database URL (not prisma://) for DATABASE_URL in local development. - You can keep the Accelerate extension in your code for both environments. See official guidance here.
Nurul
Nurul6mo ago
Hey! Did the bot answer help?

Did you find this page helpful?