Fixed code generation

This commit is contained in:
Sergey Kurt 2017-03-15 19:04:13 +03:00
parent bfab02bde1
commit ad15668462
4 changed files with 16 additions and 5 deletions

View file

@ -4,7 +4,7 @@
var {{$varNameSingular}}BeforeInsertHooks []{{$tableNameSingular}}Hook
var {{$varNameSingular}}BeforeUpdateHooks []{{$tableNameSingular}}Hook
var {{$varNameSingular}}BeforeDeleteHooks []{{$tableNameSingular}}Hook
{{- if ne .DriverName "mssql" -}}
{{if ne .DriverName "mssql" -}}
var {{$varNameSingular}}BeforeUpsertHooks []{{$tableNameSingular}}Hook
{{- end}}
@ -12,7 +12,7 @@ var {{$varNameSingular}}AfterInsertHooks []{{$tableNameSingular}}Hook
var {{$varNameSingular}}AfterSelectHooks []{{$tableNameSingular}}Hook
var {{$varNameSingular}}AfterUpdateHooks []{{$tableNameSingular}}Hook
var {{$varNameSingular}}AfterDeleteHooks []{{$tableNameSingular}}Hook
{{- if ne .DriverName "mssql" -}}
{{if ne .DriverName "mssql" -}}
var {{$varNameSingular}}AfterUpsertHooks []{{$tableNameSingular}}Hook
{{- end}}
@ -140,7 +140,7 @@ func Add{{$tableNameSingular}}Hook(hookPoint boil.HookPoint, {{$varNameSingular}
{{$varNameSingular}}AfterUpdateHooks = append({{$varNameSingular}}AfterUpdateHooks, {{$varNameSingular}}Hook)
case boil.AfterDeleteHook:
{{$varNameSingular}}AfterDeleteHooks = append({{$varNameSingular}}AfterDeleteHooks, {{$varNameSingular}}Hook)
{{- if ne .DriverName "mssql" -}}
{{if ne .DriverName "mssql" -}}
case boil.AfterUpsertHook:
{{$varNameSingular}}AfterUpsertHooks = append({{$varNameSingular}}AfterUpsertHooks, {{$varNameSingular}}Hook)
{{- end}}

View file

@ -135,11 +135,22 @@ func (o {{$tableNameSingular}}Slice) DeleteAll(exec boil.Executor) error {
args = append(args, pkeyArgs...)
}
{{if ne .DriverName "mssql" -}}
sql := fmt.Sprintf(
"DELETE 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 := "DELETE FROM {{$schemaTable}} WHERE " +
strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), startIndex, {{$varNameSingular}}PrimaryKeyColumns, len(o))
{{- end}}
if boil.DebugMode {
fmt.Fprintln(boil.DebugWriter, sql)

View file

@ -126,7 +126,7 @@ func test{{$tableNamePlural}}Hooks(t *testing.T) {
}
{{$varNameSingular}}AfterDeleteHooks = []{{$tableNameSingular}}Hook{}
{{- if ne .DriverName "mssql" -}}
{{if ne .DriverName "mssql" -}}
Add{{$tableNameSingular}}Hook(boil.BeforeUpsertHook, {{$varNameSingular}}BeforeUpsertHook)
if err = o.doBeforeUpsertHooks(nil); err != nil {
t.Errorf("Unable to execute doBeforeUpsertHooks: %s", err)

View file

@ -327,7 +327,7 @@ func TestSliceUpdateAll(t *testing.T) {
{{end -}}
{{- end -}}
}
{{- if ne .DriverName "mssql" -}}
{{if ne .DriverName "mssql" -}}
func TestUpsert(t *testing.T) {
{{- range $index, $table := .Tables}}
{{- if $table.IsJoinTable -}}