2016-02-23 13:38:24 +01:00
|
|
|
{{- $tableName := .TableName -}}
|
|
|
|
func Select{{makeGoColName $tableName}}(id int, db *sqlx.DB) ({{makeGoColName $tableName}}, error) {
|
|
|
|
if id == 0 {
|
|
|
|
return nil, errors.New("No ID provided for {{makeGoColName $tableName}} select")
|
2016-02-23 09:27:32 +01:00
|
|
|
}
|
2016-02-23 13:38:24 +01:00
|
|
|
{{$varName := makeGoVarName $tableName}}
|
|
|
|
var {{$varName}} {{makeGoColName $tableName}}
|
|
|
|
err := db.Select(&{{$varName}}, `
|
|
|
|
SELECT {{makeSelectParamNames $tableName .TableData}}
|
|
|
|
WHERE id=$1
|
|
|
|
`, id)
|
2016-02-23 09:27:32 +01:00
|
|
|
|
|
|
|
if err != nil {
|
2016-02-23 13:38:24 +01:00
|
|
|
return nil, fmt.Errorf("Unable to select from {{$tableName}}: %s", err)
|
2016-02-23 09:27:32 +01:00
|
|
|
}
|
|
|
|
|
2016-02-23 13:38:24 +01:00
|
|
|
return {{$varName}}, nil
|
2016-02-23 09:27:32 +01:00
|
|
|
}
|