diff options
Diffstat (limited to 'models/db/context.go')
-rw-r--r-- | models/db/context.go | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/models/db/context.go b/models/db/context.go index 521857fae8..9f72b43555 100644 --- a/models/db/context.go +++ b/models/db/context.go @@ -178,6 +178,15 @@ func GetByBean(ctx context.Context, bean any) (bool, error) { return GetEngine(ctx).Get(bean) } +func Exist[T any](ctx context.Context, cond builder.Cond) (bool, error) { + if !cond.IsValid() { + return false, ErrConditionRequired{} + } + + var bean T + return GetEngine(ctx).Where(cond).NoAutoCondition().Exist(&bean) +} + // DeleteByBean deletes all records according non-empty fields of the bean as conditions. func DeleteByBean(ctx context.Context, bean any) (int64, error) { return GetEngine(ctx).Delete(bean) |