Skip to main content
Prisma Documentation Docs
current

Search documentation

Type to search this documentation.

On this pageOverview

Supabase with Accelerate (Prisma ORM v7)

Learn how to set up PostgreSQL on Supabase with Prisma Accelerate's Connection Pool

This guides teaches you how to add connection pooling to a PostgreSQL database hosted on Supabase using Prisma Accelerate.

Prisma Accelerate is a connection pooler that keeps your database within its connection limits during traffic spikes and high load. Check out this video demonstrating how it performs in a load test or learn why connection pooling is important.

Set up Supabase with Prisma Accelerate connection pooling

To successfully complete this guide, you need a connection string for a PostgreSQL instance hosted on Supabase. It typically looks similar to this:

no-copy
postgresql://postgres:[YOUR-PASSWORD]@db.nzpppscrldfwlzfalbrf.supabase.co:5432/postgres

If you already have a project using Prisma ORM, you can skip the first two steps and jump ahead to Step 3. Install the Accelerate extension.

Start by installing the Prisma CLI in your project:

bun
bun add prisma@prev --dev
pnpm
pnpm add prisma@prev --save-dev
yarn
yarn add prisma@prev --dev
npm
npm install prisma@prev --save-dev

Then, run the following command to initialize a new project:

bun
bunx --bun prisma init
pnpm
pnpm prisma init
yarn
yarn prisma init
npm
npx prisma init

This will create a new prisma directory with a schema.prisma file and add a .env file with the DATABASE_URL environment variable.

Update the file and set the DATABASE_URL to your Supabase connection string:

.env
DATABASE_URL="postgresql://postgres:[YOUR-PASSWORD]@db.nzpppscrldfwlzfalbrf.supabase.co:5432/postgres"

Create a prisma.config.ts file to configure Prisma:

prisma.config.ts
import "dotenv/config";
import { defineConfig, env } from "prisma/config";

export default defineConfig({
  schema: "prisma/schema.prisma",
  migrations: {
    path: "prisma/migrations",
  },
  datasource: {
    url: env("DATABASE_URL"),
  },
});
```bash
bun add dotenv
```
```bash
pnpm add dotenv
```
```bash
yarn add dotenv
```
```bash
npm install dotenv
```

Next, run the following command to introspect your database and create your data model:

bun
bunx prisma db pull
pnpm
pnpm prisma db pull
yarn
yarn prisma db pull
npm
npx prisma db pull

This command reads your database schema and creates new models in your schema.prisma file that match the tables in your database.

Install the Prisma Client extension for Accelerate:

bun
bun add @prisma/extension-accelerate
pnpm
pnpm add @prisma/extension-accelerate
yarn
yarn add @prisma/extension-accelerate
npm
npm install @prisma/extension-accelerate

This is needed to access Prisma Accelerate's connection pool.

To set up Accelerate in the Prisma Console, follow these steps:

  1. Log into the Prisma Console.
  2. Select New project
  3. Choose a Name for your project
  4. In the Choose your starting product section, find the Accelerate card and click Get started
  5. In the field for your Database connection string, paste your Supabase connection string
  6. Select the Region that's closest to your database
  7. Click Create project
  8. On the next screen, click Enable Accelerate

Once you went through these steps, you'll be redirected to another page where you need to the click the Generate API key button.

You'll then be shown a new connection URL which enables you to connect to Prisma Accelerate's connection pool. This needs to be set as the new DATABASE_URL in your .env file:

.env
DATABASE_URL="prisma://accelerate.prisma-data.net/?api_key=ey..."

With your Prisma schema in place, generate Prisma Client:

bun
bunx prisma generate
pnpm
pnpm prisma generate
yarn
yarn prisma generate
npm
npx prisma generate

In your application code, you now need to apply the Accelerate extension to your Prisma Client instance:

TypeScript
import { PrismaClient } from "./generated/prisma/client";
import { withAccelerate } from "@prisma/extension-accelerate";

const prisma = new PrismaClient({
  accelerateUrl: process.env.DATABASE_URL,
}).$extends(withAccelerate());

At this point, you can now start sending queries which will be routed through the connection pool to your database.

Suggest an edit

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

Export
Documentation menu