Drizzle
Drizzle ORM with PostgreSQL — a TypeScript-first, SQL-like alternative to Prisma.
Overview
Adds Drizzle ORM with PostgreSQL. Schema lives in TypeScript under db/schema/, with a shared client in lib/db.ts.
Prerequisites
None. Mutually exclusive with Prisma — choose one ORM per project.
Installation
npx ds-start init my-app --drizzleWith Better Auth:
npx ds-start init my-app --drizzle --authWhat It Adds
db/schema/— Database schema files (TypeScript)db/schema/events.ts— Startereventstabledrizzle.config.ts— Drizzle Kit configurationlib/db.ts— Shared Drizzle client instance for server-side usage
Environment Variables
| Variable | Description |
|---|---|
DATABASE_URL | PostgreSQL connection string |
First-run Setup
# Set your DATABASE_URL in .env.schema
bun run env:check
bun run db:pushUsage
Database client
Import db from @/lib/db in Server Components, Route Handlers, or Server Actions — never instantiate the Drizzle client directly.
Adding tables
- Create a new file in
db/schema/(e.g.,db/schema/posts.ts). - Define your table using
pgTable()fromdrizzle-orm/pg-core. - Re-export from
db/schema/index.ts. - Run
bun run db:generateto generate a migration. - Run
bun run db:push(dev) orbun run db:migrate(prod) to apply.
Scripts
| Script | Description |
|---|---|
db:generate | Generate SQL migration from schema changes |
db:migrate | Run pending migrations |
db:push | Push schema directly (dev only) |
db:studio | Open Drizzle Studio (browser-based DB viewer) |