What is SQL to Ent Schema Generator?
This tool converts SQL CREATE TABLE statements into Go Ent schema definitions. Ent (entgo.io/ent) is a powerful entity framework for Go that uses code generation to provide type-safe database interactions. The converter generates schema structs with Fields(), Edges(), and Annotations() methods, including proper SchemaType mappings for database dialect compatibility.
How to Use
- Set the package name (default: "schema")
- Choose the database dialect (MySQL, PostgreSQL, or SQLite)
- Toggle "Generate Edges stub" if you want edge scaffolding
- Paste your SQL CREATE TABLE statements into the input area
- Click "Generate Ent Schema" to create the Go schema definitions
- Copy the output and save it as a .go file in your Ent schema directory
Why Use This Tool?
Tips & Best Practices
- The SchemaType mapping ensures Ent generates the correct SQL column types for your chosen dialect
- Use the "Generate Edges stub" option to scaffold edge definitions for entity relationships
- After generating schemas, run `go generate ./ent` to create the full Ent client code
- Nullable fields use both .Optional() and .Nillable() — Optional allows omission in create, Nillable allows nil values
Frequently Asked Questions
What is Ent?
Ent is an entity framework for Go developed by Facebook (Meta). It uses a code-generation approach where you define schemas as Go types, and Ent generates type-safe builders, clients, and CRUD helpers. It supports MySQL, PostgreSQL, SQLite, and Gremlin, and provides features like migrations, hooks, privacy layers, and GraphQL integration.
How are SQL types mapped to Ent field types?
SQL types are mapped to Ent field types based on their semantic meaning. For example, VARCHAR/CHAR/TEXT → field.String(), INT/INTEGER → field.Int(), BIGINT → field.Int64(), SMALLINT → field.Int16(), TINYINT → field.Int8(), DECIMAL/NUMERIC/FLOAT/DOUBLE → field.Float(), BOOLEAN → field.Bool(), DATETIME/TIMESTAMP/DATE → field.Time(), JSON → field.JSON(). Each field also gets a SchemaType annotation for dialect-specific type mapping.
Why does the generated code use SchemaType?
Ent uses generic Go types (e.g., field.Int, field.String) by default, but databases have specific type names (e.g., bigint, varchar(255)). The SchemaType mapping tells Ent which SQL type to use when creating or migrating the database schema, ensuring the generated DDL matches your original table definition.
What is the Annotations method for?
The Annotations() method adds table-level metadata to the schema. The entsql.Annotation with the Table field ensures that Ent maps the schema struct to the correct SQL table name, which is especially important when the Go struct name (PascalCase) differs from the SQL table name (snake_case).
Is my SQL data sent to a server?
No, all processing happens entirely in your browser. Your SQL schema never leaves your device. The conversion is performed client-side using a regex-based parser.