Registry / database / prisma-generator-drizzle

prisma-generator-drizzle

JSON →
library0.7.6jsnpmunverified

A Prisma generator that creates a Drizzle ORM schema from your Prisma schema, enabling migration from Prisma to Drizzle or using both together. Version 0.7.6 targets Node >=14.0 and generates tables, enums, constraints, and relational query support. It aims for 1:1 compatibility with Prisma's field mapping, ignoring @db.* modifiers. The generator is experimental but production-safe, with ongoing development toward v1. Differentiators include support for Drizzle-specific features like $type<> and custom default functions, as well as integration with drizzle-kit.

npm install prisma-generator-drizzle
INSTALL
IMPORT
SIG · PRISMA-GENERATOR-D
P
prisma-generator-drizzle
databasejavascriptv0.7.6
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.

default (generated schema)
✓ import * as schema from './drizzle/schema'
✗ import schema from './drizzle/schema'
Generated output exports multiple tables and relations as named exports, so use wildcard import or named imports
users (example table)
✓ import { users } from './drizzle/schema'
✗ const { users } = require('./drizzle/schema')
Generated schema is ESM; CJS require works in Node but may break with bundlers
drizzle (from drizzle-orm)
✓ import { drizzle } from 'drizzle-orm/node-postgres'
✗ import { drizzle } from 'drizzle-orm'
The correct import depends on the database driver: node-postgres, mysql2, better-sqlite3, etc.
relations
✓ import { usersRelations } from './drizzle/schema'
✗ import { relations } from './drizzle/schema'
Relation objects are named as <table>Relations; import them individually

Shows setup: install generator and drizzle-orm, configure Prisma schema, generate, then use the generated schema with drizzle-orm and relational query.

// 1. Install dependencies // npm install -D prisma-generator-drizzle // npm install drizzle-orm @prisma/client // 2. Add to Prisma schema (schema.prisma): // generator drizzle { // provider = "prisma-generator-drizzle" // output = "./drizzle" // } // 3. Run: prisma generate // 4. Use the generated schema with Drizzle import { drizzle } from 'drizzle-orm/node-postgres'; import { Pool } from 'pg'; import * as schema from './drizzle/schema'; const pool = new Pool({ connectionString: process.env.DATABASE_URL ?? 'postgres://localhost:5432/mydb' }); const db = drizzle(pool, { schema }); // Example query using relational query const result = await db.query.users.findMany({ with: { posts: true } }); console.log(result);
Debug
Known issues
gotchaThe generator ignores @db.* modifiers, meaning custom database type annotations in Prisma schema are not reflected in the generated Drizzle schema.
fix
Manually adjust the generated Drizzle schema or use only default scalar types
affects: >=0.0.0
gotchaThe generator only works with Node >=14.0; using older Node versions will cause runtime errors.
fix
Update Node.js to version 14 or higher
affects: >=0.0.0
deprecatedThe dateMode option for sqLite is not supported; setting it will have no effect.
fix
Do not use dateMode with SQLite databases
affects: >=0.0.0
gotchaThe generator does not support tsconfig extends; it reads the closest tsconfig.json without resolving inheritance.
fix
Manually specify moduleResolution in the generator config or ensure tsconfig doesn't use extends
affects: >=0.0.0
breakingIn version 0.7.0, the relationalQuery option was introduced and defaults to true. If you rely on the previous default (no relational query), you need to explicitly set it to false.
fix
Set relationalQuery = false in the generator configuration if you do not want relational query support
affects: >=0.7.0
Errors
Common errors & fixes
Error: Cannot find module 'drizzle-orm'
Missing drizzle-orm dependency in the project
fix
Run 'npm install drizzle-orm'
Error: Generator 'drizzle' must be defined in schema.prisma
The generator block is missing or not correctly spelled
fix
Add 'generator drizzle { provider = "prisma-generator-drizzle" }' to your Prisma schema
Error: Failed to generate schema: Unsupported scalar type 'XYZ'
Using a custom scalar type not supported by the generator
fix
Use only default Prisma scalar types (String, Int, Float, Boolean, DateTime, Json, Bytes) or resolve manually
Error: Unexpected token '.' (or similar) when importing generated files
The generated files use ESM imports and the consuming code uses CommonJS require without transpilation
fix
Use ESM imports (import ... from) or configure a bundler/transpiler like TypeScript with esModuleInterop
Upgrade
Version history
0.7.6latest on npm
Audit
Dependencies
drizzle-ormrequiredGenerated schema depends on drizzle-orm for table definitions and relational query
@prisma/generator-helperrequiredUsed internally to interact with Prisma's generation pipeline
Agent activity
11 hits · last 30 days
node
9
Amazon
1
Resources
prisma-generator-drizzle — npm install prisma-generator-drizzle · libregistry