diff --git a/templates/02_hooks.tpl b/templates/02_hooks.tpl index 073c8e9..073f8ec 100644 --- a/templates/02_hooks.tpl +++ b/templates/02_hooks.tpl @@ -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}} diff --git a/templates/18_delete.tpl b/templates/18_delete.tpl index c34822e..317ae19 100644 --- a/templates/18_delete.tpl +++ b/templates/18_delete.tpl @@ -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) diff --git a/templates_test/hooks.tpl b/templates_test/hooks.tpl index 9f11698..412ab0c 100644 --- a/templates_test/hooks.tpl +++ b/templates_test/hooks.tpl @@ -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) diff --git a/templates_test/singleton/boil_suites_test.tpl b/templates_test/singleton/boil_suites_test.tpl index c1c3516..022d7be 100644 --- a/templates_test/singleton/boil_suites_test.tpl +++ b/templates_test/singleton/boil_suites_test.tpl @@ -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 -}}