Refactor get item functions
This commit is contained in:
parent
2d7d48846d
commit
675cb64f47
@ -87,13 +87,8 @@ func DeactivateItem(db *DB, source string, id string) (bool, error) {
|
||||
return active, nil
|
||||
}
|
||||
|
||||
func GetAllActiveItems(db *DB) ([]Item, error) {
|
||||
rows, err := db.Query(`
|
||||
select
|
||||
source, id, created, active, title, author, body, link, time
|
||||
from items
|
||||
where active <> 0
|
||||
`)
|
||||
func getItems(db *DB, query string, args ...any) ([]Item, error) {
|
||||
rows, err := db.Query(query, args...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -109,8 +104,17 @@ func GetAllActiveItems(db *DB) ([]Item, error) {
|
||||
return items, nil
|
||||
}
|
||||
|
||||
func GetAllActiveItems(db *DB) ([]Item, error) {
|
||||
return getItems(db, `
|
||||
select
|
||||
source, id, created, active, title, author, body, link, time
|
||||
from items
|
||||
where active <> 0
|
||||
`)
|
||||
}
|
||||
|
||||
func GetActiveItemsForSource(db *DB, source string) ([]Item, error) {
|
||||
rows, err := db.Query(`
|
||||
return getItems(db, `
|
||||
select
|
||||
source, id, created, active, title, author, body, link, time
|
||||
from items
|
||||
@ -118,17 +122,4 @@ func GetActiveItemsForSource(db *DB, source string) ([]Item, error) {
|
||||
source = ?
|
||||
and active <> 0
|
||||
`, source)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var items []Item
|
||||
for rows.Next() {
|
||||
var item Item
|
||||
err = rows.Scan(&item.Source, &item.Id, &item.Created, &item.Active, &item.Title, &item.Author, &item.Body, &item.Link, &item.Time)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, item)
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user