diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2022-02-17 16:37:48 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-17 16:37:48 +0800 |
commit | 397d2ac303d7dd34295537a5776bb77903100715 (patch) | |
tree | 702edfc191527b78731022d24f1eb2d4b84622eb /models/db | |
parent | bd71245c53275d5c8ffcd231b9e0f6fcd7b5dc80 (diff) | |
download | gitea-397d2ac303d7dd34295537a5776bb77903100715.tar.gz gitea-397d2ac303d7dd34295537a5776bb77903100715.zip |
Move deletebeans into models/db (#18781)
Diffstat (limited to 'models/db')
-rw-r--r-- | models/db/context.go | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/models/db/context.go b/models/db/context.go index 833c26ff6c..1cd23d453c 100644 --- a/models/db/context.go +++ b/models/db/context.go @@ -148,6 +148,17 @@ func DeleteByBean(ctx context.Context, bean interface{}) (int64, error) { return GetEngine(ctx).Delete(bean) } +// DeleteBeans deletes all given beans, beans should contain delete conditions. +func DeleteBeans(ctx context.Context, beans ...interface{}) (err error) { + e := GetEngine(ctx) + for i := range beans { + if _, err = e.Delete(beans[i]); err != nil { + return err + } + } + return nil +} + // CountByBean counts the number of database records according non-empty fields of the bean as conditions. func CountByBean(ctx context.Context, bean interface{}) (int64, error) { return GetEngine(ctx).Count(bean) |