sqlboiler/templates/select.tpl

19 lines
595 B
Smarty
Raw Normal View History

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 13:38:24 +01:00
{{$varName := makeGoVarName $tableName}}
var {{$varName}} {{makeGoColName $tableName}}
err := db.Select(&{{$varName}}, `
SELECT {{makeSelectParamNames $tableName .TableData}}
WHERE id=$1
`, id)
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 13:38:24 +01:00
return {{$varName}}, nil
}