aboutsummaryrefslogtreecommitdiff
path: root/database.go
diff options
context:
space:
mode:
authorknotteye <knotteye@airmail.cc>2021-07-02 14:20:16 -0500
committerknotteye <knotteye@airmail.cc>2021-07-02 14:20:16 -0500
commitfaae38726dd804e3246514d88f93794c23a0cdb2 (patch)
tree4671606919340098b81c398e8478ba616a0432b1 /database.go
parentad5f4e9ff7e7ab0abab4a964cbf1626d0cdc3365 (diff)
show only the last 3 news items on index, link to a page with all news items
Diffstat (limited to 'database.go')
-rw-r--r--database.go18
1 files changed, 13 insertions, 5 deletions
diff --git a/database.go b/database.go
index 7dc7f5c..731f160 100644
--- a/database.go
+++ b/database.go
@@ -1491,15 +1491,23 @@ func MarkObjectSensitive(db *sql.DB, id string, sensitive bool) {
//if limit less than 1 return all news items
func getNewsFromDB(db *sql.DB, limit int) []NewsItem {
- news := []NewsItem
+ var news []NewsItem
+ var query string
if(limit > 0) {
- query :=`select title, content, time from newsItem order by time desc limit $1`
+ query =`select title, content, time from newsItem order by time desc limit $1`
} else {
- query :=`select title, content, time from newsItem order by time desc`
+ query =`select title, content, time from newsItem order by time desc`
}
- rows, err := db.Query(query, limit)
+ var rows *sql.Rows
+ var err error
+ if(limit > 0) {
+ rows, err = db.Query(query, limit)
+ } else {
+ rows, err = db.Query(query)
+ }
+
if CheckError(err, "could not get news from db query") != nil {
return news
@@ -1512,7 +1520,7 @@ func getNewsFromDB(db *sql.DB, limit int) []NewsItem {
if CheckError(err, "error scanning news from db") != nil {
return news
}
- append(news, n)
+ news = append(news, n)
}
return news