Skip to content

Instantly share code, notes, and snippets.

@colonelpanic8
Created October 20, 2024 01:49
Show Gist options
  • Save colonelpanic8/1209b73d60b64001c46db85c1300a890 to your computer and use it in GitHub Desktop.
Save colonelpanic8/1209b73d60b64001c46db85c1300a890 to your computer and use it in GitHub Desktop.
def build_lexical_condition(
ordering_components: list[gql.ShotsOrderingComponent],
) -> sa.sql.elements.BooleanClauseList:
if not ordering_components:
return False
this_component = ordering_components[0]
_, field, ordering = this_component.get_component_with_column()
this_condition = (
field < ordering.starting_at
if ordering.descending
else field > ordering.starting_at
)
remaining_components = ordering_components[1:]
rest_conditions = [field == ordering.starting_at]
if remaining_components:
rest_conditions.append(build_lexical_condition(remaining_components))
return sa.or_(
this_condition,
(sa.and_(*rest_conditions)),
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment