Skip to main content

Local development

Prisma Accelerate efficiently scales production traffic with integrated connection pooling and a global database cache.

In development environments, you may want to use a local database to minimize expenses. Furthermore, you may 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


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:

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

    npx prisma generate

    Note: The --no-engine flag should only be used in preview and production environments. The command generates Prisma Client artifacts without a Query Engine file, which requires an Accelerate connection string.

  3. Set up Prisma Client with the Accelerate client extension:

    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

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

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.