Drizzle ORM is a TypeScript-first ORM (Object-Relational Mapping) tool for SQL databases. It’s designed to be lightweight, fast, type-safe, and fully compatible with modern full-stack development in TypeScript and JavaScript environments.


πŸ”§ Key Features of Drizzle ORM

Feature Description
βœ… Type Safety Full TypeScript support with end-to-end types (schema, queries, results).
⚑ Performance Minimal abstraction for faster runtime and less overhead.
🧩 Modular Design Supports standalone use with libraries like Next.js, Express, or Bun.
πŸ“„ Schema as Code Schema definitions are written directly in TypeScript code.
πŸ’Ύ Migrations Built-in migration system with SQL-like syntax.
πŸ› οΈ Framework Agnostic Works with many backends: Next.js, Vite, Node, Bun, etc.

πŸ—„οΈ Supported Databases

  • PostgreSQL

  • MySQL

  • SQLite

  • Planetscale (via MySQL support)


🧱 Example: Define Schema

ts
// db/schema.ts
import { pgTable, serial, text, integer } from "drizzle-orm/pg-core";

export const users = pgTable("users", {
id: serial("id").primaryKey(),
name: text("name").notNull(),
age: integer("age"),
});


πŸ” Example: Querying

ts
import { db } from "./db"; // your drizzle client
import { users } from "./schema";

// Insert
await db.insert(users).values({ name: "Alice", age: 30 });

// Select
const result = await db.select().from(users);

// Filtered Query
const adults = await db
.select()
.from(users)
.where(users.age.gte(18));


πŸš€ Getting Started

1. Install

bash
npm install drizzle-orm drizzle-kit pg

2. Configure drizzle-kit

json
// drizzle.config.ts
export default {
schema: "./db/schema.ts",
out: "./drizzle",
driver: "pg",
dbCredentials: {
connectionString: "postgres://user:password@localhost:5432/mydb",
},
};

3. Run Migrations

bash
npx drizzle-kit push

🧠 When to Use Drizzle

  • You want type-safe SQL in a full-stack TypeScript app.

  • You’re using Next.js, Express, Bun, or other modern stacks.

  • You prefer defining schemas in code instead of via GUI or raw SQL files.