GORM Update data

// Update user with ID 1, set the name to "John Doe" and age to 30
db.Model(&User{}).Where("id = ?", 1).Updates(User{Name: "John Doe", Age: 30})

Explanation:

  • db.Model(&User{}): Specifies the model (User struct) to be used for the database operation.
  • .Where("id = ?", 1): Specifies the condition for the update operation. In this case, it targets the user with an ID of 1.
  • .Updates(User{Name: "John Doe", Age: 30}): Performs the update operation on the selected user, setting the Name field to "John Doe" and the Age field to 30.