DEV Community

Alex Spinov
Alex Spinov

Posted on

Drizzle Studio Has a Free API You've Never Heard Of

Drizzle ORM is a TypeScript ORM that's headless — it generates SQL without an abstraction layer. Drizzle Studio is its free database browser that runs in your terminal. Together they give you the best SQL DX in TypeScript.

What Makes Drizzle Special?

  • SQL-like syntax — if you know SQL, you know Drizzle
  • Zero overhead — generates optimal SQL, no N+1
  • Type-safe — full inference from schema
  • Drizzle Studio — free database GUI
  • Serverless-ready — works with D1, Turso, Neon, PlanetScale

The Hidden API: SQL-Level Control with Type Safety

import { pgTable, serial, text, integer, timestamp, boolean } from 'drizzle-orm/pg-core';
import { drizzle } from 'drizzle-orm/node-postgres';
import { eq, and, gt, desc, sql, count } from 'drizzle-orm';

// Schema definition
export const users = pgTable('users', {
  id: serial('id').primaryKey(),
  name: text('name').notNull(),
  email: text('email').notNull().unique(),
  role: text('role', { enum: ['admin', 'user'] }).default('user'),
  createdAt: timestamp('created_at').defaultNow()
});

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),
  views: integer('views').default(0)
});

const db = drizzle(pool);

// Queries read like SQL
const publishedPosts = await db
  .select({
    title: posts.title,
    author: users.name,
    views: posts.views
  })
  .from(posts)
  .innerJoin(users, eq(posts.authorId, users.id))
  .where(and(
    eq(posts.published, true),
    gt(posts.views, 100)
  ))
  .orderBy(desc(posts.views))
  .limit(10);

// Aggregations
const topAuthors = await db
  .select({
    name: users.name,
    postCount: count(posts.id),
    totalViews: sql<number>`sum(${posts.views})`
  })
  .from(users)
  .leftJoin(posts, eq(users.id, posts.authorId))
  .groupBy(users.name)
  .having(gt(count(posts.id), 5));
Enter fullscreen mode Exit fullscreen mode

Drizzle Studio — Free Database GUI

# Launch Drizzle Studio — free database browser
npx drizzle-kit studio
# Opens at https://local.drizzle.studio
Enter fullscreen mode Exit fullscreen mode

Migration API

# Generate migrations from schema changes
npx drizzle-kit generate

# Apply migrations
npx drizzle-kit migrate

# Push schema directly (dev)
npx drizzle-kit push
Enter fullscreen mode Exit fullscreen mode

Quick Start

npm install drizzle-orm postgres
npm install -D drizzle-kit
npx drizzle-kit generate && npx drizzle-kit migrate
Enter fullscreen mode Exit fullscreen mode

Why Teams Choose Drizzle

A developer shared: "We switched from Prisma to Drizzle. Our query performance improved 3x because Drizzle generates optimal SQL — no unnecessary JOINs, no N+1 queries. And the TypeScript autocomplete is incredible — it knows the exact return type of every query."


Working with databases? Email spinov001@gmail.com or check my tools.

Drizzle vs Prisma vs TypeORM — what's your ORM choice?

Top comments (0)