feathersjs-ecosystem / feathers-knex

Service adapters for KnexJS a query builder for PostgreSQL, MySQL, MariaDB, Oracle and SQLite3
MIT License
112 stars 59 forks source link

Unable to get correct total on query with GROUP BY #192

Open Hendribcg opened 5 years ago

Hendribcg commented 5 years ago

Create a custom query with GROUP BY clause, it will return false number as total As the current SQL query to get the total number of row is by using a count statement in SQL select, if we are using GROUP BY in our SQL it will return the count in the grouped rows instead of total row count. My workaround solution is by extending the _find function and adding _clearGrouping('group'); in the query for getting count numbers.

Expected behavior

Return count of total row not the count of grouped row.

Actual behavior

It return count of grouped row.

System configuration

Tell us about the applicable parts of your setup.

Module versions (especially the part that's not working): feathers-knex 5.0.4, knex 0.16.3

stale[bot] commented 5 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Apologies if the issue could not be resolved. FeathersJS ecosystem modules are community maintained so there may be a chance that there isn't anybody available to address the issue at the moment. For other ways to get help see here.

smparsons commented 4 years ago

@daffl Are there any plans on fixing this bug anytime soon? If not, are you okay with me making a pull request to fix this? It would be nice to not have to override this service in order to get the correct total. I feel like this should be a fairly easy fix too (I think it's just a matter of adding a clearGroup call when initializing the countQuery variable).

daffl commented 4 years ago

A pull request with a test and fix is always welcome.