count
Category
Tags
Export size
min 6.05 kB · gzip 2.50 kB
See also
Counts the items matching params without loading them.
Calls find with $limit: 0 and returns the total of the paginated result. Pagination is forced for this one call via params.paginate, so it works for services with and without pagination - a paginate: false in params included. The adapters then only run their counting query.
A service that ignores params.paginate and returns an array makes it throw, as an empty array cannot tell "no items" from "not counted". That is the case for custom services, and for a client calling a server service without pagination - params.paginate never reaches the server.
ts
import { count } from 'feathers-utils/utils';Example
ts
import { count } from 'feathers-utils/utils'
const openTodos = await count(app, 'todos', { query: { done: false } })Type declaration
Show Type Declarations
ts
/**
* Counts the items matching `params` without loading them.
*
* Calls `find` with `$limit: 0` and returns the `total` of the paginated
* result. Pagination is forced for this one call via `params.paginate`, so it
* works for services with and without pagination - a `paginate: false` in
* `params` included. The adapters then only run their counting query.
*
* A service that ignores `params.paginate` and returns an array makes it throw,
* as an empty array cannot tell "no items" from "not counted". That is the case
* for custom services, and for a client calling a server service without
* pagination - `params.paginate` never reaches the server.
*
* @example
* ```ts
*
*
* const openTodos = await count(app, 'todos', { query: { done: false } })
* ```
*
* @see https://utils.feathersjs.com/utils/count.html
*/
export declare function count<
Services,
Path extends KeyOf<Services>,
Service extends Services[Path] = Services[Path],
P extends Params = InferFindParams<Service>,
>(
app: Application<Services>,
servicePath: Path,
params?: P & {
paginate?: PaginationOptions | false
},
): Promise<number>| Argument | Type | Description |
|---|---|---|
| app | Application<Services> | |
| servicePath | Path | |
| params | P & { paginate?: PaginationOptions | false } |
