AllDotPy / AllDotPy/Ryx

feat: implement Case/When expressions for QuerySet.annotate()

Open
#53 0 comments 0 reactions 0 assignees View on GitHub

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:

  1. Create Case, When, and Value classes in ryx/queryset.py.
  2. 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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.