Using postgres adapter, how do we know if an update was successful?
update users set email='[email protected]' where id=2 (i.e. db.Table("users").Where(2).Updates(map))
If id=2 does not exist, then postgres will return "UPDATE 0".
I would consider any client using a non-existent id in an update statement to be an error. I would want to send back this error to client.
Is there any way to know the updated number of rows for an update using gorm? If updated number of rows is 0 (and client used an id to update), then we can send back an error.
Hi @satb
Thank you for your feedback, already added this support, you could get the affected columns like this:
fmt.Println(db.Table("users").Where(2).Updates(map).RowsAffected)
@jinzhu Hi, how to check errors with affected rows ?
Thanks
Hi @satb
Thank you for your feedback, already added this support, you could get the affected columns like this:
fmt.Println(db.Table("users").Where(2).Updates(map).RowsAffected)
我按照你这个写法,还是不对,返回的值永远是 0
Most helpful comment
Hi @satb
Thank you for your feedback, already added this support, you could get the affected columns like this: