forked from forgejo/forgejo
Backport #27673 by @lng2020 Related to https://gitea.com/xorm/xorm/pulls/2341 Co-authored-by: Nanguan Lin <70063547+lng2020@users.noreply.github.com>
This commit is contained in:
parent
9b14f1a8ed
commit
89d3766d22
4 changed files with 13 additions and 5 deletions
|
@ -96,7 +96,15 @@ func AssertExistsAndLoadMap(t assert.TestingT, table string, conditions ...any)
|
|||
// GetCount get the count of a bean
|
||||
func GetCount(t assert.TestingT, bean any, conditions ...any) int {
|
||||
e := db.GetEngine(db.DefaultContext)
|
||||
count, err := whereOrderConditions(e, conditions).Count(bean)
|
||||
for _, condition := range conditions {
|
||||
switch cond := condition.(type) {
|
||||
case *testCond:
|
||||
e = e.Where(cond.query, cond.args...)
|
||||
default:
|
||||
e = e.Where(cond)
|
||||
}
|
||||
}
|
||||
count, err := e.Count(bean)
|
||||
assert.NoError(t, err)
|
||||
return int(count)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue