Skip to content
Oxford Harrison edited this page Nov 12, 2024 · 7 revisions

DOCSAPITable API


Programmatically perform a COUNT query.

See also ➞ SELECT

Syntax

table.count(
    expr?: any,
    modifiers?: CountOptions | Callback,
): Promise<number>;
Param Interfaces Description
expr? - Optional expression to pass to the COUNT() function; e.g. a column name. Defaults to star *.
modifiers? CountOptions Optional additional query modifiers. Can be Callback—a callback function that recieves the underlying SelectStatement instance for manipulation.

CountOptions

interface CountOptions {
    where?: WhereClause;
}
Param Interfaces Description
where? WhereClause An optional WHERE clause.

Usage

Call patterns

Count on all columns:

// COUNT *
const rowCount = await table.count();

Count on a column:

// Number of rows where column_1 isn't null
const rowCount = await table.count('column_1');

Add filters:

// Number of rows where column_1 isn't null and the extra conditions are also satisfied
const rowCount = await table.count(
    [ 'column_1' ],
    { where: { eq: ['col1', { value: 'val1' }] } }
);
// Number of rows where conditions are satisfied
const rowCount = await table.count(
    { where: { eq: ['col1', { value: 'val1' }] } }
);
Clone this wiki locally