SQL to GORM Model Generator

Convert SQL CREATE TABLE statements to Go GORM model struct definitions with proper tags, type mapping, and TableName methods.

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

  1. Set the package name (default: "model")
  2. Toggle options: GORM tags, JSON tags, and TableName() method
  3. Paste your SQL CREATE TABLE statements into the input area
  4. Click "Generate GORM Model" to create the Go struct definitions
  5. Copy the output and save it as a .go file in your Go project

Why Use This Tool?

Automatically map SQL types to Go types (VARCHAR → string, BIGINT → int64, etc.)
Generate GORM struct tags with column name, type, constraints, and defaults
Nullable columns use pointer types (*int, *time.Time) for proper null handling
JSON tags for seamless API serialization with standard library encoding/json

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.

Related Tools