summaryrefslogtreecommitdiffstats
path: root/models/context.go
diff options
context:
space:
mode:
Diffstat (limited to 'models/context.go')
-rw-r--r--models/context.go13
1 files changed, 13 insertions, 0 deletions
diff --git a/models/context.go b/models/context.go
index 5f47c595a2..6b8b9af570 100644
--- a/models/context.go
+++ b/models/context.go
@@ -4,6 +4,12 @@
package models
+import (
+ "code.gitea.io/gitea/modules/setting"
+
+ "xorm.io/builder"
+)
+
// DBContext represents a db context
type DBContext struct {
e Engine
@@ -53,3 +59,10 @@ func WithTx(f func(ctx DBContext) error) error {
sess.Close()
return err
}
+
+// Iterate iterates the databases and doing something
+func Iterate(ctx DBContext, tableBean interface{}, cond builder.Cond, fun func(idx int, bean interface{}) error) error {
+ return ctx.e.Where(cond).
+ BufferSize(setting.Database.IterateBufferSize).
+ Iterate(tableBean, fun)
+}