Drizzle ORM package for SQL databases
Drizzle ORM is a TypeScript-first SQL query builder and ORM designed for developers who understand SQL and want type safety without sacrificing performance or control. Unlike traditional ORMs that abstract SQL away, Drizzle provides direct SQL-like syntax with full TypeScript inference, compiling to efficient database queries without runtime overhead. At 7.4kb minified and gzipped with zero dependencies, it's built specifically for modern JavaScript runtimes including serverless environments like Cloudflare Workers, Vercel Edge Functions, and AWS Lambda.
The library supports PostgreSQL, MySQL, SQLite, and SingleStore with native driver integration—no adapters or binaries required. You define your schema in TypeScript code, and Drizzle automatically infers select and insert types without code generation steps. The package includes Drizzle Kit, a CLI tool that handles migration generation, schema pushes, and includes Drizzle Studio for visual data browsing. This approach eliminates the compile-time delays common in other ORMs while maintaining complete type safety.
Drizzle offers two query APIs: a SQL-like API for developers comfortable with raw SQL who want type safety, and a relational API for nested queries with automatic joins. Both APIs work with the same schema definitions and share the same connection pool. The library has gained significant traction with over 4.6 million weekly downloads, particularly among teams building Next.js applications with serverless databases like Neon, PlanetScale, Turso, and Supabase where cold start performance is critical.
The project is actively maintained under the Apache-2.0 license with regular updates adding features like the drizzle-seed package for deterministic test data generation, enhanced numeric type handling, and improved TypeScript enum support. It's designed for teams that value SQL knowledge, need predictable query performance, and want to avoid the bundle size and cold start penalties of heavier ORMs.
import { drizzle } from 'drizzle-orm/neon-http';
import { neon } from '@neondatabase/serverless';
import { pgTable, serial, text, timestamp, integer } from 'drizzle-orm/pg-core';
import { eq, and, gt } from 'drizzle-orm';
// Define schema with TypeScript
const users = pgTable('users', {
id: serial('id').primaryKey(),
email: text('email').notNull().unique(),
name: text('name'),
createdAt: timestamp('created_at').defaultNow()
});
const posts = pgTable('posts', {
id: serial('id').primaryKey(),
userId: integer('user_id').notNull().references(() => users.id),
title: text('title').notNull(),
views: integer('views').default(0)
});
// Initialize connection
const sql = neon(process.env.DATABASE_URL!);
const db = drizzle(sql);
// Type-safe queries - types automatically inferred
const newUser = await db.insert(users)
.values({ email: 'alice@example.com', name: 'Alice' })
.returning(); // NewUser: { id: number; email: string; name: string | null; ... }
// SQL-like query with full type safety
const popularPosts = await db.select({
title: posts.title,
authorName: users.name,
views: posts.views
})
.from(posts)
.innerJoin(users, eq(posts.userId, users.id))
.where(and(
gt(posts.views, 100),
eq(users.id, newUser[0].id)
));
// Relational query - fetches nested data in one query
const usersWithPosts = await db.query.users.findMany({
where: eq(users.email, 'alice@example.com'),
with: {
posts: {
where: gt(posts.views, 50),
orderBy: (posts, { desc }) => [desc(posts.views)],
limit: 10
}
}
});
// Transaction with automatic rollback on error
await db.transaction(async (tx) => {
await tx.update(posts)
.set({ views: posts.views + 1 })
.where(eq(posts.id, 1));
await tx.insert(users)
.values({ email: 'bob@example.com', name: 'Bob' });
});Serverless API development: Build Next.js API routes or Cloudflare Workers with sub-second cold starts. Drizzle's minimal bundle size and zero dependencies mean your functions deploy faster and execute with 73% better cold start performance compared to alternatives, critical for user-facing APIs where first request latency matters.
Type-safe database layers in monorepos: Share schema definitions across frontend and backend TypeScript codebases. Since Drizzle schemas are pure TypeScript with automatic type inference (typeof users.$inferSelect), you get compile-time guarantees across your entire stack without maintaining separate schema files or running code generators.
Multi-tenant SaaS applications: Manage complex queries with tenant isolation using Drizzle's SQL-like API for precise WHERE clauses and indexes. The relational API handles nested data fetching (user → posts → comments) in a single query, while maintaining full control over JOIN strategies for performance optimization.
Edge-first applications: Deploy database-backed apps to Vercel Edge or Cloudflare Pages with direct support for edge-compatible database drivers. Drizzle works natively with Neon serverless, Turso, and Cloudflare D1 without HTTP overhead, enabling sub-10ms query latencies from edge locations.
Migration from raw SQL codebases: Incrementally add type safety to existing projects using raw SQL queries. Drizzle's SQL-like syntax maps directly to SQL patterns developers already know, making migration straightforward while adding TypeScript inference to catch runtime errors at compile time.
Type safe SQL query builder
Prisma is an open-source database toolkit. It includes a JavaScript/TypeScript ORM for Node.js, migrations and a modern GUI to view and edit the data in your database. You can use Prisma in new projects or add it to an existing one.
Data-Mapper ORM for TypeScript and ES2021+. Supports MySQL/MariaDB, PostgreSQL, MS SQL Server, Oracle, SAP HANA, SQLite, MongoDB databases.
npm install drizzle-ormpnpm add drizzle-ormbun add drizzle-orm