transmet/news/news.go

40 lines
834 B
Go

package news
import (
"time"
"database/sql"
_ "github.com/lib/pq"
"fmt"
)
type News struct {
news_id int
Url string
Title string
Category_id int
Date time.Time
Notes string
Expoerted bool
}
func (news *News) Insert(db *sql.DB) error {
_, err := db.Exec("INSERT INTO news (url, title, category_id, notes) VALUES($1, $2, $3, $4)", news.Url, news.Title, news.Category_id, news.Notes );
if err != nil {
fmt.Println("Error inserting news: ", err)
return err
}
return nil
}
func Unexported(db *sql.DB) ([]News, error) {
res, err := db.Query("SELECT url, title, category_id, timestamp, notes FROM news WHERE exported=false")
if err != nil {
fmt.Println("DB errpr reading unexported news: ", err)
return nil, err
}
news := []News{}
return news, nil
}