30 lines
539 B
Go
30 lines
539 B
Go
package database
|
|
|
|
import (
|
|
"time"
|
|
)
|
|
|
|
// New entry in the news table
|
|
type New struct {
|
|
ID int
|
|
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(),
|
|
})
|
|
}
|
|
|
|
// 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
|
|
}
|