Overview

Drizzle ORM is a TypeScript-first object-relational mapper that emphasizes performance, type safety, and a SQL-like developer experience. Founded in 2022, Drizzle ORM provides a thin layer over traditional SQL queries, allowing developers to write type-safe queries that closely resemble raw SQL while benefiting from TypeScript's static analysis features. This approach aims to reduce the learning curve for developers already familiar with SQL and minimize the overhead often associated with more opinionated ORMs.

Drizzle ORM is designed for projects that prioritize a lightweight footprint and efficient database interactions. It supports a range of relational databases, including PostgreSQL, MySQL, and SQLite, along with PlanetScale and Turso, and also has adapters for serverless environments. The ORM's architecture is built to be modular, allowing developers to use only the components necessary for their application, which can contribute to smaller bundle sizes and faster execution times, particularly in serverless functions where cold start times are a concern. Its explicit focus on type safety means that database schema changes are often reflected in compile-time errors, helping to prevent runtime issues and improve code maintainability.

Developers using Drizzle ORM can define their database schemas entirely in TypeScript, and then use Drizzle Kit to generate SQL migrations. The ORM's query builder allows for complex queries, including joins, aggregations, and subqueries, all while maintaining end-to-end type safety from the database to the application code. This makes it a suitable choice for modern web applications, APIs, and microservices where TypeScript is a primary language and performance is critical. For instance, developers building applications with frameworks like Next.js or SvelteKit can integrate Drizzle ORM to manage their data layer efficiently, ensuring that their database interactions are type-checked and optimized.

Key features

  • Type-Safe Query Builder: Offers a fluent API for constructing database queries with full TypeScript inference, providing compile-time safety for queries and results, as described in the Drizzle ORM documentation.
  • SQL-like Syntax: Designed to feel similar to writing raw SQL, making it accessible for developers familiar with database query languages.
  • Multi-Database Support: Compatible with PostgreSQL, MySQL, SQLite, and serverless databases like PlanetScale and Turso.
  • Drizzle Kit for Migrations: A CLI tool that generates SQL migrations based on TypeScript schema definitions, facilitating database schema evolution.
  • Lightweight Footprint: Engineered for minimal overhead and bundle size, making it suitable for performance-sensitive applications and serverless functions.
  • Schema Definition in TypeScript: Define database tables and relationships directly in TypeScript, enabling type checking throughout the data layer.
  • Prepared Statements: Supports prepared statements for improved performance and protection against SQL injection vulnerabilities.
  • Relation Inferences: Automatically infers relationships between tables, simplifying join operations and data fetching.
  • Transactions: Provides robust transaction management for ensuring data consistency during complex operations.

Pricing

Drizzle ORM is a free and open-source project. There are no licensing fees, subscriptions, or commercial editions for its core features.

Offering Cost Details As of Date
Drizzle ORM & Drizzle Kit Free Fully open-source under the MIT License. All features available without cost. 2026-06-26

For more details on Drizzle ORM's open-source status, refer to the project's official homepage.

Common integrations

  • Next.js: Often used with Next.js for building full-stack applications, leveraging Drizzle's type safety for database interactions in API routes and server components. Official guidance on database integration with Next.js is available on the Next.js data fetching documentation.
  • SvelteKit: Integrates with SvelteKit applications to provide a type-safe data layer for endpoints and server-side logic.
  • React: Can be used with React applications, typically via a backend API layer built with Node.js and a framework like Express or NestJS, where Drizzle manages database access.
  • PostgreSQL: Direct support and dedicated drivers for interacting with PostgreSQL databases.
  • MySQL: Provides adapters for MySQL and compatible databases like PlanetScale.
  • SQLite: Supports SQLite for local development, testing, and embedded database scenarios.
  • Serverless Functions: Optimized for use in serverless environments such as AWS Lambda, Google Cloud Functions, or Vercel Edge Functions due to its lightweight nature.

Alternatives

  • Prisma: A next-generation ORM that offers a comprehensive toolkit for database access, migrations, and schema management with a focus on type safety and developer experience.
  • Kysely: A type-safe SQL query builder for TypeScript, providing a more raw SQL experience than Drizzle while retaining strong type inference.
  • TypeORM: An ORM that supports multiple databases and provides features like Active Record and Data Mapper patterns, often used in TypeScript projects.
  • Sequelize: A promise-based Node.js ORM for Postgres, MySQL, MariaDB, SQLite and SQL Server, known for its stability and extensive feature set.
  • Knex.js: A flexible SQL query builder, often used as a foundation for custom data access layers or in conjunction with other ORMs.

Getting started

To begin using Drizzle ORM, you'll typically set up your database schema and then write queries. Below is a minimal example demonstrating how to define a schema, connect to a database (using a generic adapter), and perform a simple insert and select operation.

First, install Drizzle ORM and a database driver (e.g., pg for PostgreSQL or mysql2 for MySQL) along with drizzle-kit:

npm install drizzle-orm pg
npm install -D drizzle-kit typescript @types/node

Next, define your schema in a TypeScript file (e.g., src/schema.ts):

import { pgTable, serial, text, varchar } from 'drizzle-orm/pg';

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

Then, create a Drizzle configuration file (e.g., drizzle.config.ts):

import { defineConfig } from 'drizzle-kit';

export default defineConfig({
  schema: './src/schema.ts',
  out: './drizzle',
  driver: 'pg',
  dbCredentials: {
    connectionString: process.env.DATABASE_URL!,
  },
});

Now, you can generate a migration using Drizzle Kit:

npx drizzle-kit generate

Finally, write your application code to interact with the database (e.g., src/index.ts):

import { drizzle } from 'drizzle-orm/pg';
import { Client } from 'pg';
import { users } from './schema';
import { eq } from 'drizzle-orm';

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

  const db = drizzle(client);

  // Insert a new user
  const insertedUsers = await db.insert(users).values({ fullName: 'Alice Smith', email: '[email protected]' }).returning();
  console.log('Inserted user:', insertedUsers[0]);

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

  // Select a user by ID
  const userById = await db.select().from(users).where(eq(users.id, insertedUsers[0].id));
  console.log('User by ID:', userById[0]);

  await client.end();
}

main().catch(console.error);

Replace process.env.DATABASE_URL with your actual database connection string. This example provides a basic workflow to get started with Drizzle ORM for database schema definition and data manipulation.