26 lines
527 B
Go
26 lines
527 B
Go
|
package news
|
||
|
|
||
|
import (
|
||
|
"time"
|
||
|
"database/sql"
|
||
|
_ "github.com/lib/pq"
|
||
|
"fmt"
|
||
|
)
|
||
|
|
||
|
type News struct {
|
||
|
news_id int
|
||
|
Url string
|
||
|
Title string
|
||
|
Tag_id int
|
||
|
Date time.Time
|
||
|
Description string
|
||
|
}
|
||
|
|
||
|
func (news *News) Insert(db *sql.DB) error {
|
||
|
_, err := db.Exec("INSERT INTO news (url, title, tag_id, description) VALUES($1, $2, $3, $4)", news.Url, news.Title, news.Tag_id, news.Description );
|
||
|
if err != nil {
|
||
|
fmt.Println("Error inserting news: ", err)
|
||
|
return err
|
||
|
}
|
||
|
return nil
|
||
|
}
|