From 5feb32a122680fd8d5bb322b820cff8cc0af5860 Mon Sep 17 00:00:00 2001 From: Garritt McCune Date: Thu, 9 Sep 2021 15:15:05 -0500 Subject: [PATCH] Quick cleanup on a few bits of code, also added some places where a transaction rollback was missed. --- category.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/category.go b/category.go index 81bd25b..a3ef7a8 100644 --- a/category.go +++ b/category.go @@ -2,7 +2,6 @@ package main import ( "context" - "fmt" ) type Category struct { @@ -68,6 +67,7 @@ func insertNewCategory(name string, subcategories []Subcategory) (recordID int64 statement, err := transaction.Prepare("INSERT INTO category (category_name) VALUES ($1) RETURNING category_id;") if err != nil { + transaction.Rollback() println(err.Error()) return 0, false } @@ -93,6 +93,7 @@ func insertNewCategory(name string, subcategories []Subcategory) (recordID int64 statement, err := transaction.Prepare("INSERT INTO subcategory(subcategory_name, category_id) VALUES($1, $2);") if err != nil { + transaction.Rollback() println(err.Error()) return 0, false } @@ -100,7 +101,7 @@ func insertNewCategory(name string, subcategories []Subcategory) (recordID int64 defer statement.Close() for _, subcategory := range subcategories { - println(fmt.Sprintf("For cat %d, add sub '%s'.", recordID, subcategory.Name)) + _, err := statement.Exec(subcategory.Name, recordID) if err != nil {