summaryrefslogtreecommitdiffstats
path: root/models/db
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2023-02-13 13:11:41 +0800
committerGitHub <noreply@github.com>2023-02-13 13:11:41 +0800
commitf2772b5920967f5dacc3de27dee2bc1b464533e2 (patch)
treefff67444be7a76b666148709e0771a19c2d3ebc4 /models/db
parenteb5e1bcd2175c05c724e19c1a261c3f3d063abe6 (diff)
downloadgitea-f2772b5920967f5dacc3de27dee2bc1b464533e2.tar.gz
gitea-f2772b5920967f5dacc3de27dee2bc1b464533e2.zip
Move delete user to service (#22478)
Move delete user to service Co-authored-by: delvh <dev.lh@web.de> Co-authored-by: Jason Song <i@wolfogre.com>
Diffstat (limited to 'models/db')
-rw-r--r--models/db/context.go26
1 files changed, 26 insertions, 0 deletions
diff --git a/models/db/context.go b/models/db/context.go
index 911dbd1c6f..4b3f7f0ee7 100644
--- a/models/db/context.go
+++ b/models/db/context.go
@@ -7,6 +7,7 @@ import (
"context"
"database/sql"
+ "xorm.io/builder"
"xorm.io/xorm"
"xorm.io/xorm/schemas"
)
@@ -183,6 +184,31 @@ func DeleteByBean(ctx context.Context, bean interface{}) (int64, error) {
return GetEngine(ctx).Delete(bean)
}
+// DeleteByID deletes the given bean with the given ID
+func DeleteByID(ctx context.Context, id int64, bean interface{}) (int64, error) {
+ return GetEngine(ctx).ID(id).NoAutoTime().Delete(bean)
+}
+
+// FindIDs finds the IDs for the given table name satisfying the given condition
+// By passing a different value than "id" for "idCol", you can query for foreign IDs, i.e. the repo IDs which satisfy the condition
+func FindIDs(ctx context.Context, tableName, idCol string, cond builder.Cond) ([]int64, error) {
+ ids := make([]int64, 0, 10)
+ if err := GetEngine(ctx).Table(tableName).
+ Cols(idCol).
+ Where(cond).
+ Find(&ids); err != nil {
+ return nil, err
+ }
+ return ids, nil
+}
+
+// DecrByIDs decreases the given column for entities of the "bean" type with one of the given ids by one
+// Timestamps of the entities won't be updated
+func DecrByIDs(ctx context.Context, ids []int64, decrCol string, bean interface{}) error {
+ _, err := GetEngine(ctx).Decr(decrCol).In("id", ids).NoAutoCondition().NoAutoTime().Update(bean)
+ return err
+}
+
// DeleteBeans deletes all given beans, beans should contain delete conditions.
func DeleteBeans(ctx context.Context, beans ...interface{}) (err error) {
e := GetEngine(ctx)