Fix where clause so it outputs quotes.

- Fix templates that this change broke
This commit is contained in:
Aaron L 2016-06-25 20:17:39 -07:00
parent c7eafa4e08
commit 49d3260dcd
5 changed files with 11 additions and 11 deletions

View file

@ -121,17 +121,17 @@ func GenerateParamFlags(colCount int, startAt int) string {
// WhereClause returns the where clause using start as the $ flag index
// For example, if start was 2 output would be: "colthing=$2 AND colstuff=$3"
func WhereClause(pkeyCols []string, start int) string {
func WhereClause(cols []string, start int) string {
if start == 0 {
panic("0 is not a valid start number for whereClause")
}
cols := make([]string, len(pkeyCols))
for i, c := range pkeyCols {
cols[i] = fmt.Sprintf("%s=$%d", c, start+i)
ret := make([]string, len(cols))
for i, c := range cols {
ret[i] = fmt.Sprintf(`"%s"=$%d`, c, start+i)
}
return strings.Join(cols, " AND ")
return strings.Join(ret, " AND ")
}
// DriverUsesLastInsertID returns whether the database driver supports the

View file

@ -148,9 +148,9 @@ func TestWhereClause(t *testing.T) {
Start int
Should string
}{
{Cols: []string{"col1"}, Start: 2, Should: "col1=$2"},
{Cols: []string{"col1", "col2"}, Start: 4, Should: "col1=$4 AND col2=$5"},
{Cols: []string{"col1", "col2", "col3"}, Start: 4, Should: "col1=$4 AND col2=$5 AND col3=$6"},
{Cols: []string{"col1"}, Start: 2, Should: `"col1"=$2`},
{Cols: []string{"col1", "col2"}, Start: 4, Should: `"col1"=$4 AND "col2"=$5`},
{Cols: []string{"col1", "col2", "col3"}, Start: 4, Should: `"col1"=$4 AND "col2"=$5 AND "col3"=$6`},
}
for i, test := range tests {

View file

@ -12,7 +12,7 @@ func {{$tableNameSingular}}FindX(exec boil.Executor, {{sqlColDefinitions .Table.
mods := []qm.QueryMod{
qm.Select(selectCols...),
qm.Table("{{.Table.Name}}"),
qm.Where("{{whereClause .Table.PKey.Columns 1}}", {{.Table.PKey.Columns | stringMap .StringFuncs.camelCase | join ", "}}),
qm.Where(`{{whereClause .Table.PKey.Columns 1}}`, {{.Table.PKey.Columns | stringMap .StringFuncs.camelCase | join ", "}}),
}
q := NewQueryX(exec, mods...)

View file

@ -19,7 +19,7 @@ func (o *{{$tableNameSingular}}) DeleteX(exec boil.Executor) error {
mods = append(mods,
qm.Table("{{.Table.Name}}"),
qm.Where("{{whereClause .Table.PKey.Columns 1}}", {{.Table.PKey.Columns | stringMap .StringFuncs.titleCase | prefixStringSlice "o." | join ", "}}),
qm.Where(`{{whereClause .Table.PKey.Columns 1}}`, {{.Table.PKey.Columns | stringMap .StringFuncs.titleCase | prefixStringSlice "o." | join ", "}}),
)
query := NewQueryX(exec, mods...)

View file

@ -19,7 +19,7 @@ func Test{{$tableNamePlural}}Bind(t *testing.T) {
j := {{$tableNameSingular}}{}
err = {{$tableNamePlural}}(qm.Where("{{whereClause .Table.PKey.Columns 1}}", {{.Table.PKey.Columns | stringMap .StringFuncs.titleCase | prefixStringSlice "o." | join ", "}})).Bind(&j)
err = {{$tableNamePlural}}(qm.Where(`{{whereClause .Table.PKey.Columns 1}}`, {{.Table.PKey.Columns | stringMap .StringFuncs.titleCase | prefixStringSlice "o." | join ", "}})).Bind(&j)
if err != nil {
t.Errorf("Unable to call Bind on {{$tableNameSingular}} single object: %s", err)
}