Count Fixes

This commit is contained in:
Hein
2025-11-07 13:54:24 +02:00
parent 2e9a0bd51a
commit abee5c942f
3 changed files with 11 additions and 8 deletions

View File

@@ -228,7 +228,10 @@ func (b *BunSelectQuery) Scan(ctx context.Context, dest interface{}) error {
}
func (b *BunSelectQuery) Count(ctx context.Context) (int, error) {
count, err := b.query.Count(ctx)
// Use ColumnExpr with Scan instead of Count() to avoid requiring a model
// This works with just Table() set and avoids "Model(nil)" error
var count int
err := b.query.ColumnExpr("count(*)").Scan(ctx, &count)
return count, err
}