Become a Gold Sponsor

Drizzle extension for Prisma

If you have an existing project with Prisma and want to try Drizzle or gradually adopt it, you can use our first-class extension that will add Drizzle API to your Prisma client. It will allow you to use Drizzle alongside your Prisma queries reusing your existing DB connection.

How to use

Install dependencies

You need to install Drizzle itself and a generator package that will create Drizzle schema from the Prisma schema.

npm
yarn
pnpm
bun
npm i drizzle-orm@latest
npm i -D drizzle-prisma-generator

Update your Prisma schema

Add Drizzle generator to your Prisma schema. output is the path where generated Drizzle schema TS files will be placed.

schema.prisma
generator client {
  provider = "prisma-client-js"
}

generator drizzle {
  provider = "drizzle-prisma-generator"
  output   = "./drizzle" // Where to put generated Drizle tables
}

// Rest of your Prisma schema

datasource db {
  provider = "postgresql"
  url      = env("DB_URL")
}

model User {
  id    Int     @id @default(autoincrement())
  email String  @unique
  name  String?
}

...

Generate Drizzle schema

prisma generate

Add Drizzle extension to your Prisma client

PostgreSQL
MySQL
SQLite
import { PrismaClient } from '@prisma/client';
import { drizzle } from 'drizzle-orm/prisma/pg';

const prisma = new PrismaClient().$extends(drizzle());

Run Drizzle queries via prisma.$drizzle

In order to use Drizzle query builder, you need references to Drizzle tables. You can import them from the output path that you specified in the generator config.

import { User } from './drizzle';

await prisma.$drizzle.insert().into(User).values({ email: '[email protected]', name: 'Søren' });
const users = await prisma.$drizzle.select().from(User);

Limitations