Overview

Drizzle ORM is an Object-Relational Mapper built specifically for TypeScript and JavaScript applications, launched in 2022. It distinguishes itself by offering a type-safe API that closely mirrors SQL, aiming to provide a lightweight alternative to more opinionated ORMs. The design philosophy of Drizzle ORM focuses on performance, minimal overhead, and a developer experience that integrates deeply with TypeScript's type system. This approach allows developers to write SQL-like queries while benefiting from compile-time type checking and auto-completion for database schemas, table names, and column types.

Drizzle ORM is well-suited for projects where type safety is a top priority and developers prefer to maintain a direct understanding of the underlying SQL queries. Its API is designed to be intuitive for those familiar with SQL, acting as a thin abstraction layer rather than a complete obfuscation of the database language. This makes it particularly effective for optimizing database interactions and debugging, as the generated SQL is often transparent and predictable. Drizzle ORM supports multiple relational databases, including PostgreSQL, MySQL, and SQLite, expanding its applicability across various project requirements and deployment environments.

The ORM is composed of two primary components: Drizzle ORM itself, which handles database interactions and query building, and Drizzle Kit, a companion tool for managing database schema migrations. Drizzle Kit facilitates schema definition directly from TypeScript, enabling developers to define their database structure using code and then generate migration files to apply changes. This combination simplifies the development workflow, ensuring that the application's schema remains synchronized with the database. The focus on a pragmatic, SQL-aware approach makes Drizzle ORM a strong candidate for modern web applications, particularly those leveraging serverless architectures where cold start times and bundle size are critical considerations.

For development teams evaluating ORM solutions, Drizzle ORM presents a compelling option when strict type safety, performance, and control over SQL are prioritized. Its lightweight footprint and open-source nature reduce project overhead and offer flexibility. Compared to more comprehensive ORMs, Drizzle ORM aims for a balance between abstraction and accessibility, allowing developers to optimize specific queries when needed without completely abandoning the benefits of an ORM. Its design principles are particularly beneficial in environments where transparent query generation and efficient resource utilization are paramount, such as in high-traffic APIs or microservices.

Key features

  • Type-Safe Query Builder: Provides a fluent, type-safe API for constructing SQL queries, leveraging TypeScript's inference capabilities to ensure correct column and table references at compile time. This helps prevent common runtime errors related to incorrect field names or data types.
  • Multi-Database Support: Offers adapters for PostgreSQL, MySQL, and SQLite, allowing developers to use the same ORM API across different relational database backends. This provides flexibility in database choice based on project needs (Drizzle ORM database support details).
  • Schema Migrations with Drizzle Kit: Includes a command-line tool, Drizzle Kit, for defining database schemas directly in TypeScript and generating migration files to manage database changes over time. This streamlines schema evolution alongside application code (Drizzle Kit migration documentation).
  • Lightweight and Performant: Designed with a focus on minimal overhead and efficient query generation, aiming for performance characteristics close to raw SQL. This makes it suitable for performance-critical applications and serverless functions.
  • Relations and Joins: Supports defining relationships between tables and performing complex joins, enabling efficient querying of related data. Developers can define one-to-one, one-to-many, and many-to-many relationships within their schema.
  • Prepared Statements: Utilizes prepared statements to enhance security against SQL injection attacks and improve query execution performance by pre-compiling query plans.
  • Serverless Compatibility: Optimized for serverless environments due to its small bundle size and efficient connection management, reducing cold start times and resource consumption.
  • Custom SQL Expressions: Allows for the embedding of raw SQL expressions within the type-safe query builder, providing an escape hatch for highly specialized or database-specific operations while retaining type safety where possible.

Pricing

Drizzle ORM is free and open source, available under the MIT License. There are no proprietary versions or paid tiers for its core functionality.

Product Pricing Model Details As of Date
Drizzle ORM Free and Open Source All features and components are freely available under the MIT License. 2026-06-21
Drizzle Kit Free and Open Source The schema migration tool is also freely available under the MIT License. 2026-06-21

Further details on Drizzle ORM's open-source licensing can be found on its official website, affirming its commitment to community-driven development (Drizzle ORM getting started guide).

Common integrations

  • Next.js: Drizzle ORM can be integrated with Next.js for full-stack TypeScript applications, managing database interactions for API routes and server components (Next.js integration guide).
  • PostgreSQL: Connects to PostgreSQL databases using various drivers, leveraging its type-safe query builder for robust data operations (PostgreSQL quick start).
  • MySQL: Supports MySQL databases, providing a consistent API for schema definition and query execution (MySQL getting started).
  • SQLite: Integrates with SQLite for local development, testing, and embedded database solutions, including support for technologies like better-sqlite3 (SQLite integration instructions).
  • PlanetScale: Can be used with PlanetScale's serverless database platform, particularly effective for serverless applications requiring scalable MySQL-compatible backend (PlanetScale quick start with Drizzle).
  • Vercel Postgres: Seamlessly integrates with Vercel's serverless PostgreSQL offering, ideal for deployments on the Vercel platform (Vercel Postgres integration details).
  • Bun: Compatible with the Bun JavaScript runtime, allowing developers to build and run Drizzle ORM applications with Bun's performance advantages (Bun quick start guide).
  • Astro: Works within Astro projects to handle server-side data fetching and manipulation, complementing Astro's island architecture (Astro Drizzle integration documentation).

Alternatives

  • Prisma: A comprehensive, modern ORM that generates a type-safe database client. Prisma offers a schema definition language and extensive tooling for migrations and database introspection (Prisma ORM homepage).
  • Kysely: A type-safe SQL query builder for TypeScript that focuses on providing a thin, yet powerful, layer over raw SQL without being a full ORM. Kysely is often compared to Drizzle for its SQL-centric approach (Kysely query builder website).
  • TypeORM: A popular ORM that supports multiple databases and offers features like Active Record and Data Mapper patterns. TypeORM provides a rich API for entity management and relationships, often appealing to developers familiar with ORMs like Hibernate or Entity Framework (TypeORM official documentation).
  • Sequelize: A well-established Node.js ORM that supports PostgreSQL, MySQL, MariaDB, SQLite, and SQL Server. Sequelize provides extensive features for migrations, associations, and hooks (Sequelize ORM project documentation).
  • Knex.js: A SQL query builder for Node.js that supports PostgreSQL, MySQL, SQLite3, and Oracle. While not a full ORM, Knex.js provides a programmatic way to build SQL queries, which can be extended with custom data mapping logic to achieve ORM-like functionality (Knex.js query builder usage guide).

Getting started

To get started with Drizzle ORM, you typically install the core package along with a database-specific driver. This example demonstrates setting up Drizzle ORM with a PostgreSQL database using the pg driver and defining a simple schema.

// 1. Install Drizzle ORM and a database driver (e.g., 'pg' for PostgreSQL)
// npm install drizzle-orm pg
// npm install --save-dev drizzle-kit ts-node

// 2. Define your schema in schema.ts
import { pgTable, serial, text, varchar } from 'drizzle-orm/pg-core';

export const users = pgTable('users', {
  id: serial('id').primaryKey(),
  fullName: text('full_name'),
  email: varchar('email', { length: 256 }).notNull().unique(),
});

export const products = pgTable('products', {
  id: serial('id').primaryKey(),
  name: varchar('name', { length: 256 }).notNull(),
  description: text('description'),
  price: text('price').notNull(),
});

// 3. Configure Drizzle Kit for migrations (drizzle.config.ts)
import type { Config } from 'drizzle-kit';

export default {
  schema: './schema.ts',
  out: './drizzle',
  driver: 'pg',
  dbCredentials: {
    connectionString: process.env.DATABASE_URL!,
  },
} satisfies Config;

// 4. Run migrations (e.g., using a script in package.json)
// "db:migrate": "drizzle-kit migrate"

// 5. Interact with the database (e.g., in index.ts)
import { drizzle } from 'drizzle-orm/node-postgres';
import { Client } from 'pg';
import * as schema from './schema';

async function main() {
  const client = new Client({
    connectionString: process.env.DATABASE_URL,
  });
  await client.connect();

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

  // Insert a new user
  const newUser = await db.insert(schema.users).values({
    fullName: 'Jane Doe',
    email: '[email protected]',
  }).returning();
  console.log('Inserted user:', newUser);

  // Select all users
  const allUsers = await db.query.users.findMany();
  console.log('All users:', allUsers);

  // Update a user
  if (newUser[0]) {
    const updatedUser = await db.update(schema.users)
      .set({ fullName: 'Jane A. Doe' })
      .where(eq(schema.users.id, newUser[0].id))
      .returning();
    console.log('Updated user:', updatedUser);
  }

  await client.end();
}

main().catch(console.error);

This example sets up a basic Drizzle ORM project. You define your database schema using Drizzle's helper functions, which are then used by Drizzle Kit to generate and apply migrations. The drizzle() function initializes the ORM client, which you then use to perform type-safe CRUD operations. Ensure your DATABASE_URL environment variable is correctly configured for your PostgreSQL instance.