diff options
author | xengineering <me@xengineering.eu> | 2024-03-03 08:49:46 +0100 |
---|---|---|
committer | xengineering <me@xengineering.eu> | 2024-03-03 13:50:58 +0100 |
commit | 55b69380ebd704477c4a37ff9b70fcb3cbdc63e5 (patch) | |
tree | a006606f559635e4a5c86e4f8a7267824824a4f5 /model/recipe.go | |
parent | 110f9db31a2a2b72031292558f7b1d5bab7649c3 (diff) | |
download | ceres-55b69380ebd704477c4a37ff9b70fcb3cbdc63e5.tar ceres-55b69380ebd704477c4a37ff9b70fcb3cbdc63e5.tar.zst ceres-55b69380ebd704477c4a37ff9b70fcb3cbdc63e5.zip |
model: Assert one affected row on .Update()
A missing or wrong .Id field for example otherwise results in a silent
error because nothing is actually updated.
Diffstat (limited to 'model/recipe.go')
-rw-r--r-- | model/recipe.go | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/model/recipe.go b/model/recipe.go index e5cf0a6..760fe79 100644 --- a/model/recipe.go +++ b/model/recipe.go @@ -90,11 +90,18 @@ SET WHERE id = ?` - _, err := db.Exec(query, r.Title, r.Portions, r.Url, r.Notes, + res, err := db.Exec(query, r.Title, r.Portions, r.Url, r.Notes, r.Created, r.LastChanged, r.Id) if err != nil { return err } + affected, err := res.RowsAffected() + if err != nil { + return err + } + if affected != 1 { + return fmt.Errorf("Recipe update affected %d rows instead of 1", affected) + } return nil } |