aboutsummaryrefslogtreecommitdiff
path: root/database.go
diff options
context:
space:
mode:
Diffstat (limited to 'database.go')
-rw-r--r--database.go24
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)`