diff options
author | knotteye <knotteye@airmail.cc> | 2021-07-01 20:26:49 -0500 |
---|---|---|
committer | knotteye <knotteye@airmail.cc> | 2021-07-01 20:26:49 -0500 |
commit | 168225daa21fe494bcd74ab6c90d6498ecf9f1e3 (patch) | |
tree | 65274dc8181e7c1805fb601f3674f6d357b5dc80 /database.go | |
parent | 4e3848cadbb3fd89b94a7ef24838173939d198db (diff) |
Make news list links to full page news articles
Diffstat (limited to 'database.go')
-rw-r--r-- | database.go | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/database.go b/database.go index 5fcebf0..037fde2 100644 --- a/database.go +++ b/database.go @@ -1504,6 +1504,9 @@ func getNewsFromDB(db *sql.DB) []NewsItem { for rows.Next() { n := NewsItem{} err = rows.Scan(&n.Title, &n.Content, &n.Time) + if CheckError(err, "error scanning news from db") != nil { + return make([]NewsItem, 0) + } news.PushBack(n) } @@ -1519,6 +1522,27 @@ func getNewsFromDB(db *sql.DB) []NewsItem { return anews } +func getNewsItemFromDB(db *sql.DB, timestamp int) (NewsItem, error) { + var news NewsItem + query := `select title, content, time from newsItem where time=$1 limit 1` + + rows, err := db.Query(query, timestamp) + + if err != nil { + return news, err + } + + defer rows.Close() + rows.Next() + err = rows.Scan(&news.Title, &news.Content, &news.Time) + + if err != nil { + return news, err + } + + return news, nil +} + func WriteNewsToDB(db *sql.DB, news NewsItem) { query := `insert into newsItem (title, content, time) values ($1, $2, $3)` |