mirror of
https://github.com/miniflux/v2.git
synced 2025-08-01 17:38:37 +00:00
Check for category uniqueness before saving
This commit is contained in:
parent
5983db1a77
commit
238b9e4c85
10 changed files with 47 additions and 12 deletions
|
@ -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))
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue