Schema Classes

Schema classes define the column structure of your models. In Nimbus, your model struct is the schema — you define columns as struct fields with GORM tags for type, constraints, and JSON serialization.

Struct as schema

GORM infers column names from field names (snake_case by default). Use struct tags to override:

type User struct {
    database.Model
    Name      string `gorm:"size:255"`
    Email     string `gorm:"uniqueIndex;not null"`
    Password  string `gorm:"-"`  // ignore in DB
    Role      string `gorm:"default:user"`
}

Common GORM tags

TagDescription
primaryKeyPrimary key
uniqueIndexUnique constraint
not nullNOT NULL
default:valueDefault value
size:255Column size
column:db_nameOverride column name
-Ignore field

JSON serialization

Use json:"-" to hide sensitive fields from JSON output:

Password string `json:"-"`  // omit from JSON