-
-
Notifications
You must be signed in to change notification settings - Fork 1
table.count()
Oxford Harrison edited this page Nov 17, 2024
·
7 revisions
Programmatically perform a COUNT
query.
See related ➞
SELECT
table.count(
expr?: string | string[],
clauses?: SelectClauses | Callback,
): Promise<number>;
Param | Interfaces | Description |
---|---|---|
expr? |
- | Optional expression to pass to the COUNT() function; e.g. a column name. Defaults to star * . |
clauses? |
SelectClauses |
Optional additional query clauses. Can be Callback —a callback function that recieves the underlying SelectStatement instance for manipulation. |
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' }] } }
);