Initial commit
This commit is contained in:
29
pkg/repo/guestbook.go
Normal file
29
pkg/repo/guestbook.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package repo
|
||||
|
||||
import (
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
)
|
||||
|
||||
type Guestbook struct {
|
||||
PageviewId int64 `json:"pageviewId"`
|
||||
FirstName string `json:"firstName" validate:"required"`
|
||||
LastName string `json:"lastName" validate:"required"`
|
||||
EmailAddress string `json:"emailAddress" validate:"required"`
|
||||
Message string `json:"message"`
|
||||
}
|
||||
|
||||
func AddGuestbook(entry Guestbook) (int64, error) {
|
||||
db := getDB()
|
||||
|
||||
result, err := db.Exec("INSERT INTO guestbook (first_name, last_name, email_address, message, pageview_id) VALUES (?, ?, ?, ?, ?)", entry.FirstName, entry.LastName, entry.EmailAddress, entry.Message, entry.PageviewId)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
id, err := result.LastInsertId()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return id, nil
|
||||
}
|
||||
Reference in New Issue
Block a user