2016-12-08 17:44:49 +00:00
|
|
|
package models
|
|
|
|
|
2016-12-08 21:20:40 +00:00
|
|
|
import (
|
|
|
|
"database/sql"
|
|
|
|
)
|
|
|
|
|
2016-12-08 17:44:49 +00:00
|
|
|
type User struct {
|
2016-12-08 21:20:40 +00:00
|
|
|
ID int64
|
2016-12-08 17:44:49 +00:00
|
|
|
Email string
|
2016-12-08 21:20:40 +00:00
|
|
|
Password string `json:"-"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (u *User) Save(conn *sql.DB) error {
|
|
|
|
// prepare statement for inserting data
|
|
|
|
stmt, err := conn.Prepare(`INSERT INTO users(
|
|
|
|
email,
|
|
|
|
password
|
|
|
|
) VALUES(?, ?)`)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer stmt.Close()
|
|
|
|
|
|
|
|
result, err := stmt.Exec(u.Email, u.Password)
|
|
|
|
u.ID, _ = result.LastInsertId()
|
|
|
|
|
|
|
|
return err
|
2016-12-08 17:44:49 +00:00
|
|
|
}
|