sqlboiler/cmds/templates/fieldsall.tpl
Patrick O'brien 195e8d16e8 Broke up all commands into individual templates.
* Added bunch of new command names and descriptions.
* Changed "all" command to "boil", so we can use "all"
  for the name of the all database select helper.
2016-02-29 21:45:28 +10:00

15 lines
684 B
Smarty

{{- $tableName := .TableName -}}
// {{makeGoColName $tableName}}FieldsAll retrieves the specified columns for all records.
// Pass in a pointer to an object with `db` tags that match the column names you wish to retrieve.
// For example: friendName string `db:"friend_name"`
func {{makeGoColName $tableName}}FieldsAll(db *sqlx.DB, results interface{}) error {
{{$varName := makeGoVarName $tableName -}}
var {{$varName}} []*{{makeGoColName $tableName}}
err := db.Select(&{{$varName}}, `SELECT {{makeSelectParamNames $tableName .TableData}}`)
if err != nil {
return nil, fmt.Errorf("models: unable to select from {{$tableName}}: %s", err)
}
return {{$varName}}, nil
}