This repository has been archived on 2025-03-01. You can view files and clone it, but cannot push or open issues or pull requests.
trantor/lib/database/news.go

31 lines
539 B
Go
Raw Normal View History

2014-06-29 19:41:29 -05:00
package database
import (
2014-08-30 13:17:50 -05:00
"time"
2014-06-29 19:41:29 -05:00
)
// New entry in the news table
type New struct {
ID int
2014-06-29 19:41:29 -05:00
Date time.Time
Text string
}
// AddNews creates a new entry
func (db *pgDB) AddNews(text string) error {
return db.sql.Create(&New{
Text: text,
Date: time.Now(),
})
2014-06-29 19:41:29 -05:00
}
// GetNews returns all the news for the last 'days' limiting with a maximum of 'num' results
func (db *pgDB) GetNews(num int, days int) ([]New, error) {
var news []New
err := db.sql.Model(&news).
Limit(num).
Order("date DESC").
Select()
return news, err
2014-06-29 19:41:29 -05:00
}