Skip to content

ORM Model Generation

Generate ORM models in DDLBuilder. Start with the getting started guide or import existing SQL if you do not have a table yet. For cross-table references, check the foreign keys and ER diagram first.

SQLite / D1 supports Drizzle output. Use the group export for cross-table foreign keys. See Query Design and Modeling for type mapping and initialization limits.

This guide details how to export schema designs directly into strongly typed model classes across industry-standard ORM frameworks.

Example: convert a MySQL users table to a Prisma model

This example generates a single-table model without cross-table relationships. Open DDLBuilder, select MySQL, and import this SQL:

sql
CREATE TABLE users (
  id INT NOT NULL,
  name VARCHAR(100) NOT NULL,
  PRIMARY KEY (id ASC)
);

Select users, open the ORM tab on the right, and choose Prisma. The generated model is shown below; alignment spacing may differ.

prisma
model Users {
  id             Int        @id
  name           String
  @@map("users")
}

The primary key on id maps to @id, name becomes a required String, and @@map("users") preserves the database table name. There is no auto-increment or default value in this example, so inserts must provide both id and name.

This is a model fragment. Configure the MySQL datasource and client generator in your own Prisma project, validate the model, then generate the client or migrations according to your project's workflow. Model generation does not connect to or modify your database. For a users-and-orders relationship, continue with foreign keys and ER diagrams.

Overview

Bridge database modeling and backend engineering by generating clean, typed, and annotated model code without manual transcription errors.


Operations Walkthrough

1. Select Target Framework

  1. Switch to the ORM tab in the right-hand output panel.
  2. Select your framework from the dropdown:
    • Prisma (Node.js / TypeScript)
    • TypeORM (TypeScript / NestJS)
    • SQLAlchemy (Python / FastAPI / Django)
    • GORM (Go / Gin / Fiber)
    • JPA / Hibernate (Java / Spring Boot)
  3. The editor immediately renders framework-compliant entity definitions.

2. Copy Code to Your Project

Click Copy ORM to copy the generated class or schema to your clipboard, then paste it directly into your application codebase.


Frameworks and Type Mapping Specifications

FrameworkOutput FormatCommon Annotations and Constructs
Prisma.prisma schema file@id, @default(), @map(), @unique, @@index, @@schema
TypeORMTypeScript Entity class@Entity(), @PrimaryGeneratedColumn(), @Column({ type, precision }), @Index()
SQLAlchemyPython Declarative classColumn(), Integer(), String(), DECIMAL(), __table_args__
GORMGo Structgorm.Model, gorm:"column:xxx;type:xxx;primaryKey;uniqueIndex"
JPAJava Entity class@Entity, @Table(name, schema), @Id, @Column(name, nullable), @Index

Precision Safety & Schema Namespace Details

Type Safety and Namespaces

  • High-Precision Decimals & BigInt: In TypeORM outputs, bigint and decimal/numeric types are mapped to string properties to prevent JavaScript float precision truncation.
  • Schema Namespaces:
    • Prisma: Appends @@schema("schemaName") for PostgreSQL and SQL Server.
    • SQLAlchemy: Declares schema='schemaName' in __table_args__.
    • JPA: Binds schema = "schemaName" within @Table.
    • GORM: Implements a custom TableName() method returning the qualified table name.

Verification Checklist

  • [ ] Generated ORM fields, primary keys, and column attributes match table configurations.
  • [ ] Pasted model files compile and pass static type checks cleanly.
  • [ ] Schema namespaces are appropriately declared in framework-specific configurations.