feat: implement Case/When expressions for QuerySet.annotate()
Open
Nobody has claimed this yet.
enhancement
query builder
querysets
ryx-python
- Dominant language
- Rust
- Stars
- 13
- Forks
- 5
- Avg merge
- 1h 49m
- Merged PRs (30d)
- 3
Description
Ryx currently supports CASE WHEN internally for bulk updates, but it is not exposed as a high-level API for annotate().
Goal: Implement a Case and When API allowing users to create conditional columns in their result sets.
Example usage:
posts = await Post.objects.annotate(
status=Case(
When(views__gt=1000, then=Value("viral")),
When(views__gt=100, then=Value("popular")),
default=Value("normal")
)
)
Implementation hint:
- Create Case, When, and Value classes in ryx/queryset.py.
- Update the Rust compiler in ryx-query to handle these new AST nodes and generate the corresponding CASE WHEN ... THEN ... ELSE ... END SQL. Label: advanced
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 in ryx/queryset.py with the existing query expression APIs, then inspect the Rust compiler in ryx-query and its bulk-update CASE WHEN support. Implement the Case, When, and Value API and compiler handling so the annotated query produces CASE WHEN ... THEN ... ELSE ... END SQL matching the issue's example.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, rust, sql
- Domain
- backend-api-design, databases
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 42/100