Reference
?

db.count

Count rows, optionally matching a predicate, as a SQL COUNT.
Table.count(predicate?, bindings?) → Query<number>

Counts rows with a SQL COUNT, so no rows are fetched. Pass a predicate to count a subset, and lift any outer-scope comparison into bindings. Reach for it instead of reading rows and taking .length whenever the table can grow.

Parameters
predicate
(row, $) => boolean
Optional filter, compiled to SQL.
bindings
object
Outer-scope values lifted into the WHERE clause.
Count a subset
const pending = await Invoices.count((i) => i.status === 'pending');