MS SQL compatible query for checks if the row exists
This commit is contained in:
parent
83d90f3f28
commit
ed6dad7eed
1 changed files with 4 additions and 1 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Reference in a new issue