Skip to content
This repository was archived by the owner on Sep 7, 2021. It is now read-only.
This repository is currently being migrated. It's locked while the migration is in progress.
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions session_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ func (session *Session) Count(bean ...interface{}) (int64, error) {
args = session.statement.RawParams
}

if len(session.statement.selectStr) > 0 {
sqlStr = "SELECT COUNT(*) FROM ("+sqlStr+") _TEMP_"
}

var total int64
err = session.queryRow(sqlStr, args...).Scan(&total)
if err == sql.ErrNoRows || err == nil {
Expand Down
4 changes: 4 additions & 0 deletions session_stats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ func TestCount(t *testing.T) {
assert.NoError(t, err)
assert.EqualValues(t, 1, cnt)

total, err = testEngine.Where(cond).Select(colName).Count(new(UserinfoCount))
assert.NoError(t, err)
assert.EqualValues(t, 1, total)

total, err = testEngine.Where(cond).Count(new(UserinfoCount))
assert.NoError(t, err)
assert.EqualValues(t, 1, total)
Expand Down