fathom/models/page.go

31 lines
488 B
Go
Raw Normal View History

package models
2016-12-11 13:50:01 +00:00
import (
"database/sql"
)
type Page struct {
2016-12-11 13:50:01 +00:00
ID int64
Hostname string
Path string
Title string
}
func (p *Page) Save(conn *sql.DB) error {
2016-12-11 13:50:01 +00:00
// prepare statement for inserting data
stmt, err := conn.Prepare(`INSERT INTO pages(
hostname,
path,
title
) VALUES( ?, ?, ? )`)
2016-12-11 13:50:01 +00:00
if err != nil {
return err
}
defer stmt.Close()
2016-12-11 13:50:01 +00:00
result, err := stmt.Exec(p.Hostname, p.Path, p.Title)
p.ID, _ = result.LastInsertId()
2016-12-11 13:50:01 +00:00
return err
}