Skip to content

Commit

Permalink
Fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
lunny committed May 28, 2022
1 parent 52f64ff commit 4f56237
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion models/repo_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"code.gitea.io/gitea/models/unit"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/container"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/util"

Expand Down Expand Up @@ -548,6 +549,20 @@ func SearchRepositoryByCondition(opts *SearchRepoOptions, cond builder.Cond, loa
return repos, count, nil
}

func withDB() *builder.Builder {
switch setting.Database.Type {
case "sqlite3":
return builder.Dialect(builder.SQLITE)
case "mysql":
return builder.Dialect(builder.MYSQL)
case "postgres":
return builder.Dialect(builder.POSTGRES)
case "mssql":
return builder.Dialect(builder.MSSQL)
}
return &builder.Builder{}
}

func searchRepositoryByCondition(ctx context.Context, opts *SearchRepoOptions, selCols string, cond builder.Cond) (*builder.Builder, int64, error) {
if opts.Page <= 0 {
opts.Page = 1
Expand Down Expand Up @@ -579,7 +594,7 @@ func searchRepositoryByCondition(ctx context.Context, opts *SearchRepoOptions, s
orderBy = opts.OrderBy.String()
}

b := builder.Select(selCols).From("repository").Where(cond).OrderBy(orderBy)
b := withDB().Select(selCols).From("repository").Where(cond).OrderBy(orderBy)
if opts.PageSize > 0 {
b.Limit(opts.PageSize, (opts.Page-1)*opts.PageSize)
}
Expand Down

0 comments on commit 4f56237

Please sign in to comment.