Add more template functions.

- Fix some quoting nonsense in another template.
This commit is contained in:
Aaron L 2016-06-25 20:19:13 -07:00
parent 642069645b
commit c6740529df
2 changed files with 5 additions and 3 deletions

View file

@ -106,8 +106,9 @@ var templateStringMappers = map[string]func(string) string{
var templateFunctions = template.FuncMap{
// String ops
"substring": strmangle.Substring,
"remove": func(rem string, str string) string { return strings.Replace(str, rem, "", -1) },
"prefix": func(add string, str string) string { return fmt.Sprintf("%s%s", add, str) },
"remove": func(rem, str string) string { return strings.Replace(str, rem, "", -1) },
"replace": func(rep, with, str string) string { return strings.Replace(str, rep, with, -1) },
"prefix": func(add, str string) string { return fmt.Sprintf("%s%s", add, str) },
"quoteWrap": func(a string) string { return fmt.Sprintf(`"%s"`, a) },
// Pluralization
@ -138,4 +139,5 @@ var templateFunctions = template.FuncMap{
"sqlColDefinitions": bdb.SQLColDefinitions,
"sqlColDefStrings": bdb.SQLColDefStrings,
"columnNames": bdb.ColumnNames,
"toManyRelationships": bdb.ToManyRelationships,
}

View file

@ -12,7 +12,7 @@
func ({{$receiver}} *{{$localTable}}) {{$foreignColumn}}(exec boil.Executor, selectCols ...string) (*{{$foreignTable}}, error) {
{{$varname}} := &{{$foreignTable}}{}
query := fmt.Sprintf(`select %s from {{.ForeignTable}} where id = $1`, strings.Join(selectCols, `,`))
query := fmt.Sprintf(`select "%s" from {{.ForeignTable}} where id = $1`, strings.Join(selectCols, `","`))
err := exec.QueryRow(query, {{$receiver}}.{{titleCase .Column}}).Scan(boil.GetStructPointers({{$varname}}, selectCols...)...)
if err != nil {
return nil, fmt.Errorf(`{{$pkg}}: unable to select from {{.ForeignTable}}: %v`, err)