Skip to content

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

@Einswilli

Description

@Einswilli

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

Metadata

Metadata

Assignees

No one assigned
    No fields configured for Feature.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions