Skip to Content

gofasta g model

Generates a GORM database model file with the specified fields and types. The model includes standard fields (ID, CreatedAt, UpdatedAt, DeletedAt) automatically, plus any custom fields you define.

Use this command when you need only the model without the full scaffold. For a complete resource with all layers, use gofasta g scaffold instead.

Usage

gofasta g model <ModelName> [field:type ...] [flags]

Flags

FlagShortDefaultDescription
--table-tpluralized model nameOverride the database table name

Field Types

TypeGo TypeGORM Tag
stringstringtype:varchar(255);not null
textstringtype:text
intinttype:integer;not null
floatfloat64type:decimal(10,2);not null
boolbooltype:boolean;default:false
uuiduuid.UUIDtype:uuid
timetime.Timetype:timestamp

Examples

Generate a Product model:

gofasta g model Product name:string price:float

Generate a model with multiple field types:

gofasta g model Article title:string body:text published:bool view_count:int

Generate with a custom table name:

gofasta g model UserProfile bio:text avatar_url:string --table profiles

What It Generates

Running gofasta g model Product name:string price:float creates one file:

app/models/product.model.go

Generated Code

// app/models/product.model.go package models import ( "time" "github.com/google/uuid" "gorm.io/gorm" ) type Product struct { ID uuid.UUID `gorm:"type:uuid;primary_key;default:gen_random_uuid()" json:"id"` Name string `gorm:"type:varchar(255);not null" json:"name"` Price float64 `gorm:"type:decimal(10,2);not null" json:"price"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` DeletedAt gorm.DeletedAt `gorm:"index" json:"deleted_at,omitempty"` }

The model automatically includes:

  • A UUID primary key with auto-generation
  • CreatedAt and UpdatedAt timestamps managed by GORM
  • DeletedAt for soft deletes with an index
  • JSON tags using snake_case naming
  • GORM tags for column type definitions

Database Driver Compatibility

Field type mappings adapt automatically based on the database driver configured in config/config.yaml:

Field TypePostgresMySQLSQLiteSQL ServerClickHouse
stringVARCHAR(255)VARCHAR(255)TEXTNVARCHAR(255)String
textTEXTLONGTEXTTEXTNVARCHAR(MAX)String
intINTEGERINTINTEGERINTInt64
floatDECIMAL(10,2)DECIMAL(10,2)REALDECIMAL(10,2)Float64
boolBOOLEANTINYINT(1)INTEGERBITUInt8
uuidUUIDCHAR(36)TEXTUNIQUEIDENTIFIERUUID
timeTIMESTAMPDATETIMEDATETIMEDATETIME2DateTime
Last updated on