SQL to ORM Model Generator

Paste table definitions and choose your ORM. Copy the model draft and adapt the mappings and application-specific behavior before using it.

Runs locally in your browser
This tool processes all data locally in your browser.
SQL DDLPaste CREATE TABLE statements from MySQL, PostgreSQL, SQLite, or SQL Server. The parser reads tables, columns, primary keys, and direct REFERENCES clauses.
Generated models

How to turn CREATE TABLE statements into ORM models

Paste CREATE TABLE statements, choose Prisma, Drizzle, TypeORM or SQLAlchemy, and press Generate models. Every table in the paste is read — columns, types, NOT NULL, primary keys, defaults and foreign keys — and one model block per table is returned, ready to copy or download.

The work happens in the page: generating the models sent no network request in testing, so the schema text never leaves the browser and the tool keeps working after the connection drops.

  1. Paste the DDL into the SQL DDL pane, or press Load example to start from two small tables.
  2. Choose the target in Generate for: Prisma, Drizzle ORM, TypeORM or SQLAlchemy.
  3. Press Generate models. The status line reports how many table models were produced, and adds a note when a definition in the pasted DDL could not be read.
  4. Switch the target at any time: the pane is regenerated, so the code always matches the ORM shown next to it.
  5. Use Copy or Download (models.ts, or models.py for SQLAlchemy) to take the code out, and Clear to empty both panes. If the parser finds no CREATE TABLE at all, the pane is emptied and Copy says there is nothing to copy.

How the DDL is read and what the models contain

What the parser reads

Table names, with or without a schema prefix (app.accounts is emitted as accounts), column names in backticks, double quotes or brackets, and the type of every column. NOT NULL makes a field required and a nullable column becomes optional. Primary keys are taken from a column-level PRIMARY KEY and from a table-level PRIMARY KEY (a, b), composite keys included.

Auto-increment comes from the DDL rather than from the column name: SERIAL, BIGSERIAL, AUTO_INCREMENT, GENERATED … AS IDENTITY and a nextval(…) default are recognised, while a plain PRIMARY KEY is left as an ordinary key. DEFAULT CURRENT_TIMESTAMP and now() become each target’s own “now” default. Foreign keys are read from column-level REFERENCES and from table-level CONSTRAINT … FOREIGN KEY clauses. Line comments (-- and MySQL #) and block comments are removed before parsing.

What each target emits

Prisma: one model per table with @id, @@id([...]) when the key spans several columns, @default(autoincrement()) only where the DDL declares it, @default(now()) for current timestamps, @db.Uuid for UUID columns, and @map / @@map so the generated names still point at the original SQL names.

Drizzle ORM: pgTable declarations written for the Postgres dialect, with primaryKey({ columns: [...] }) for composite keys. TypeORM: @PrimaryGeneratedColumn only for auto-increment columns and @PrimaryColumn for every other key, so the decorators match the schema. SQLAlchemy: 2.0-style DeclarativeBase classes with Mapped[...] annotations, mapped_column() and ForeignKey('table.column') for both foreign-key syntaxes; the import list contains only the names the models use.

Check before you build on the result

Type mapping is deliberately coarse. varchar, char, text and citext all become the target’s string type, DECIMAL and NUMERIC become a decimal column annotated as Decimal, JSON, JSONB and XML use the generic JSON type, and any type the mapping does not know falls back to string. Compare one representative table against the real schema before you generate migrations from the output.

Anything that is not a column stays in the database: CHECK, UNIQUE, indexes, views, triggers, sequences, collations and storage clauses are not converted, and no target gets relation or navigation properties — a foreign key stays a plain column everywhere except SQLAlchemy, which adds ForeignKey. Drizzle output is Postgres-flavoured whatever the dialect of the pasted DDL.

Recent tools: