summaryrefslogtreecommitdiff
path: root/model
diff options
context:
space:
mode:
authorxengineering <me@xengineering.eu>2024-03-03 08:49:46 +0100
committerxengineering <me@xengineering.eu>2024-03-03 13:50:58 +0100
commit55b69380ebd704477c4a37ff9b70fcb3cbdc63e5 (patch)
treea006606f559635e4a5c86e4f8a7267824824a4f5 /model
parent110f9db31a2a2b72031292558f7b1d5bab7649c3 (diff)
downloadceres-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')
-rw-r--r--model/recipe.go9
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
}