Slide 10
Slide 10 text
// UserAccount represents public.user_account
type UserAccount struct {
ID int64 // id
Email string // email
LastName string // last_name
FirstName string // first_name
}
// Create inserts the UserAccount to the database.
func (r *UserAccount) Create(db Queryer) error {
err := db.QueryRow(
`INSERT INTO user_account (email, last_name, first_name) VALUES ($1, $2,
$3) RETURNING id`,
&r.Email, &r.LastName, &r.FirstName).Scan(&r.ID)
if err != nil {
return errors.Wrap(err, "failed to insert user_account")
}
return nil
}
// GetUserAccountByPk select the UserAccount from the database.
func GetUserAccountByPk(db Queryer, pk0 int64) (*UserAccount, error) {
var r UserAccount
err := db.QueryRow(
`SELECT id, email, last_name, first_name FROM user_account WHERE id = $1`,
pk0).Scan(&r.ID, &r.Email, &r.LastName, &r.FirstName)
if err != nil {
return nil, errors.Wrap(err, "failed to select user_account")
}
return &r, nil
}