PostgreSQL Drivers
Drizzle ORM supports multiple PostgreSQL drivers, each optimized for different deployment environments and use cases.node-postgres (pg)
The traditional PostgreSQL driver for Node.js with robust connection pooling.Installation
Basic Usage
Connection Pool Configuration
Accessing the Client
postgres.js
A modern, fast PostgreSQL driver with excellent TypeScript support.Installation
Basic Usage
Advanced Options
postgres.js automatically handles date parsing. Drizzle overrides default parsers to return raw values for consistent date handling.
Neon Serverless
WebSocket-based PostgreSQL driver optimized for Neon’s serverless databases.Installation
Basic Usage
With WebSocket Polyfill
Required for environments without native WebSocket support:Neon HTTP
HTTP-based PostgreSQL driver for edge environments and serverless functions.Installation
Basic Usage
Advanced Options
Row-Level Security with Auth Token
Batch Queries
Vercel Postgres
Optimized PostgreSQL driver for Vercel deployments.Installation
Basic Usage
Environment Variables
Vercel automatically provides these environment variables:Vercel Edge Functions
Choosing a Driver
- Node.js Servers
- Serverless
- Edge Runtime
Recommended: node-postgres or postgres.js
- Connection pooling for optimal performance
- Battle-tested in production environments
- Full PostgreSQL feature support
Mock Database for Testing
All drivers support creating mock instances for testing:Mock databases are useful for unit testing query builders but don’t execute actual SQL.