Diagram to Code — Free ER Diagram Converter

Convert Mermaid & PlantUML ER diagrams to SQL & ORM models — instantly.

Mermaid ER PlantUML PostgreSQL MySQL SQLite Oracle GORMREST API
postgres
mermaid
Live preview mermaid

New to Diagram2Code?

Learn how to write ER diagrams and get the most out of the converter.

What is Diagram2Code?

Diagram2Code is a free onlinediagram to codeconverter that turns Mermaid ER diagrams and PlantUML entity-relationship diagrams into production-ready SQL DDL statements and ORM model code. Paste your diagram, choose your target output, and get instant code. Also known as a diagram 2 code tool, it eliminates the need to hand-write SQL schemas from your ER designs.

Supported Databases

  • PostgreSQL — SERIAL primary keys, CREATE TYPE enums, COMMENT ON syntax
  • MySQL — AUTO_INCREMENT, inline ENUM, backtick quoting
  • SQLite — Type affinity mapping, IF NOT EXISTS support
  • Oracle 19c+ — IDENTITY columns, NUMBER types, VARCHAR2, COMMENT ON

Supported ORM Frameworks

  • GORM (Go) — Free tier, generates Go structs with GORM tags

How It Works

The tool parses your diagram into an intermediate schema model, normalizes it (adding synthetic primary keys, deduplicating columns), then generates dialect-specific SQL or framework-specific ORM code with proper type mapping, constraints, foreign keys, and relationships. Read the full documentation for details.

Frequently Asked Questions

What is a diagram to code converter?
A diagram to code converter is a tool that reads a text-based diagram — such as a Mermaid ER diagram or PlantUML entity diagram — and automatically generates production-ready source code. Diagram2Code converts your ER diagram directly to SQL DDL and ORM model code, eliminating hand-written boilerplate.
How do I convert a diagram to code?
Paste your Mermaid ER or PlantUML diagram into the input field above, select your target database or ORM framework, and click Convert. The diagram 2 code generator instantly produces SQL DDL statements or ORM model classes ready for use in your project.
What diagram formats are supported?
Diagram2Code supports Mermaid erDiagram syntax and PlantUML entity-relationship syntax. Both formats can be converted to SQL or ORM code for PostgreSQL, MySQL, SQLite, Oracle, and eight ORM frameworks.
Is the diagram to code tool free?
Yes. SQL DDL generation for all four databases (PostgreSQL, MySQL, SQLite, Oracle) is completely free with no sign-up required. GORM model generation is also free. Advanced ORM frameworks require a premium tier.
What is "diagram 2 code"?
"Diagram 2 code" (or "diagram to code") refers to generating source code automatically from a diagram, rather than writing it by hand. Diagram2Code does exactly this: it turns your database ER diagram into correct, production-ready SQL and ORM code in seconds.