Generate Prisma, Drizzle, and Zod code from DBML
Paste DBML or a SQL dump, pick a target, and get the code: a Prisma schema, Drizzle tables, SQLAlchemy models, TypeScript row types, or Zod schemas, generated from the same schema so they agree with each other.
What each target produces
Prisma schema
A schema.prisma with a model per table and an enum per enum. Relations are
written on both sides, as Prisma requires: the side holding the key gets @relation(fields, references) and the other gets the list. Two models joined
more than once, and every self-relation, get named relations so the schema is not
ambiguous. Native types are kept with @db attributes.
Drizzle ORM
A schema.ts of pgTable definitions and pgEnums, with
camelCase properties over the real column names, .references() for foreign
keys, defaults, and indexes.
SQLAlchemy
A models.py in SQLAlchemy 2.0’s typed declarative style: a class per table with Mapped[...] annotations and mapped_column, Python enum.Enum classes, foreign keys, and indexes in __table_args__.
TypeScript types and Zod schemas
A types.ts with an interface per table and a union type per enum, describing a
row as the database returns it. Or a schemas.ts with a z.object per table, to validate rows at runtime, each with its inferred type. Decimals are typed as
strings in both, which is how drivers hand them over and the only way they stay exact.
One schema, every layer
The reason to generate these from one source is that they then cannot drift apart. The ORM model, the row type the API returns, and the validator at the edge all describe the same table, and when the table changes they are regenerated together.
In DB Planner that source is a schema your team designs on a shared ER diagram, and the export adds the options this page leaves at their defaults: the target database, naming conventions, and how dates are typed. Have an existing Prisma schema? Turn it into a diagram. Need plain DDL? Convert DBML to SQL.
Code generation questions
Can I generate a Prisma schema from SQL?
Yes. Paste CREATE TABLE statements from PostgreSQL, MySQL, or SQL Server in place of DBML. The SQL is read into a schema first and the Prisma schema is generated from that.
Which database is the generated code written for?
On this page, PostgreSQL: the Prisma datasource is postgresql and Drizzle uses pg-core. In DB Planner the export has a database chooser, with MySQL and SQL Server for Prisma and MySQL for Drizzle.
How are the model names chosen?
By each tool’s convention. Prisma models are PascalCase and singular with camelCase fields, mapped back to the real names with @@map and @map, so a users table becomes model User and still reads and writes users.
Is the generated code safe to use as is?
Treat it as a first draft that is right about the structure. It is generated from the schema alone, so review naming and relation names against how your codebase already does things before committing it.
Put your schema on the board
Start on the free plan, no card needed. Pro is $5 a month when you outgrow it.
Start designing free