Native PostgreSQL integration
Use PostgreSQL through the native pg JavaScript driver while retaining Prisma Client's query API.
Prisma · Const
driverAdapters is a Prisma Client preview feature for using JavaScript database drivers through driver adapters. Adapters translate Prisma queries for supported database or serverless drivers.
The driverAdapters preview feature lets Prisma Client use a JavaScript database driver through an adapter. The adapter translates between Prisma Client and that driver; Prisma still turns client queries into SQL, while the adapter-backed driver sends those queries to the database.
previewFeatures = ["driverAdapters"]| Name | Type | Description |
|---|---|---|
adapter | DriverAdapter | An adapter instance implementing the database-driver integration used by Prisma Client. |
generator client {
provider = "prisma-client-js"
previewFeatures = ["driverAdapters"]
}
// npm install @prisma/adapter-pg
import { PrismaClient } from "./generated/prisma";
import { PrismaPg } from "@prisma/adapter-pg";
const adapter = new PrismaPg({
connectionString: process.env.DATABASE_URL!,
});
const prisma = new PrismaClient({ adapter });
const users = await prisma.user.findMany();
console.log(users);Enable the preview feature, create a PostgreSQL adapter with the connection string, and pass it to PrismaClient.
Use PostgreSQL through the native pg JavaScript driver while retaining Prisma Client's query API.
Connect Prisma to a database through a driver designed for serverless or edge deployment.
Integrate a database driver for which Prisma does not provide a maintained adapter.
driverAdapters preview feature provide?driverAdapters enables Prisma Client to work with JavaScript database drivers through adapter objects. The adapter translates between Prisma Client and the selected driver, which executes the generated SQL against the database.
Follow-up: Why might an application choose an adapter? It can use a supported native JavaScript driver, including drivers suited to serverless environments, instead of relying exclusively on Prisma's built-in connection path.
Create the database-specific adapter, configure it with the connection details, and pass it to new PrismaClient({ adapter }). The PostgreSQL example uses PrismaPg from @prisma/adapter-pg.
Follow-up: Where should the connection string be configured? In application code when the adapter is initialized, because adapter-based connections require it there.
The documentation distinguishes database driver adapters from serverless driver adapters. Prisma maintains adapters for several drivers, and developers can also build an adapter for another database driver.
Follow-up: What is the role of a community adapter? It extends the same integration approach to drivers or platforms not maintained directly by Prisma.
queryCompilerPrismaClientPrismaPg@prisma/adapter-pgserverless driver adaptersdatabase driver adapters