Run application queries through the pooled Neon endpoint
Serverless Node.js or TypeScript application queries
Neon · Const
Connect Prisma ORM to Neon with @prisma/adapter-neon. Use a pooled URL for application queries and a direct URL for Prisma CLI operations such as migrations and schema pushes.
Prisma connects to Neon through @prisma/adapter-neon, which uses Neon's serverless driver and WebSockets. Configure a pooled connection for application queries and a direct connection for Prisma CLI operations such as migrations and schema pushes.
new PrismaNeon({ connectionString: process.env.DATABASE_URL });
new PrismaClient({ adapter });A configured PrismaClient instance that executes Prisma queries against Neon.
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);This creates Prisma Client with Neon's adapter and uses the pooled application connection to query the database.
Serverless Node.js or TypeScript application queries
Database schema management
Type-safe data access
Install @prisma/client, @prisma/adapter-neon, and the matching Prisma packages. Construct PrismaNeon with the application connection string, then pass that adapter to PrismaClient.
Follow-up: Why use two URLs? The pooled URL is designed for application traffic, while the direct URL is used by Prisma CLI operations.
The pooled URL contains -pooler in the hostname and is assigned to DATABASE_URL. DATABASE_URL_UNPOOLED contains the direct endpoint and is used by Prisma CLI commands such as migrations and db push.
Follow-up: What should be checked if CLI operations fail? Verify that the CLI is configured with DATABASE_URL_UNPOOLED rather than the pooled URL.
PrismaNeon is the driver adapter that connects Prisma Client through Neon's serverless driver. After configuring the adapter, normal Prisma queries can be executed through the generated client.
Follow-up: How can schema changes be applied? Generate the client, then use Prisma CLI commands such as prisma db push or migrations with the direct connection configured.
@prisma/adapter-neonPrismaNeonPrismaClientDATABASE_URLDATABASE_URL_UNPOOLEDprisma.config.tsprisma/schema.prismanpx prisma generate