GORM in Golang: Structs to Database Tables Made Easy | Go Tutorial #34
34views
1likes
2comments
19:23
T
Taught by Celeste AI - AI Coding Coach
View on YouTubeDescription
Learn GORM, the most popular ORM for Go! Map Go structs to database tables automatically using gorm.io/gorm with a pure Go SQLite driver —
no CGO required.
📚 What you'll learn:
- `gorm.Open(sqlite.Open("file.db"))` to connect
- `gorm.Model` for auto ID, CreatedAt, UpdatedAt, DeletedAt
- `db.AutoMigrate(&User{})` to create tables from structs
- `db.Create(&user)` with auto-populated ID
- `db.First(&user, 1)` and `db.Find(&users)` for queries
- `db.Model().Update()` and `db.Model().Updates()` for modifications
- Soft delete with `db.Delete()` and `db.Unscoped()` for recovery
- `db.Where("done = ?", true).Find()` for filtered queries
- Has Many / Belongs To associations with `UserID` convention
- `db.Preload("Posts").First()` for eager loading
- Nested create: user with posts in one call
- `BeforeCreate` / `AfterCreate` lifecycle hooks
- Scopes: reusable query filters like `Expensive` and `NotDiscounted`
- `db.Raw()` and `db.Exec()` for raw SQL when needed
- `db.Transaction()` with automatic rollback on error
⏱️ Timestamps:
0:00 - Introduction
0:30 - GORM Basics (Connect, AutoMigrate, Create, Find)
3:44 - CRUD Operations (Update, Delete, Soft Delete, Unscoped)
8:19 - Associations (Has Many, Belongs To, Preload)
12:32 - Advanced Features (Hooks, Scopes, Raw SQL, Transactions)
18:12 - Recap
18:42 - Up Next: REST API
💻 Code: https://github.com/GoCelesteAI/go_gorm_orm
Back to tutorialsOpen in YouTube
Duration
19:23
Published
February 6, 2026
Added to Codegiz
March 15, 2026