Skip to content

Instantly share code, notes, and snippets.

@plutov
Last active August 21, 2018 05:03
Show Gist options
  • Save plutov/16aa74048059f15f8800271e15e1204a to your computer and use it in GitHub Desktop.
Save plutov/16aa74048059f15f8800271e15e1204a to your computer and use it in GitHub Desktop.
working-with-db-nulls1
type Customer struct {
ID int
Email string
Phone string
Age int
}
func GetCustomerByEmail(db *sql.DB, email string) (*Customer, error) {
stmt, err := db.Prepare("SELECT id, email, phone, age FROM customer where email = ?")
if err != nil {
return nil, err
}
defer stmt.Close()
customer := new(Customer)
if err = stmt.QueryRow(email).Scan(&customer.ID, &customer.Email, &customer.Phone, &customer.Age); err != nil {
return nil, err
}
return customer, nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment