Version: v0.7.1 - Beta.  We welcome contributors & feedback.

Db.countRows

Db.countRows($table, $whereMapOrSql) -> number

Description

Return the number of rows in $table that match $whereMapOrSql.

$whereMapOrSql can be a Map of column-to-value constraints, or a SQL TypeString.

// Count posts written by user #123
Db.countRows('posts', { authorId: 123 }))
//= 20

// Count posts written in the past 24 hours
$oneDayAgo = date'24 hours ago'
Db.countRows('posts', { 'postDate >=': $oneDayAgo }))
//= 78

// Same, but with SQL TypeString
Db.countRows('posts', sql'postDate > {}'.fill($oneDayAgo)))
//= 78

See Also