Skip to content

Commit

Permalink
Allow calling struct.Exists() without having to pass on PK fields
Browse files Browse the repository at this point in the history
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().
  • Loading branch information
MJacred committed Sep 26, 2022
1 parent 92bf892 commit ca4aba1
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions templates/main/20_exists.go.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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 -}}

0 comments on commit ca4aba1

Please sign in to comment.