# Next.js boilerplate with Drizzle ORM

> TypeScript-first SQL ORM with generated SQL migrations, a typed query builder and a relational query API. It is the default ORM. It fills src/db/schema.ts through the db-schema slot, which every other battery injects its tables into. It wraps the connection your database battery configured instead of opening its own.

Typed SQL in TypeScript, no engine binary, and migrations you read as plain SQL.

- **Category:** ORM
- **Pricing:** Free and open source: drizzle-orm is Apache 2.0 and drizzle-kit is MIT. No hosted service, no seats, no data proxy to pay for.
- **Best for:** Teams who want SQL semantics in TypeScript and serverless deploys without a native binary. Every migration is plain SQL you review in the pull request.
- **Requires:** database
- **Conflicts with:** prisma
- **Vendor docs:** https://orm.drizzle.team/docs/overview

## Trade-offs

- No separate schema language: tables are TypeScript, so your editor is the schema editor and there is no codegen step to forget.
- Migrations are generated SQL files you commit and can hand-edit before the first apply. You review the SQL itself, not a diff of a custom format.
- Plain JavaScript with no engine binary, so cold starts on Vercel stay small and edge runtimes work.
- Fewer extras than Prisma: no built-in seeding framework, no data browser beyond drizzle-kit studio, and a smaller plugin ecosystem.
- The relational query API (db.query) is younger than the core builder. Complex aggregate reports still read better as an explicit join or raw sql``.
- You own the connection lifecycle. Nothing pools for you, so serverless pooling is a decision you make, not one the ORM hides.

## Known fixes it ships

- [Adding a NOT NULL column to a table that already has rows](https://agenticboilerplate.com/cookbook/drizzle/adding-a-column-with-a-backfill): The one-line migration fails on any populated database. Split it into add-nullable, backfill in batches, and enforce: three migrations across two deploys.
- [drizzle-kit generate or drizzle-kit push, and when each is safe](https://agenticboilerplate.com/cookbook/drizzle/generate-vs-push): push diffs your schema straight onto the database with no file to review; generate writes SQL you commit. Use push only on a database you can throw away.
- [db.query relations or an explicit join: choosing in Drizzle without an N+1](https://agenticboilerplate.com/cookbook/drizzle/relations-vs-joins): The relational API returns nested objects and one round trip; the core builder returns flat rows and total control. Which to reach for, and the loop that quietly becomes N+1.
- [Transactions in Drizzle on serverless: what works over HTTP and what needs a socket](https://agenticboilerplate.com/cookbook/drizzle/transactions-in-serverless): An interactive db.transaction() needs a real connection held open. On an HTTP driver it silently is not one. Here is what each driver supports and how to write atomic writes without holding a connection.
- [Typing partial selects and joins in Drizzle without writing the types by hand](https://agenticboilerplate.com/cookbook/drizzle/typing-partial-selects): $inferSelect describes the whole row, not the three columns you selected. Use the query builder's inferred types, Awaited<ReturnType<...>>, and helper types instead of hand-maintained interfaces.

## Generate it

[Build a repo with Drizzle ORM](https://agenticboilerplate.com/build?b=drizzle)

---

Agentic Boilerplate: A Next.js repo your agent already knows. Free during launch, then $99 once.

- Site map for agents: https://agenticboilerplate.com/llms.txt
- Public API: https://agenticboilerplate.com/openapi.json
- Contact: agenticstudio@gmail.com
