summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTucker Evans <tuckerevans24@gmail.com>2019-11-12 09:51:17 -0500
committerTucker Evans <tuckerevans24@gmail.com>2019-11-12 09:51:17 -0500
commit9e81f2af7f4c0130217658c4c2fc73f8a933e183 (patch)
tree498d9eaaeedccb758585f246149524672ddfb64e
parent16e187899c1cd008a5d36d4ac772a7bbc854e165 (diff)
Add id to ingredients so we can delete unused on update
When updating ingredients if some # are remove we need to remove the same number from the database and update the rest, without an id column we don't know which ones to delete.
-rw-r--r--backend/recipe.go6
1 files changed, 4 insertions, 2 deletions
diff --git a/backend/recipe.go b/backend/recipe.go
index fc34ba7..ab1b631 100644
--- a/backend/recipe.go
+++ b/backend/recipe.go
@@ -100,6 +100,7 @@ func RecipeFromId(id int, db *sql.DB) *Recipe {
id)
defer rows_ingr.Close()
if err == nil {
+ var i int
for rows_ingr.Next() {
rows_ingr.Scan(&name, &amount, &unit)
ingr = Ingredient{
@@ -164,8 +165,9 @@ func AddRecipeDB(r *Recipe, db *sql.DB) error {
for i, ingr := range r.Ingredients {
res, err := db.Exec(`INSERT INTO ingredients
- (name, amount, unit, recipe_id)
- VALUES ($1, $2, $3, $4)`,
+ (id, name, amount, unit, recipe_id)
+ VALUES ($1, $2, $3, $4, $5)`,
+ i,
ingr.Name,
ingr.Amount,
ingr.Unit,