Fixed code generation for Update and Reload
This commit is contained in:
parent
f45f98ef03
commit
4c2062caee
2 changed files with 23 additions and 1 deletions
|
@ -157,12 +157,23 @@ func (o {{$tableNameSingular}}Slice) UpdateAll(exec boil.Executor, cols M) error
|
|||
pkeyArgs := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(obj)), {{$varNameSingular}}PrimaryKeyMapping)
|
||||
args = append(args, pkeyArgs...)
|
||||
}
|
||||
|
||||
{{if ne .DriverName "mssql" -}}
|
||||
sql := fmt.Sprintf(
|
||||
"UPDATE {{$schemaTable}} SET %s WHERE ({{.LQ}}{{.Table.PKey.Columns | join (printf "%s,%s" .LQ .RQ)}}{{.RQ}}) IN (%s)",
|
||||
strmangle.SetParamNames("{{.LQ}}", "{{.RQ}}", {{if .Dialect.IndexPlaceholders}}1{{else}}0{{end}}, colNames),
|
||||
strmangle.Placeholders(dialect.IndexPlaceholders, len(o) * len({{$varNameSingular}}PrimaryKeyColumns), len(colNames)+1, len({{$varNameSingular}}PrimaryKeyColumns)),
|
||||
)
|
||||
{{- else -}}
|
||||
startIndex := len(colNames) + 1
|
||||
|
||||
if !dialect.IndexPlaceholders {
|
||||
startIndex = 0
|
||||
}
|
||||
|
||||
sql := fmt.Sprintf("UPDATE {{$schemaTable}} SET %s WHERE %s",
|
||||
strmangle.SetParamNames("{{.LQ}}", "{{.RQ}}", {{if .Dialect.IndexPlaceholders}}1{{else}}0{{end}}, colNames),
|
||||
strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), startIndex, {{$varNameSingular}}PrimaryKeyColumns, len(o)))
|
||||
{{- end}}
|
||||
|
||||
if boil.DebugMode {
|
||||
fmt.Fprintln(boil.DebugWriter, sql)
|
||||
|
|
|
@ -79,11 +79,22 @@ func (o *{{$tableNameSingular}}Slice) ReloadAll(exec boil.Executor) error {
|
|||
args = append(args, pkeyArgs...)
|
||||
}
|
||||
|
||||
{{if ne .DriverName "mssql" -}}
|
||||
sql := fmt.Sprintf(
|
||||
"SELECT {{$schemaTable}}.* FROM {{$schemaTable}} WHERE (%s) IN (%s)",
|
||||
strings.Join(strmangle.IdentQuoteSlice(dialect.LQ, dialect.RQ, {{$varNameSingular}}PrimaryKeyColumns), ","),
|
||||
strmangle.Placeholders(dialect.IndexPlaceholders, len(*o) * len({{$varNameSingular}}PrimaryKeyColumns), 1, len({{$varNameSingular}}PrimaryKeyColumns)),
|
||||
)
|
||||
{{- else -}}
|
||||
startIndex := 1
|
||||
|
||||
if !dialect.IndexPlaceholders {
|
||||
startIndex = 0
|
||||
}
|
||||
|
||||
sql := "SELECT {{$schemaTable}}.* FROM {{$schemaTable}} WHERE " +
|
||||
strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), startIndex, {{$varNameSingular}}PrimaryKeyColumns, len(*o))
|
||||
{{- end}}
|
||||
|
||||
q := queries.Raw(exec, sql, args...)
|
||||
|
||||
|
|
Loading…
Reference in a new issue