diff options
author | Frédéric Guillot <fred@miniflux.net> | 2017-11-21 14:57:27 -0800 |
---|---|---|
committer | Frédéric Guillot <fred@miniflux.net> | 2017-11-21 14:57:27 -0800 |
commit | 238b9e4c8594b8846b3cd9a24702a2299581a0a1 (patch) | |
tree | e2fc2898cde61d3ae9dc0d6f23ef578010159443 /storage | |
parent | 5983db1a770e458c4ecbbe9a4a2df70f0ebc0d9a (diff) |
Check for category uniqueness before saving
Diffstat (limited to 'storage')
-rw-r--r-- | storage/category.go | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/storage/category.go b/storage/category.go index 3d08c4d..e1986b7 100644 --- a/storage/category.go +++ b/storage/category.go @@ -8,11 +8,21 @@ import ( "database/sql" "errors" "fmt" + "time" + "github.com/miniflux/miniflux2/helper" "github.com/miniflux/miniflux2/model" - "time" ) +func (s *Storage) AnotherCategoryExists(userID, categoryID int64, title string) bool { + defer helper.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:AnotherCategoryExists] userID=%d, categoryID=%d, title=%s", userID, categoryID, title)) + + var result int + query := `SELECT count(*) as c FROM categories WHERE user_id=$1 AND id != $2 AND title=$3` + s.db.QueryRow(query, userID, categoryID, title).Scan(&result) + return result >= 1 +} + func (s *Storage) CategoryExists(userID, categoryID int64) bool { defer helper.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:CategoryExists] userID=%d, categoryID=%d", userID, categoryID)) |