From ca4aba1ac4ddcabfa6b5a5c75ecfa89618819672 Mon Sep 17 00:00:00 2001 From: MJacred Date: Mon, 26 Sep 2022 16:52:01 +0200 Subject: [PATCH] Allow calling struct.Exists() without having to pass on PK fields For when having a helper interface that has Insert(), Update(), Upsert(). Upsert() is not always possible. Knowing that the record exists helps to decide between Insert() and Update(). --- templates/main/20_exists.go.tpl | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/templates/main/20_exists.go.tpl b/templates/main/20_exists.go.tpl index 17be1aebd..971760f4c 100644 --- a/templates/main/20_exists.go.tpl +++ b/templates/main/20_exists.go.tpl @@ -76,4 +76,9 @@ func {{$alias.UpSingular}}Exists({{if .NoContext}}exec boil.Executor{{else}}ctx return exists, nil } +// Exists checks if the {{$alias.UpSingular}} row exists. +func (o *{{$alias.UpSingular}}) Exists({{if .NoContext}}exec boil.Executor{{else}}ctx context.Context, exec boil.ContextExecutor{{end}}) (bool, error) { + return {{$alias.UpSingular}}Exists({{if .NoContext}}exec{{else}}ctx, exec{{end}}, o.{{$.Table.PKey.Columns | stringMap (aliasCols $alias) | join ", o."}}) +} + {{- end -}}