Skip to main content
Prisma Documentation Docs
current

Search documentation

Type to search this documentation.

On this pageOverview

Local development

Learn how to use Prisma Accelerate in a development environment

Prisma Accelerate provides connection pooling and a global database cache for production traffic.

In development environments, you may want to use a local database to minimize expenses. You may also consider extending Prisma Client with the Accelerate client extension once so that you can use a local database in development and a hosted database with Accelerate's connection pooling and caching enabled. This eliminates the need for conditional logic to switch clients between development and production.

This guide will explain how to use Prisma Accelerate client extension in a development environment with a local database.

Using Prisma Accelerate client extension in development and production

Section titled “Using Prisma Accelerate client extension in development and production”
Using Prisma Accelerate client extension in development

Accelerate does not work with a local database. However, in a development environment, you can still use Prisma Client with the Accelerate client extension. This setup will not provide Accelerate's connection pooling and caching features.

The following steps outline how to use Prisma ORM and Prisma Accelerate with a local PostgreSQL database.

  1. Update the DATABASE_URL environment variable with your local database's connection string:

    Bash
    DATABASE_URL="postgres://username:password@127.0.0.1:5432/localdb"
  2. Generate a Prisma Client:

bun
bunx prisma generate
pnpm
pnpm prisma generate
yarn
yarn prisma generate
npm
npx prisma generate
  1. Set up Prisma Client with the Accelerate client extension:

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

    The extended instance of Prisma Client will use the local database. Hence, Prisma Accelerate will not be used in your development environment to respond to your Prisma Client queries.

Using Prisma Accelerate client extension in production

If an Accelerate connection string is used as the DATABASE_URL environment variable, Prisma Client will route your queries through Accelerate.

Using Prisma Accelerate locally in an edge function

Section titled “Using Prisma Accelerate locally in an edge function”

When using an edge function, e.g., Vercel's edge runtime, for your development environment, update your Prisma Client import as follows:

TypeScript
import { PrismaClient } from "@prisma/client/edge";

Generally, edge function environments lack native support for existing APIs enabling TCP-based database connections. Prisma Accelerate provides a connection string that allows querying your database over HTTP, a protocol supported in all edge runtimes.

Suggest an edit

Propose a replacement for this page. The site team reviews it before applying any changes.

Export
Documentation menu