Add `findManyAndCount()` to return count of queried items
In order to properly perform pagination, one has to know the total count of items. For example, in a list of 1000 users paged in groups of 100, you have to know that the last page is at skip 900. This can easily be done in a separate query call using `.count` However, when filtering the data, this counting becomes more difficult. Say each `user` has a `profile`, and each profile has an `address`, and I want to get all users living in city X. This requires two joins and filtering by `where`. Count is still relevant here, because it may well be hundres of users in one city, still requiring pagination. It's not possible to use `.length` on the data, because it is already shortened to 100 items by `take` Using a separate .count() call adds a lot of repeated code and overhead since the query is basically performed twice. But, This can be fixed by returning the count object on findMany along with the data, such as TypeOrm does it: ``` const [users, count] = await this._userRepository.findAndCount({ query options }) ``` ## Alternatives Using the .count() function seperately, but as mentioned above, this is not very efficient.
Posted by julianflapper on Jun 9, 2021, 6:30 AM
Tags
Related issues
- It’s such an annoying problem to solve.
- > My point is, the impression many people will unavoidably take away from "many recalls" is that the vehicle must me in the shop all the ...
- [Feature]: Ability to merge old runs with a new run
- One of the best, and first, things we did when starting our machine learning platform was to design it using a plugin architecture.
- gh pr push
Raise real-world problems, find people facing the same issue, and discuss solutions.3,000 issues0 comments
ux (E-commerce)
It’s such an annoying problem to solve.
> My point is, the impression many people will unavoidably take away from "many recalls" is that the vehicle must me in the shop all the ...
[Feature]: Ability to merge old runs with a new run
Add `findManyAndCount()` to return count of queried items
One of the best, and first, things we did when starting our machine learning platform was to design it using a plugin architecture.
gh pr push
Add `findManyAndCount()` to return count of queried items
In order to properly perform pagination, one has to know the total count of items. For example, in a list of 1000 users paged in groups of 100, you have to know that the last page is at skip 900. This can easily be done in a separate query call using `.count` However, when filtering the data, this counting becomes more difficult. Say each `user` has a `profile`, and each profile has an `address`, and I want to get all users living in city X. This requires two joins and filtering by `where`. Count is still relevant here, because it may well be hundres of users in one city, still requiring pagination. It's not possible to use `.length` on the data, because it is already shortened to 100 items by `take` Using a separate .count() call adds a lot of repeated code and overhead since the query is basically performed twice. But, This can be fixed by returning the count object on findMany along with the data, such as TypeOrm does it: ``` const [users, count] = await this._userRepository.findAndCount({ query options }) ``` ## Alternatives Using the .count() function seperately, but as mentioned above, this is not very efficient.
Comments (0)
No comments yet. Start the discussion.