2016-08-03 12:23:43 +02:00
|
|
|
{{- $tableNameSingular := .Table.Name | singular | titleCase -}}
|
|
|
|
{{- $colDefs := sqlColDefinitions .Table.Columns .Table.PKey.Columns -}}
|
|
|
|
{{- $pkNames := $colDefs.Names | stringMap .StringFuncs.camelCase -}}
|
2016-08-21 08:28:47 +02:00
|
|
|
{{- $pkArgs := joinSlices " " $pkNames $colDefs.Types | join ", " -}}
|
2016-08-03 12:23:43 +02:00
|
|
|
// {{$tableNameSingular}}Exists checks if the {{$tableNameSingular}} row exists.
|
|
|
|
func {{$tableNameSingular}}Exists(exec boil.Executor, {{$pkArgs}}) (bool, error) {
|
2016-08-08 08:07:15 +02:00
|
|
|
var exists bool
|
2016-08-03 12:23:43 +02:00
|
|
|
|
2016-09-08 23:23:10 +02:00
|
|
|
sql := `select exists(select 1 from {{schemaTable .DriverName .Schema .Table.Name}} where {{whereClause 1 .Table.PKey.Columns}} limit 1)`
|
2016-08-13 18:58:18 +02:00
|
|
|
|
|
|
|
if boil.DebugMode {
|
|
|
|
fmt.Fprintln(boil.DebugWriter, sql)
|
|
|
|
fmt.Fprintln(boil.DebugWriter, {{$pkNames | join ", "}})
|
|
|
|
}
|
|
|
|
|
2016-08-13 20:39:03 +02:00
|
|
|
row := exec.QueryRow(sql, {{$pkNames | join ", "}})
|
2016-08-03 12:23:43 +02:00
|
|
|
|
2016-08-08 08:07:15 +02:00
|
|
|
err := row.Scan(&exists)
|
2016-08-03 12:23:43 +02:00
|
|
|
if err != nil {
|
2016-08-13 20:36:03 +02:00
|
|
|
return false, errors.Wrap(err, "{{.PkgName}}: unable to check if {{.Table.Name}} exists")
|
2016-08-03 12:23:43 +02:00
|
|
|
}
|
|
|
|
|
2016-08-08 08:07:15 +02:00
|
|
|
return exists, nil
|
2016-08-03 12:23:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// {{$tableNameSingular}}ExistsG checks if the {{$tableNameSingular}} row exists.
|
|
|
|
func {{$tableNameSingular}}ExistsG({{$pkArgs}}) (bool, error) {
|
|
|
|
return {{$tableNameSingular}}Exists(boil.GetDB(), {{$pkNames | join ", "}})
|
|
|
|
}
|
|
|
|
|
|
|
|
// {{$tableNameSingular}}ExistsGP checks if the {{$tableNameSingular}} row exists. Panics on error.
|
|
|
|
func {{$tableNameSingular}}ExistsGP({{$pkArgs}}) bool {
|
|
|
|
e, err := {{$tableNameSingular}}Exists(boil.GetDB(), {{$pkNames | join ", "}})
|
|
|
|
if err != nil {
|
|
|
|
panic(boil.WrapErr(err))
|
|
|
|
}
|
|
|
|
|
|
|
|
return e
|
|
|
|
}
|
|
|
|
|
|
|
|
// {{$tableNameSingular}}ExistsP checks if the {{$tableNameSingular}} row exists. Panics on error.
|
|
|
|
func {{$tableNameSingular}}ExistsP(exec boil.Executor, {{$pkArgs}}) bool {
|
|
|
|
e, err := {{$tableNameSingular}}Exists(exec, {{$pkNames | join ", "}})
|
|
|
|
if err != nil {
|
|
|
|
panic(boil.WrapErr(err))
|
|
|
|
}
|
|
|
|
|
|
|
|
return e
|
|
|
|
}
|