Overview
Drizzle supports multiple database drivers and connection methods. Choose the driver that matches your runtime environment and database.PostgreSQL
node-postgres (pg)
The standard PostgreSQL driver for Node.js:1
Install dependencies
2
Create connection
3
Use connection string
Postgres.js
A lightweight PostgreSQL driver:Neon Serverless
For Neon’s serverless PostgreSQL:Vercel Postgres
Optimized for Vercel deployments:MySQL
mysql2
The MySQL driver with prepared statement support:1
Install dependencies
2
Create connection
3
Configure mode
The
mode parameter is required when providing a schema. Use 'planetscale' for databases without foreign key support, or 'default' for standard MySQL.PlanetScale Serverless
SQLite
better-sqlite3
Synchronous SQLite driver for Node.js:Bun SQLite
Native SQLite for Bun runtime:libSQL (Turso)
For distributed SQLite:Configuration Options
Logger
Enable SQL query logging:Schema
Providing your schema enables the relational query API:Casing
Configure column name conversion:Connection Patterns
Singleton Pattern
Create a single database instance:db.ts
Connection Pooling
Configure pool settings for optimal performance:Read Replicas
Distribute read queries across replicas:Environment Variables
Store connection strings securely:.env
TypeScript Types
The database instance is fully typed:Best Practices
- Use connection pooling: Especially for serverless and high-traffic applications
- Close connections: Implement graceful shutdown to close database connections
- Environment variables: Never hardcode credentials
- Schema parameter: Include schema for type-safe relational queries
- Logging: Enable in development, disable in production for performance
Next Steps
Queries
Learn how to query your database
Migrations
Set up database migrations