Registry / devops / drizzle-gen

drizzle-gen

JSON →
library1.0.3jsnpmunverified

drizzle-gen (v1.0.3) is a code-generation tool that automatically derives Drizzle ORM relations from your schema definitions. It parses your PostgreSQL or MySQL Drizzle schema files and generates a `.gen.ts` file with the correct `relations()` calls, saving you from manually writing and maintaining them. Key differentiators: zero runtime dependencies, runs as a one-off CLI or in watch mode, supports npx/pnpx/bunx/yarn dlx, and auto-updates on schema changes. However, it requires a single schema file path in `drizzle.config.ts` (list format not supported) and currently only works with PostgreSQL and MySQL. Ideal for Drizzle projects that want to avoid boilerplate relation code.

npm install drizzle-gen
INSTALL
IMPORT
SIG · DRIZZLE-GEN
D
drizzle-gen
devopsjavascriptv1.0.3
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

drizzle-gen (CLI)
npx drizzle-gen
npm install -g drizzle-gen && drizzle-gen
npx is preferred to avoid global install. The package provides a CLI, not a programmatic API.
Generated relations (import in code)
import { usersRelations } from './schema.gen'
import { usersRelations } from './schema'
Generated relations are in a separate `.gen.ts` file. Import from `{schema_path}.gen.ts`.
Watch mode (development)
npx drizzle-gen --watch
npx drizzle-gen -w
Use `--watch` flag for auto-regeneration. No short alias currently supported.

Shows a complete setup: install, run the generator, import both schema and relations, and use them in a drizzle query with relations.

// Ensure you have a drizzle.config.ts with a single schema file path // e.g., export default { schema: './schema.ts', out: './drizzle' } // Step 1: Run drizzle-gen in your project directory npx drizzle-gen // Step 2: Import generated relations in your drizzle index file import { drizzle } from 'drizzle-orm/node-postgres'; import { Pool } from 'pg'; import { * as schema } from './schema'; import { * as relations } from './schema.gen'; const pool = new Pool({ connectionString: process.env.DATABASE_URL ?? '' }); const db = drizzle(pool, { schema: { ...schema, ...relations } }); // Step 3: Use the relations automatically in queries const result = db.query.users.findMany({ with: { posts: true }, });
Debug
Known issues
gotchadrizzle.config.ts must specify a single string for schema (e.g., './schema.ts'). Array format not supported.
fix
Change schema config to a single string: schema: './schema.ts'
affects: >=1.0.0
gotchaOnly PostgreSQL and MySQL are currently supported. Other databases (SQLite, etc.) will not work.
fix
Use a supported database or wait for future updates.
affects: >=1.0.0
gotchaThe generated file is named `schema.gen.ts` based on your schema file path. If you rename your schema file, you must re-run drizzle-gen.
fix
Re-run npx drizzle-gen after renaming the schema file.
affects: >=1.0.0
Errors
Common errors & fixes
Error: schema is not a valid string. List schema not yet supported.
drizzle.config.ts schema field is an array (e.g., ['./schema.ts']) instead of a single string.
fix
Set schema to a single string: schema: './schema.ts'
Error: database type not supported. Only PostgreSQL and MySQL are supported.
Using a non-PostgreSQL/MySQL database (e.g., SQLite, PlanetScale).
fix
Switch to PostgreSQL or MySQL, or wait for future support.
Error: drizzle.config.ts not found in current directory.
Run the command in a directory that doesn't contain drizzle.config.ts.
fix
Navigate to your project root where drizzle.config.ts is located, or create one.
Upgrade
Version history
1.0.3latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
drizzle-gen — npm install drizzle-gen · libregistry