SQL to ORM Model Generator

Paste your SQL schema and get ORM models for six frameworks, with foreign keys turned into relations on both sides and composite keys and indexes kept.

在您的瀏覽器中執行。您的檔案不會離開裝置。 瞭解如何驗證

…

使用方法

  1. 1
    Paste the schema

    Paste CREATE TABLE statements or open a .sql dump with only the schema.

  2. 2
    Check what was read

    Open What was read from the SQL to see tables, columns, types and relations.

  3. 3
    Fix warnings

    Read the warnings about missing primary keys or unknown referenced tables.

  4. 4
    Choose the framework

    Click Prisma, TypeORM, Sequelize, SQLAlchemy 2.0, Django or GORM.

  5. 5
    Set the database

    For Prisma choose PostgreSQL, MySQL, SQLite or SQL Server for native types.

  6. 6
    Copy or download

    Copy the models, download the file, or press ZIP all six.

關於此工具

Moving an existing database to an ORM, or keeping models in sync with a schema written by a DBA, means translating every column type, default, key and constraint by hand, in a syntax that differs for every framework. This generator reads SQL DDL from PostgreSQL, MySQL and MariaDB, SQLite or SQL Server: CREATE TABLE with column and table constraints, ALTER TABLE ADD CONSTRAINT and CREATE INDEX. It maps each type to the right ORM type, keeps nullability, defaults, auto-increment and identity columns, unique constraints, composite primary keys, indexes and MySQL enums, and turns every foreign key into a relation on both tables, with ON DELETE behaviour. One click switches between Prisma, TypeORM, Sequelize, SQLAlchemy 2.0, Django and GORM.

Who this is for

Back-end developers adopting an ORM on an existing database, teams migrating between frameworks or languages, and students turning a database design into code.

What is read from the SQL

Column names, types with length, precision and scale, NOT NULL, DEFAULT values and functions, PRIMARY KEY, UNIQUE, AUTO_INCREMENT, SERIAL and IDENTITY, UNSIGNED, array types, enum and set values, column comments, inline REFERENCES and table-level FOREIGN KEY clauses with ON DELETE and ON UPDATE, composite primary and unique keys, KEY and INDEX definitions and separate CREATE INDEX statements. Quoted names in double quotes, backticks or brackets and schema prefixes are handled. Other statements are skipped with a note.

Naming

Model names are the table name in singular PascalCase: users becomes User and categories becomes Category. Prisma, TypeORM and Sequelize fields use camelCase and map back to the original column with @map, name or field. Python outputs keep the column names. Go fields use PascalCase with Go initialisms, so author_id becomes AuthorID. Every model maps to the original table name.

Relations

A foreign key column named author_id becomes a relation called author pointing to the referenced model, and the referenced model gets the reverse side, posts, as a list. If the foreign key column is unique the relation is one-to-one. When one table references another twice, for example author and editor, the relations are given distinct names so the ORM can tell them apart.

Per-framework details

Prisma gets native type attributes for PostgreSQL, MySQL or SQL Server, @default(now()), autoincrement() and uuid(), @updatedAt for ON UPDATE CURRENT_TIMESTAMP and enums. TypeORM uses PrimaryGeneratedColumn, CreateDateColumn and UpdateDateColumn where appropriate. Sequelize gets one initModels function with belongsTo and hasMany associations. SQLAlchemy uses Mapped and mapped_column with server defaults. Django uses ForeignKey or OneToOneField with on_delete and related_name and, for composite keys, the CompositePrimaryKey field of Django 5.2. GORM gets struct tags for columns, sizes, defaults, indexes and constraints.

Worked example

The sample blog schema has four tables: users, posts, tags and post_tags. posts references users twice, as author with ON DELETE CASCADE and editor with ON DELETE SET NULL, and post_tags has a composite primary key over two foreign keys. The generator finds four relations, names the two user relations PostAuthor and PostEditor in Prisma, and produces User.postsAsAuthor and User.postsAsEditor as the reverse sides.

Limits

Views, triggers, check constraints, generated columns, partitions and stored procedures are not converted, and vendor-specific types fall back to strings. Join tables become two many-to-one relations rather than implicit many-to-many. Always review the output and validate it with your ORM's tools before running migrations.

計算示例

Blog schema: 4 tables, 4 relations, two named relations from posts to users, composite key on post_tags.

要點

常見問題

Which SQL dialects are supported?

PostgreSQL, MySQL and MariaDB, SQLite and SQL Server CREATE TABLE syntax, including quoted names and schema prefixes.

How are foreign keys turned into relations?

Each becomes a relation on the referencing model and a reverse list (or single object for unique keys) on the referenced model.

What happens with two foreign keys to the same table?

The relations get distinct names, such as PostAuthor and PostEditor, so the ORM can tell them apart.

Does it support composite primary keys?

Yes, for every target; Django uses the CompositePrimaryKey field added in Django 5.2.

Can I convert to all frameworks at once?

Yes. ZIP all six downloads one file per framework.

Is my schema uploaded?

No. Parsing and code generation run in your browser.

完全免費無費用,無需註冊
檔案保持私密一切都在您的瀏覽器中執行
用您的語言輕鬆使用提供多種語言