tortoise / tortoise/tortoise-orm
Aggregations on explicit GROUP BY queries
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 5.6k
- Forks
- 516
- Avg merge
- 2d 21h
- Merged PRs (30d)
- 9
Description
Is your feature request related to a problem? Please describe.
Currently, it is not possible to group entries by a specific field to apply aggregations. A raw SQL example would be:
SELECT AVG(gpa)
FROM students
WHERE age > 21
GROUP BY gender
Describe the solution you'd like
To keep the API similar to Django's, it would be nice to be able to use annotate() on ValuesQuery:
Student.filter(age__gt=21).values('gender').annotate(average_gpa=Avg('gpa'))
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing the ValuesQuery API and its existing support for annotate(), using the Django aggregation example and the Student.filter(age__gt=21).values('gender').annotate(average_gpa=Avg('gpa')) expression as the target behavior. Done means explicit grouping can be combined with aggregation and produces the expected grouped results.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- database
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100