What is SQL to GORM Model Generator?
This tool converts SQL CREATE TABLE statements into Go GORM model struct definitions. GORM is the most popular Go ORM library, providing a developer-friendly way to interact with databases. The converter generates Go structs with proper GORM tags, JSON tags, and optional TableName() methods.
How to Use
- Set the package name (default: "model")
- Toggle options: GORM tags, JSON tags, and TableName() method
- Paste your SQL CREATE TABLE statements into the input area
- Click "Generate GORM Model" to create the Go struct definitions
- Copy the output and save it as a .go file in your Go project
Why Use This Tool?
Tips & Best Practices
- Nullable columns (no NOT NULL constraint) are generated as pointer types for proper zero-value distinction
- JSON columns map to datatypes.JSON from gorm.io/datatypes for flexible data structures
- The TableName() method ensures GORM maps the struct to the correct SQL table name
- You can customize the package name to match your project structure
Frequently Asked Questions
What is GORM?
GORM is a popular Go ORM (Object-Relational Mapping) library that provides a developer-friendly way to interact with databases. It supports MySQL, PostgreSQL, SQLite, and SQL Server, and offers features like auto-migration, associations, hooks, and transactions.
How are SQL types mapped to Go types?
SQL types are mapped to Go types based on their semantic meaning. For example, VARCHAR/CHAR/TEXT → string, INT/INTEGER → int, BIGINT → int64, SMALLINT → int16, TINYINT → int8, DECIMAL/NUMERIC/FLOAT/DOUBLE → float64, BOOLEAN → bool, DATETIME/TIMESTAMP/DATE → time.Time, BLOB/BINARY → []byte, JSON → datatypes.JSON.
Why are some fields pointer types?
Nullable columns (those without a NOT NULL constraint and not a primary key) are generated as pointer types (e.g., *int, *time.Time). This allows you to distinguish between a zero value and a NULL value in the database, which is important for proper data handling in Go.
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.