Is there way to do something like this?
userID := int64(2941)
var user User
if err := DB.Where(&User{ID: userID}).First(&user).Error; err != nil {
log.Fatalf("In %s: Failed to load user %v from SQL. Error (%v)", C.FuncPrint(), userID, err)
}
// log.Printf("%d", user.Balance)
// 1000
updatebalance := map[string]interface{}{"balance": gorm.Expr("balance + ?", 1000)}
if err := DB.Model(user).UpdateColumns(updatebalance).Error; err != nil {
log.Fatal(err)
}
Is there any way to get user.Balance updated to new value (returning) without re-selecting the object?
refer https://github.com/jinzhu/gorm#batch-updates
Is it possible to obtain IDs of the updated rows in one query? smth like this:
UPDATE table SET column = 'new value' WHERE column = 'old value' RETURNING table.id
Thanks!
Most helpful comment
Is it possible to obtain IDs of the updated rows in one query? smth like this:
UPDATE table SET column = 'new value' WHERE column = 'old value' RETURNING table.idThanks!