SQL DDL to Go GORM Structs
Converts CREATE TABLE statements into Go GORM structs with Go-style field names, pointer types for nullable columns, gorm and json tags, belongs-to association fields and TableName() methods.
Use the tool
Why this tool exists
Writing GORM models for an existing schema means translating every column into a Go field with the right type, name and tag: ID instead of Id, a pointer for NULLable columns, a gorm tag for column name, size and constraints, and a json tag for the API. For a large table that is a lot of careful typing, and a missed tag can silently map a field to the wrong column. Paste the DDL here and get structs with those details filled in, including belongs-to fields for foreign keys and a TableName method when the table name differs from GORM's convention. It is a starting point rather than a finished model. The conversion runs in your browser.
How to use it
- Paste your CREATE TABLE statements into the input box.
- Run the conversion to get the Go structs.
- Copy them into your package, run gofmt and check the field types against your code.
Frequently asked questions
How are nullable columns represented?
Nullable columns become pointer types, such as *string or *int64, so that a NULL value in the database maps to nil in Go instead of being confused with an empty string or zero.
What tags are generated?
A gorm tag with column, primaryKey, autoIncrement, size, not null, uniqueIndex, default or precision as needed, and a json tag with the column name.
How are names converted?
Column names become Go-style exported field names, with common initialisms such as ID and URL written in capitals. The original column name is kept in the gorm tag so the mapping stays correct.
Are associations created?
Foreign keys produce belongs-to association fields. Has-many and many-to-many associations are not generated, so add them where you need them.