DDLBuilderOpen DDLBuilder
DDLBuilder
Open DDLBuilder
Docs / Advanced guide

SQL to Prisma, TypeORM and other ORM models

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.

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:

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

Select users, open the ORM tab in the output area, and choose Prisma. The generated model is shown below. Alignment spacing may differ.

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.

When to use

Once the table structure is settled, generate ORM model classes and annotations instead of writing them by hand.


Steps

1. Select the target framework

  1. Click the ORM tab in the output area.
  2. In the ORM Framework selector, choose a framework:
    • Prisma (Node.js / TypeScript)
    • TypeORM (TypeScript / NestJS)
    • SQLAlchemy (Python / FastAPI)
    • GORM (Go / Gin / Fiber)
    • JPA (Java / Spring Boot)
  3. The code area shows the model code for the selected framework and updates when you change the table.

2. Copy the code to your project

Click Copy ORM Code, then paste the code into an entity or model file in your project.


Frameworks and type mappings

FrameworkOutput formatCommon annotations and constructs
Prisma.prisma schema file@id, @default(), @map(), @@unique, @@index, @@map, @@schema
TypeORMTypeScript entity class@Entity(), @PrimaryGeneratedColumn(), @PrimaryColumn(), @Column({ type, precision }), @Index()
SQLAlchemyPython declarative classColumn(), Integer, String(), Numeric(), Index(), __table_args__
GORMGo structgorm:"column:xxx;primaryKey;autoIncrement;uniqueIndex", TableName()
JPAJava entity class@Entity, @Table(name, schema), @Id, @Column(name, nullable)

Precision and schema namespaces

Precision and namespaces

  • TypeORM maps bigint to a string property. On MySQL-family and PostgreSQL-family databases, it also maps decimal and numeric to string, so the JavaScript number type does not lose precision.
  • When Schema Name is set:
    • Prisma adds @@schema("schemaName") on PostgreSQL-family databases and SQL Server.
    • SQLAlchemy adds {"schema": "schemaName"} to __table_args__.
    • JPA adds @Table(schema = "schemaName"), or uses catalog on MySQL-family databases.
    • GORM's TableName() method returns the table name with the schema prefix.

Verification checklist

  • Field names, type mappings, and primary keys in the ORM code match the table configuration.
  • The pasted code passes type checks and compiles in your project.
  • When Schema Name is set, the ORM code declares the namespace.

Last updated:

Need more help?

Start with the FAQ. If that does not solve it, tell us.

Example: convert a MySQL users table to a Prisma modelWhen to useSteps1. Select the target framework2. Copy the code to your projectFrameworks and type mappingsPrecision and schema namespacesVerification checklist