Skip to content
This repository has been archived by the owner on Sep 2, 2022. It is now read-only.

Commit

Permalink
Merge pull request #4200 from prisma/CountQuery
Browse files Browse the repository at this point in the history
Improve Count query when no query arguments are given
  • Loading branch information
do4gr authored Mar 15, 2019
2 parents 54942c7 + ea4ed7d commit de8fc9d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ trait NodeManyQueries extends BuilderBase with FilterConditionBuilder with Curso

def countFromModel(model: Model, queryArguments: QueryArguments): DBIO[Int] = {
val baseQuery = modelQuery(model, queryArguments, SelectedFields(Set(SelectedScalarField(model.idField_!))))
val query = sql.selectCount().from(baseQuery)

val query = if (queryArguments.isEmpty) sql.selectCount().from(modelTable(model)) else sql.selectCount().from(baseQuery)

queryToDBIO(query)(
setParams = pp => SetParams.setQueryArgs(pp, queryArguments),
setParams = pp => if (queryArguments.isEmpty) () else SetParams.setQueryArgs(pp, queryArguments),
readResult = { rs =>
val _ = rs.next()
val count = rs.getInt(1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ case class QueryArguments(
orderBy: Option[OrderBy]
) {
val isWithPagination = last.orElse(first).orElse(skip).isDefined
val isEmpty = skip.isEmpty && after.isEmpty && first.isEmpty && before.isEmpty && last.isEmpty && filter.isEmpty && orderBy.isEmpty
}

object QueryArguments {
Expand Down

0 comments on commit de8fc9d

Please sign in to comment.