Models and AutoMigrate
Define and migrate schema.
What Is GORM
GORM is the most popular ORM for Go. It maps Go structs to database tables so you work with objects instead of raw SQL. It supports PostgreSQL, MySQL, SQLite, and more.
- Struct-to-table mapping
- Automatic migrations
- Associations and hooks
Defining a Model
A model is a Go struct. Each exported field becomes a column. Embedding gorm.Model adds ID, CreatedAt, UpdatedAt, and DeletedAt fields.
type User struct {
gorm.Model
Name string
Email string
Age int
}All lessons in this course
- Models and AutoMigrate
- CRUD Operations
- Associations
- Hooks and Scopes