mirror of
https://github.com/empayre/fleet.git
synced 2024-11-07 17:28:54 +00:00
f4bee00b01
Closes issue #1390 There were quite a few places where UPDATES could fail silently because we weren't checking target rows where actually found where we expect them to be. In order to address this problem clientFoundRows was set in the sql driver configuration and checks for UPDATES were added to determine if matched rows were found where we expect them to be.
25 lines
494 B
Go
25 lines
494 B
Go
package mysql
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/pkg/errors"
|
|
)
|
|
|
|
func (d *Datastore) deleteEntity(dbTable string, id uint) error {
|
|
deleteStmt := fmt.Sprintf(
|
|
`
|
|
UPDATE %s SET deleted_at = ?, deleted = TRUE
|
|
WHERE id = ? AND NOT deleted
|
|
`, dbTable)
|
|
result, err := d.db.Exec(deleteStmt, d.clock.Now(), id)
|
|
if err != nil {
|
|
return errors.Wrap(err, fmt.Sprintf("delete %s", dbTable))
|
|
}
|
|
rows, _ := result.RowsAffected()
|
|
if rows != 1 {
|
|
return notFound(dbTable).WithID(id)
|
|
}
|
|
return nil
|
|
}
|