# 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. ## Install Save as a script file and run: ## Quick Use ```bash npm install drizzle-orm postgres npm install -D drizzle-kit ``` ```typescript // schema.ts import { pgTable, serial, text, timestamp } from "drizzle-orm/pg-core"; export const users = pgTable("users", { id: serial("id").primaryKey(), name: text("name").notNull(), email: text("email").notNull().unique(), createdAt: timestamp("created_at").defaultNow(), }); ``` ```typescript // query.ts import { db } from "./db"; import { users } from "./schema"; import { eq } from "drizzle-orm"; // Type-safe queries that look like SQL const allUsers = await db.select().from(users); const user = await db.select().from(users).where(eq(users.email, "alice@example.com")); const newUser = await db.insert(users).values({ name: "Alice", email: "alice@example.com" }).returning(); ``` --- ## Intro 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 ```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 ```typescript // 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 ```bash # 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 & Thanks > Created by [Drizzle Team](https://github.com/drizzle-team). Licensed under Apache 2.0. > > [drizzle-orm](https://github.com/drizzle-team/drizzle-orm) — ⭐ 28,000+ Thanks for making TypeScript and SQL feel like the same language. --- ## 快速使用 ```bash npm install drizzle-orm postgres ``` ```typescript import { pgTable, serial, text } from "drizzle-orm/pg-core"; export const users = pgTable("users", { id: serial("id").primaryKey(), name: text("name").notNull(), }); ``` --- ## 简介 Drizzle ORM 是一个类型安全的 TypeScript ORM,GitHub 28,000+ stars。SQL 风格语法,零抽象开销,7.4KB 体积。原生支持 Serverless,支持 PostgreSQL/MySQL/SQLite。适合懂 SQL 且想要类型安全的 TypeScript 开发者。 --- ## 来源与感谢 > Created by [Drizzle Team](https://github.com/drizzle-team). Licensed under Apache 2.0. > > [drizzle-orm](https://github.com/drizzle-team/drizzle-orm) — ⭐ 28,000+ --- Source: https://tokrepo.com/en/workflows/0e904437-215d-4941-af94-eb0cf7424e0d Author: Script Depot