Skip to main content

Database Drivers

Drizzle ORM supports a wide range of database drivers across PostgreSQL, MySQL, and SQLite. Each driver is optimized for specific use cases and deployment environments.

Driver Categories

PostgreSQL Drivers

Drizzle supports multiple PostgreSQL drivers, each optimized for different environments:

node-postgres (pg)

Traditional Node.js driver with connection pooling

postgres.js

Modern, fast PostgreSQL driver for Node.js

Neon Serverless

WebSocket-based driver for Neon serverless databases

Neon HTTP

HTTP-based driver for edge environments

Vercel Postgres

Optimized driver for Vercel deployments

MySQL Drivers

MySQL and MySQL-compatible database drivers:

mysql2

Fast MySQL driver for Node.js with prepared statements

PlanetScale

Serverless driver for PlanetScale databases

SQLite Drivers

SQLite drivers for various JavaScript runtimes:

better-sqlite3

Synchronous SQLite driver for Node.js

libSQL

Driver for Turso and local SQLite databases

Cloudflare D1

SQLite driver for Cloudflare Workers

Common Configuration Options

All Drizzle drivers support a consistent configuration API:

Schema

Pass your schema to enable relational queries:
import { drizzle } from 'drizzle-orm/[driver]';
import * as schema from './schema';

const db = drizzle(client, { schema });

Logger

Enable query logging for debugging:
// Enable default logger
const db = drizzle(client, { logger: true });

// Custom logger
const db = drizzle(client, {
  logger: {
    logQuery(query, params) {
      console.log({ query, params });
    },
  },
});

Casing

Automatically convert between database and JavaScript naming conventions:
const db = drizzle(client, {
  casing: 'snake_case', // Convert camelCase to snake_case
});

Cache

Enable query result caching:
import { caching } from 'drizzle-orm';

const db = drizzle(client, {
  cache: caching({
    ttl: 60_000, // 60 seconds
  }),
});

Connection Methods

Drizzle supports multiple ways to initialize database connections:

Method 1: Pass existing client

import { drizzle } from 'drizzle-orm/[driver]';
import { Client } from '[driver-package]';

const client = new Client({
  // connection options
});

const db = drizzle(client);

Method 2: Connection string

const db = drizzle('postgres://user:password@host:port/database');

Method 3: Configuration object

const db = drizzle({
  connection: {
    host: 'localhost',
    port: 5432,
    user: 'postgres',
    password: 'password',
    database: 'mydb',
  },
  schema,
  logger: true,
});

Environment-Specific Recommendations

Serverless (Edge)

  • PostgreSQL: Neon HTTP, Vercel Postgres
  • MySQL: PlanetScale Serverless
  • SQLite: Cloudflare D1, Turso (libSQL)

Traditional Node.js

  • PostgreSQL: node-postgres, postgres.js
  • MySQL: mysql2
  • SQLite: better-sqlite3

Long-Running Servers

  • PostgreSQL: node-postgres with connection pooling
  • MySQL: mysql2 with connection pooling
  • SQLite: better-sqlite3

Next Steps

PostgreSQL

Learn about PostgreSQL drivers

MySQL

Learn about MySQL drivers

SQLite

Learn about SQLite drivers

Build docs developers (and LLMs) love