Cette page est affichée en anglais. Une traduction française est en cours.
ScriptsApr 6, 2026·2 min de lecture

Drizzle ORM — TypeScript SQL That Feels Like Code

Type-safe TypeScript ORM with SQL-like syntax. Zero overhead, serverless-ready, supports PostgreSQL, MySQL, SQLite. Schema as code with automatic migrations. 28,000+ GitHub stars.

Introduction

Drizzle ORM is a type-safe TypeScript ORM with SQL-like syntax and zero abstraction overhead with 28,000+ GitHub stars. Unlike Prisma which generates a client from a schema file, Drizzle lets you write queries that look and feel like SQL while maintaining full TypeScript type safety. Serverless-ready with no connection pooling issues, supports PostgreSQL, MySQL, and SQLite. Best for TypeScript developers who know SQL and want type safety without the ORM magic. Works with: any Node.js/Bun/Deno project. Setup time: under 3 minutes.


Why Drizzle Over Prisma

Feature Drizzle Prisma
Query syntax SQL-like Custom API
Schema TypeScript code .prisma file
Bundle size 7.4KB 800KB+
Serverless Native Needs adapter
Migrations Auto from schema diff Separate CLI
Learning curve Know SQL = know Drizzle Learn Prisma API

Schema as TypeScript

import { pgTable, serial, text, integer, boolean, timestamp } from "drizzle-orm/pg-core";
import { relations } from "drizzle-orm";

export const posts = pgTable("posts", {
  id: serial("id").primaryKey(),
  title: text("title").notNull(),
  content: text("content"),
  authorId: integer("author_id").references(() => users.id),
  published: boolean("published").default(false),
  createdAt: timestamp("created_at").defaultNow(),
});

export const postsRelations = relations(posts, ({ one }) => ({
  author: one(users, { fields: [posts.authorId], references: [users.id] }),
}));

SQL-Like Queries

// SELECT with joins
const result = await db
  .select({ title: posts.title, author: users.name })
  .from(posts)
  .leftJoin(users, eq(posts.authorId, users.id))
  .where(eq(posts.published, true))
  .orderBy(desc(posts.createdAt))
  .limit(10);

// Aggregations
const stats = await db
  .select({ count: count(), avgLength: avg(posts.content) })
  .from(posts)
  .groupBy(posts.authorId);

// Transactions
await db.transaction(async (tx) => {
  await tx.insert(users).values({ name: "Bob", email: "bob@example.com" });
  await tx.insert(posts).values({ title: "First Post", authorId: 1 });
});

Automatic Migrations

# Generate migration from schema changes
npx drizzle-kit generate

# Apply migrations
npx drizzle-kit migrate

# Visual schema browser
npx drizzle-kit studio

Drizzle Studio

Built-in database browser at https://local.drizzle.studio:

  • Visual table explorer
  • Run queries
  • Edit data inline
  • View relationships

Key Stats

  • 28,000+ GitHub stars
  • 7.4KB bundle (vs 800KB Prisma)
  • PostgreSQL, MySQL, SQLite
  • Serverless-native
  • Built-in migration + studio

FAQ

Q: What is Drizzle ORM? A: A type-safe TypeScript ORM with SQL-like query syntax, zero abstraction overhead, and serverless-native design. 7.4KB bundle vs Prisma's 800KB.

Q: Is Drizzle free? A: Yes, fully open-source under Apache 2.0 license.

Q: Should I switch from Prisma to Drizzle? A: If you know SQL and want smaller bundles, faster serverless cold starts, and SQL-like syntax — yes. Prisma is better if you prefer its abstracted query API.


🙏

Source et remerciements

Created by Drizzle Team. Licensed under Apache 2.0.

drizzle-orm — ⭐ 28,000+

Thanks for making TypeScript and SQL feel like the same language.

Discussion

Connectez-vous pour rejoindre la discussion.
Aucun commentaire pour l'instant. Soyez le premier à partager votre avis.

Actifs similaires