Last active
August 21, 2018 05:03
-
-
Save plutov/16aa74048059f15f8800271e15e1204a to your computer and use it in GitHub Desktop.
working-with-db-nulls1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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