1
1
mirror of https://github.com/go-gitea/gitea synced 2025-11-02 12:28:25 +00:00

add models and services

This commit is contained in:
Lunny Xiao
2022-10-07 22:43:56 +08:00
committed by Jason Song
parent 4af45f7bc9
commit ab4f539453
6 changed files with 201 additions and 0 deletions

View File

@@ -4,6 +4,12 @@
package db
import (
"context"
"xorm.io/builder"
)
// SearchOrderBy is used to sort the result
type SearchOrderBy string
@@ -28,3 +34,14 @@ const (
SearchOrderByForks SearchOrderBy = "num_forks ASC"
SearchOrderByForksReverse SearchOrderBy = "num_forks DESC"
)
func FindObjects[Object any](ctx context.Context, cond builder.Cond, opts *ListOptions, objects *[]*Object) error {
sess := GetEngine(ctx).Where(cond)
if opts != nil && opts.PageSize > 0 {
if opts.Page < 1 {
opts.Page = 1
}
sess.Limit(opts.PageSize, opts.PageSize * (opts.Page - 1))
}
return sess.Find(objects)
}