Skip to content

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.

3 participants