SQL to GORM Struct Converter
Paste any CREATE TABLE SQL and get GORM-tagged Go structs with correct gorm struct tags, pointer types for nullable columns, and embedded gorm.Model for standard timestamp fields.
Runs 100% in your browser. Your input and files never leave your device.
Why use our online SQL to GORM Struct Converter?
GORM uses Go struct tags to map database columns. Every nullable column needs a pointer type, primary keys need the primaryKey tag, and foreign keys need explicit column tags. Writing this for a 10-table schema requires careful translation of SQL types to Go types and correct tag syntax.
How to use SQL to GORM Struct Converter
- 1Paste your SQL
Paste one or more CREATE TABLE statements. Click the GORM tab.
- 2Review the output
The right panel shows a models.go file with Go structs and GORM struct tags.
- 3Check the type mapping
Expand the Type Mapping panel to verify every column — SQL type → Go type + gorm tags.
- 4Copy or download
Click Copy to grab models.go, or Download ZIP for the full output.
Frequently Asked Questions
When is gorm.Model embedded vs individual fields?
When the "Detect timestamps" option is on and the table has id, created_at, updated_at, and deleted_at columns, the struct embeds gorm.Model (which provides all four fields). Otherwise, all fields are declared individually.
How are nullable columns represented in Go?
Nullable columns use pointer types (*string, *int32, *time.Time) instead of value types. GORM uses nil to represent NULL in the database.
What package is used for DECIMAL types?
DECIMAL/NUMERIC maps to decimal.Decimal from the shopspring/decimal package (github.com/shopspring/decimal). The import is included in the output. If you prefer a different decimal library, replace the type.
How are UUID columns handled?
UUID maps to uuid.UUID from github.com/google/uuid. The import is included. If the column has a gen_random_uuid() default, the gorm tag default:uuid_generate_v4() is added.
What GORM version is the output targeting?
GORM v2 (gorm.io/gorm). The struct tag syntax and embedded gorm.Model are the same across all v2 releases.
Related Tools
More Developer Tools- JSON FormatterClean, minify, and validate JSON data structures.Free • In browser
- SQL FormatterFormat, beautify, and minify SQL queries online. Supports MySQL, PostgreSQL, SQLite, and more SQL dialects.Free • In browser
- Regex TesterReal-time expression matching and testing.Free • In browser
Also useful: Cron BuilderMermaid Live Editor