ORM Generation

Last updated: March 2026

In addition to SQL DDL, diagram2code can generate ORM model code directly from your ER diagram. The generator maps the same intermediate schema model — tables, columns, types, relationships — to idiomatic model definitions in the target language and framework. In the converter, switch the Output selector to ORM Models and choose your target framework. Via the API, use the POST /v1/convert/orm endpoint with the framework field.

Free tier: GORM (Go) model generation is included in the free tier — no account or API key required. All other frameworks require a Developer or higher API key.

Supported ORM Frameworks

The table below lists all supported frameworks. GORM is available immediately with no sign-up. The remaining frameworks are available via the API with a Developer or Pro tier key, and progressively via the web converter as each generator is promoted out of beta.

FrameworkLanguageFile ext.Tier
GORM v2Go.goFree
SQLAlchemy 2Python.pyDeveloper+
TypeORMTypeScript.tsDeveloper+
Prisma SchemaPrisma DSL.prismaDeveloper+
JPA / HibernateJava.javaDeveloper+
Django ORMPython.pyDeveloper+
SequelizeJavaScript / TypeScript.jsDeveloper+
Entity Framework CoreC#.csDeveloper+

GORM (Go) — Free

The GORM generator produces idiomatic Go source code compatible with GORM v2. All structs are placed in package models. Required imports (time, encoding/json) are added automatically when needed.

Struct and field naming:

Type Mapping

Schema abstract types map to Go types as follows. Nullable columns (no NOT NULL / no PK) become pointer types.

Schema typeGo typeNotes
int, integer, serialuintUnsigned; nullable → *uint
bigint, bigserialuint64Nullable → *uint64
smallintint16Nullable → *int16
tinyintint8Nullable → *int8
string, varchar, char, text, clobstringNullable → *string
decimal, numeric, float, double, numberfloat64Nullable → *float64
realfloat32Nullable → *float32
boolean, bool, bitboolNullable → *bool
date, datetime, timestamp, timestamptztime.TimeRequires import "time"; nullable → *time.Time
uuid, uniqueidentifierstringUUID represented as string
blob, bytea[]byteBinary data
json, jsonbjson.RawMessageRequires import "encoding/json"
enum (with values)Named type + constantsSee Enums below

Relationships

Relationships detected from FK columns and diagram cardinality markers are represented as navigation fields:

RelationshipParent sideChild side
One-to-manyOrders []Order `gorm:"foreignKey:UserID"`User User `gorm:"constraint:OnDelete:CASCADE"`
One-to-oneProfile Profile `gorm:"foreignKey:UserID"`User User `gorm:"constraint:OnDelete:CASCADE"`
Many-to-manyTags []Tag `gorm:"many2many:product_tags"`Products []Product `gorm:"many2many:product_tags"`

Many-to-many join table names are auto-generated as from_table_to_table (lowercase, alphabetical order).

Enums

When a column has an enum type with defined values, the generator produces a named string type and typed constants:

Mermaid Input
erDiagram
    ORDER {
        int id PK
        enum status "active,inactive,completed"
    }
GORM Output
type OrderStatus string

const (
    OrderStatusActive    OrderStatus = "active"
    OrderStatusInactive  OrderStatus = "inactive"
    OrderStatusCompleted OrderStatus = "completed"
)

type Order struct {
    ID     uint        `gorm:"column:id;primaryKey" json:"id"`
    Status OrderStatus `gorm:"column:status;type:enum(active,inactive,completed)" json:"status"`
}

Full Example: GORM Model Generation

The same USER / ORDER diagram used in the SQL examples, converted to GORM Go models:

Mermaid Input
erDiagram
    USER {
        int id PK
        string name
        string email
    }
    ORDER {
        int id PK
        int user_id FK
        decimal total
    }
    USER ||--o{ ORDER : places
🐹 GORM (Go) Output
package models

type User struct {
    ID     uint     `gorm:"column:id;primaryKey" json:"id"`
    Name   *string  `gorm:"column:name" json:"name"`
    Email  *string  `gorm:"column:email" json:"email"`
    Orders []Order  `gorm:"foreignKey:UserID" json:"orders,omitempty"`
}

type Order struct {
    ID     uint     `gorm:"column:id;primaryKey" json:"id"`
    UserID *uint    `gorm:"column:user_id" json:"user_id"`
    Total  *float64 `gorm:"column:total" json:"total"`
    User   User     `gorm:"constraint:OnDelete:CASCADE" json:"user,omitempty"`
}
Tip: Non-primary-key fields are generated as pointer types (e.g., *string, *uint) to correctly represent nullable columns and distinguish zero values from missing values in Go.