26 lines
524 B
Go
26 lines
524 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
|
|
}
|
|
|
|
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
|
|
} |