Run Prisma queries through Neon’s serverless driver
Serverless Node.js or TypeScript application
Neon · Class
PrismaNeon is Neon’s Prisma driver adapter for serverless applications. Construct it with a Neon connection string and pass it to PrismaClient.
PrismaNeon adapts Neon’s serverless driver for Prisma Client. Construct it with the application connection string, then pass the adapter into PrismaClient so queries use Neon’s serverless-compatible connection path.
new PrismaNeon({ connectionString: process.env.DATABASE_URL })| Name | Type | Description |
|---|---|---|
options | object | Options object containing the Neon connection string. |
options.connectionString | string | Neon PostgreSQL connection URL used by the adapter. |
A PrismaNeon adapter instance for use with PrismaClient.
import 'dotenv/config';
import { PrismaNeon } from '@prisma/adapter-neon';
import { PrismaClient } from './generated/prisma/client';
const adapter = new PrismaNeon({
connectionString: process.env.DATABASE_URL
});
const prisma = new PrismaClient({ adapter });
const posts = await prisma.post.findMany();
console.log(posts);Creates Prisma Client with the Neon serverless driver adapter and queries posts.
Serverless Node.js or TypeScript application
Prisma application deployment
Schema management
PrismaNeon is the Prisma driver adapter for connecting Prisma ORM to Neon through the Neon serverless driver. Instantiate it with a connection string and provide it to PrismaClient.
Follow-up: Why should the application and Prisma CLI use different URLs? The application uses a pooled endpoint for runtime connections, while migrations and other schema operations require a direct endpoint.
Create PrismaNeon with the pooled DATABASE_URL, then pass the resulting adapter to PrismaClient. This lets application queries run through Neon’s serverless-compatible connection mechanism.
Follow-up: What must be configured for migrations? Supply DATABASE_URL_UNPOOLED as the direct connection in Prisma’s CLI configuration.
The application should use the pooled hostname containing the -pooler suffix. Prisma CLI commands such as migrations and introspection should use the direct, unpooled URL.
Follow-up: What problem does this separation avoid? It keeps schema-changing commands from going through the pooled connection layer.
@prisma/adapter-neon@prisma/clientPrisma ClientPrisma MigrateNeon serverless driverDATABASE_URLDATABASE_URL_UNPOOLEDprisma.config.ts