in products.go [112:135]
func queryProductTypes(ctx context.Context, db *sqlx.DB, id *int) ([]ProductType, error) {
var args []interface{}
queryString := "SELECT id, name FROM product_types"
if id != nil {
queryString += " WHERE id=?"
args = append(args, *id)
}
rows, err := db.QueryContext(ctx, db.Rebind(queryString), args...)
if err != nil {
return nil, errors.Wrap(err, "querying product types")
}
defer rows.Close()
var productTypes []ProductType
for rows.Next() {
var pt ProductType
if err := rows.Scan(&pt.ID, &pt.Name); err != nil {
return nil, err
}
productTypes = append(productTypes, pt)
}
return productTypes, rows.Err()
}