Skip to content

Implement Count Queries #515

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

Open
wants to merge 2 commits into
base: feat-sum-queries
Choose a base branch
from

Conversation

PineappleIOnic
Copy link
Contributor

This PR implements count queries and generally cleans up the code of how aggregates work so it's more maintainable. This supports all DB adapters excluding MongoDB.

@PineappleIOnic PineappleIOnic marked this pull request as ready for review January 31, 2025 03:01
// Test mixing count with other queries
$documents = $database->find('testCountQueries', [
Query::count('integer'),
Query::limit(1),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps should validate not using limits / offset queries Since they happen after the aggregations.
Most likely count/sum will return 1 row.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We run aggregate SQL after the main SQL using a subquery so this shouldn't be a problem

$this->assertEquals(1, $documents[0]->getAttribute('integer'));

$documents = $database->find('testCountQueries', [
Query::count('integer'),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Do we allow select queries when using aggregation queries, which will lead to errors?
  • Do we allow Query::count('integer'), Query::sum('integer') will both have the alias?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Do we validate aggregation queries in nested queries?

Copy link
Contributor Author

@PineappleIOnic PineappleIOnic Feb 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. No we do not allow select queries when using aggregation queries, we have a validator for that.
  2. We don't allow mixing aggregate queries
  3. I haven't touched nested queries, so I don't think so

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants