CRUD Operations
Create, read, update, delete.
CRUD with GORM
GORM turns the four basic operations, Create, Read, Update, Delete, into method calls on *gorm.DB. You pass pointers to structs and GORM builds the SQL.
Create
Create inserts a record. After it runs, GORM fills the structs primary key and timestamps from the database.
user := User{Name: "Ada", Email: "ada@example.com"}
result := db.Create(&user)
fmt.Println(user.ID, result.RowsAffected)All lessons in this course
- Models and AutoMigrate
- CRUD Operations
- Associations
- Hooks and Scopes