Skip to main content

Database drivers

Default built-in drivers

One of Prisma Client's components is the Query Engine. The Query Engine is responsible for transforming Prisma Client queries into SQL statements. It connects to your database via TCP using built-in drivers that don't require additional setup.

Query flow from the user application to the database with Prisma Client

Driver adapters

Prisma Client can connect and run queries against your database using JavaScript database drivers using driver adapters. Adapters act as translators between Prisma Client and the JavaScript database driver.

Prisma Client will use the Query Engine to transform the Prisma Client query to SQL and run the generated SQL queries via the JavaScript database driver.

Query flow from the user application to the database using Prisma Client and driver adapters

There are two different types of driver adapters:

Note: Driver adapters enable edge deployments of applications that use Prisma ORM.

Database driver adapters

You can connect to your database using a Node.js-based driver from Prisma Client using a database driver adapter. Prisma maintains the following database driver adapters:

Serverless driver adapters

Database providers, such as Neon and PlanetScale, allow you to connect to your database using other protocols besides TCP, such as HTTP and WebSockets. These database drivers are optimized for connecting to your database in serverless and edge environments.

Prisma ORM maintains the following serverless driver adapters:

Community-maintained database driver adapters

You can also build your own driver adapter for the database you're using. The following is a list of community-maintained driver adapters:

How to use driver adapters

To use this feature:

  1. Update the previewFeatures block in your schema to include the driverAdapters Preview feature:

    generator client {
    provider = "prisma-client-js"
    previewFeatures = ["driverAdapters"]
    }
  2. Generate Prisma Client:

    npx prisma generate
  3. Refer to the following pages to learn more about how to use the specific driver adapters with the specific database providers:

Notes about using driver adapters

Driver adapters don't read the connection string from the Prisma schema

When using Prisma ORM's built-in drivers, the connection string is read from the url field of the datasource block in your Prisma schema.

On the other hand, when using a driver adapter, the connection string needs to be provided in your application code when the driver adapter is set up initially. Here is how this is done for the pg driver and the @prisma/adapter-pg adapter:

import { PrismaClient } from '@prisma/client'
import { PrismaPg } from '@prisma/adapter-pg'
import { Pool } from 'pg'

const pool = new Pool({ connectionString: env.DATABASE_URL })
const adapter = new PrismaPg(pool)
const prisma = new PrismaClient({ adapter })

See the docs for the driver adapter you're using for concrete setup instructions.

Driver adapters and custom output paths

Since Prisma 5.9.0, when using the driver adapters Preview feature along with a custom output path for Prisma Client, you cannot reference Prisma Client using a relative path.

Let's assume you had output in your Prisma schema set to ../src/generated/client:

generator client {
provider = "prisma-client-js"
output = "../src/generated/client"
}

What you should not do is reference that path relatively:

// what not to do!
import { PrismaClient } from './src/generated/client'

const client = new PrismaClient()

Instead, you will need to use a linked dependency.

npm add db@./src/generated/client

Now, you should be able to reference your generated client using db!

import { PrismaClient } from 'db'

const client = new PrismaClient()

Driver adapters and specific frameworks

Nuxt

Using a driver adapter with Nuxt to deploy to an edge function environment does not work out of the box, but adding the nitro.experimental.wasm configuration option fixes that:

export default defineNuxtConfig({
// ...
nitro: {
// ...
experimental: {
wasm: true,
},
},
// ...
})

See this example project for a full example that can be deployed to Cloudflare Pages.