← All Posts

How to Do Drizzle ORM Setup on Claude Code

Claude Code can scaffold a full Drizzle ORM setup in minutes: install dependencies, generate a schema file, configure a database connection, and run migrations. It works with Postgres, SQLite, and MySQL. The setup follows Drizzle's official conventions, so output is production-ready with no manual cleanup. Developers building TypeScript backends benefit most, especially those who want type-safe queries without the overhead of a heavier ORM like Prisma.

  • Drizzle ORM is a lightweight TypeScript ORM with zero-dependency query building and full SQL control
  • Claude Code can handle the entire setup flow end-to-end from a single prompt
  • Migrations use drizzle-kit, which Claude configures automatically alongside the schema

What is Drizzle ORM and why use it with Claude Code?

Drizzle ORM is a TypeScript-first ORM that prioritizes SQL transparency. Unlike Prisma, it does not use a binary query engine, which means smaller bundle sizes and faster cold starts. According to the Drizzle documentation, it supports PostgreSQL, MySQL, SQLite, and several serverless-compatible drivers like Neon, Turso, and PlanetScale.

Claude Code speeds up the setup by generating boilerplate you would otherwise write by hand: the schema definition, the drizzle.config.ts file, the database connection module, and the migration command. For developers already using Claude Code for TypeScript projects, adding Drizzle is a natural fit since everything stays in the same workflow.

How to set up Drizzle ORM step by step using Claude Code

Step 1: open Claude Code in your project directory

Start Claude Code from the root of your TypeScript project. If you are starting from scratch, you can ask Claude Code to initialize a Node.js or Next.js project first. For an existing project, just make sure a package.json is present before proceeding.

Step 2: prompt Claude to install Drizzle and configure it

Use a clear, specific prompt like:

"Set up Drizzle ORM with PostgreSQL in this project. Install drizzle-orm and drizzle-kit, create a db/schema.ts file with a sample users table, configure drizzle.config.ts, and add a migration script to package.json."

Claude Code will run the install commands, write the schema and config files, and wire up the migration tooling. You can swap "PostgreSQL" for "SQLite" or "MySQL" depending on your stack. For SQLite projects, check the related guide on SQLite setup on Claude Code.

Step 3: review the generated schema

Claude typically creates a schema similar to:

import { pgTable, serial, text, timestamp } from 'drizzle-orm/pg-core';

export const users = pgTable('users', {
  id: serial('id').primaryKey(),
  email: text('email').notNull().unique(),
  createdAt: timestamp('created_at').defaultNow(),
});

Review column types and add any domain-specific tables by following up with: "Add a posts table with a foreign key to users." Claude Code understands Drizzle's relational helpers and will use relations() correctly.

Step 4: configure the database connection

Ask Claude to create a db/index.ts connection module. A typical prompt:

"Create a db/index.ts that connects to PostgreSQL using the DATABASE_URL environment variable with the drizzle-orm/node-postgres driver."

Claude will read the DATABASE_URL from process.env and export a typed db instance. For setting up environment variables in Claude Code, see the guide on environment variable setup on Claude Code.

Step 5: run migrations

Once the schema is defined, tell Claude Code:

"Generate and run the initial migration using drizzle-kit."

Claude will run npx drizzle-kit generate to produce SQL migration files and then npx drizzle-kit migrate to apply them. For more complex migration workflows, see the related guide on PostgreSQL migrations on Claude Code.

Step 6: write your first query

Ask Claude to demonstrate a basic insert and select:

"Show me how to insert a new user and query all users using the Drizzle db instance."

Drizzle's query builder is fully type-safe, so Claude's output will include correct TypeScript types inferred from your schema definition automatically.

Drizzle ORM vs Prisma: which should you use with Claude Code?

FeatureDrizzle ORMPrisma
Schema languageTypeScript (schema.ts)Prisma schema DSL
Bundle size~100KB, no binaryLarger, includes query engine binary
Serverless supportFirst-class (Neon, Turso, PlanetScale)Supported via Accelerate
Raw SQL accessFull, with type safetyAvailable via $queryRaw
Claude Code prompt complexityLow (pure TypeScript)Medium (separate DSL file)

For serverless deployments and projects already in TypeScript, Drizzle is generally simpler for Claude Code to configure because all files are plain TypeScript. Prisma requires managing a separate .prisma schema file, which adds a context switch.

Common Drizzle ORM setup issues Claude Code can fix

  • Missing peer dependencies: if you get errors about pg or postgres not being found, prompt: "Install the correct driver package for this Drizzle setup."
  • Wrong dialect in drizzle.config.ts: Claude sometimes defaults to sqlite. Ask: "Update drizzle.config.ts to use the postgres dialect."
  • Migration folder mismatch: if the migration output path does not match your project structure, ask Claude to align out in drizzle.config.ts with your folder conventions.
  • Supabase integration: for projects using Supabase as the Postgres backend, Claude can configure the @supabase/supabase-js client alongside Drizzle. See the guide on Supabase auth setup on Claude Code for the auth layer.
  • Zod schema generation: ask Claude to generate Zod validation schemas from Drizzle table definitions using drizzle-zod. Related: form validation with Zod on Claude Code.

How to monitor Claude Code usage during a Drizzle setup session

A full Drizzle ORM setup with schema design, migrations, and query examples is a multi-step task. It typically involves 10 to 20 back-and-forth exchanges with Claude Code, which can consume a meaningful chunk of your Claude usage window. Claude Code's built-in /usage command shows your current consumption, but it requires you to leave your editor context to check it.

Usagebar keeps that data visible in your macOS menu bar continuously, so you can see exactly where you stand without switching windows. It sends alerts at 50%, 75%, and 90% of your usage limit, which means you will know before hitting the wall mid-setup rather than discovering a 5-hour lockout while waiting for a migration to run. Credentials are stored in macOS Keychain, and the app is available on a pay-what-you-want basis with a free option for students.

You can also check usage at claude.ai/settings/usage, but that requires a full browser context switch away from your terminal.

Get Usagebar to stay in flow during long Drizzle setup sessions.

Key takeaways

  1. Prompt Claude Code with a single, specific request covering install, schema, config, and migration in one shot.
  2. Specify your database dialect (Postgres, SQLite, MySQL) and driver upfront to avoid config corrections.
  3. Use follow-up prompts to add tables, relations, and Zod integration iteratively.
  4. Run npx drizzle-kit generate then npx drizzle-kit migrate to apply schema changes.
  5. Monitor your Claude Code usage window with Usagebar so a long setup session does not result in an unexpected lockout.

Sources

Track Your Claude Code Usage

Never hit your usage limits unexpectedly. Usagebar lives in your menu bar and shows your 5-hour and weekly limits at a glance.

Get Usagebar