-
Notifications
You must be signed in to change notification settings - Fork 119
feat: add fetchRaw #1118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
feat: add fetchRaw #1118
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR introduces a new fetchRaw configuration option to enable retrieving raw SQL results from TypeORM queries, which is particularly useful for aggregated or computed fields.
Key changes:
- Added
fetchRawboolean option toPaginateConfiginterface - Updated pagination logic to use
getRawMany()instead ofgetMany()whenfetchRawis enabled - Added comprehensive test with SQL aggregates using a new
SaleEntityfor validation
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/paginate.ts | Adds fetchRaw config option and implements conditional logic to use getRawMany() across different pagination scenarios (standard pagination, cursor pagination, and non-paginated queries) |
| src/paginate.spec.ts | Adds test infrastructure (repository, entity imports) and a comprehensive test case demonstrating fetchRaw with SQL aggregates and custom count query |
| src/tests/sale.entity.ts | Introduces a new test entity for sales data with decimal columns to support aggregate function testing |
| README.md | Documents the new fetchRaw configuration option with clear description, use cases, and important notes about SQL aliases |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Ensures consistent line endings across the project by replacing CRLF with LF. This improves collaboration and prevents potential cross-platform compatibility issues.
|
@ppetzold The problem is: TypeORM’s getCount() cannot correctly count grouped results. Because of this limitation, I’m considering redesigning the buildCountQuery API so that: Instead of returning a QueryBuilder, buildCountQuery returns a number (or a Promise), For example: This makes it possible for users to:
What do you think about this redesign? |
This PR continues the work from the abandoned PR #975:
https://github.com/ppetzold/nestjs-paginate/pull/975
The original PR introduced raw-fetch support but also proposed a new count-related config option.
Since the current version of the library already provides buildCountQuery, which fully satisfies the count customization needs, the additional count config was not included.