Remove "ORDER BY" before counting rows

This commit is contained in:
Denis Arh
2019-07-19 06:32:31 +02:00
parent 72672f6202
commit 38b117044c
@@ -3,6 +3,7 @@ package repository
import (
"context"
"github.com/lann/builder"
"github.com/pkg/errors"
"github.com/titpetric/factory"
"gopkg.in/Masterminds/squirrel.v1"
@@ -73,6 +74,9 @@ func (r repository) count(q squirrel.SelectBuilder) (uint, error) {
cq = q.Column("COUNT(*)")
)
// Remove order-bys for counting
cq = builder.Delete(cq, "OrderBys").(squirrel.SelectBuilder)
if sqlSelect, argsSelect, err := cq.ToSql(); err != nil {
return 0, err
} else {