toCountQuery
A query counting the rows this one matches across every page, for the total a paged list shows.
val listed = db.select("id", "cognomen").from("senate").where(filter.sql).orderBy("cognomen")
val total = listed.toCountQuery().fetchFieldStrict<Long>(filter.params)
val senators = listed.page(page, 20).fetchObjects<Senator>(filter.params)Content copied to clipboard
This query is wrapped whole, SELECT count(*) FROM (…), so a DISTINCT or a GROUP BY counts the rows it returns. Its ORDER BY, LIMIT, OFFSET and locking clause are left out - a LIMIT that belongs to the meaning, a top ten, along with them.
The count takes this query's parameters and parameter converters, not its result converters. It is rendered now, so later changes to this builder do not reach it.