MS SQL compatible query for checks if the row exists

This commit is contained in:
Sergey Kurt 2017-03-14 13:53:35 +03:00
parent 83d90f3f28
commit ed6dad7eed

View file

@ -6,8 +6,11 @@
// {{$tableNameSingular}}Exists checks if the {{$tableNameSingular}} row exists.
func {{$tableNameSingular}}Exists(exec boil.Executor, {{$pkArgs}}) (bool, error) {
var exists bool
{{if eq .DriverName "mssql" -}}
sql := "select case when exists(select top(1) 1 from {{$schemaTable}} where {{if .Dialect.IndexPlaceholders}}{{whereClause .LQ .RQ 1 .Table.PKey.Columns}}{{else}}{{whereClause .LQ .RQ 0 .Table.PKey.Columns}}{{end}}) then 1 else 0 end"
{{- else -}}
sql := "select exists(select 1 from {{$schemaTable}} where {{if .Dialect.IndexPlaceholders}}{{whereClause .LQ .RQ 1 .Table.PKey.Columns}}{{else}}{{whereClause .LQ .RQ 0 .Table.PKey.Columns}}{{end}} limit 1)"
{{- end}}
if boil.DebugMode {
fmt.Fprintln(boil.DebugWriter, sql)