Coverage for src/lexigram/admin/data/filter_specs.py: 0%
32 statements
« prev ^ index » next coverage.py v7.15.4, created at 2026-08-24 23:18 +0800
« prev ^ index » next coverage.py v7.15.4, created at 2026-08-24 23:18 +0800
1"""Filter specification types for admin data queries.
3Composable via ``&`` into :class:`CombinedSpec` trees consumed by data
4sources that support structured where-clauses.
5"""
7from __future__ import annotations
9from typing import Any, Protocol
11# ============================================================================
12# Filter SpecificationProtocol Types
13# ============================================================================
16class EqualSpec:
17 """Filter specification for exact equality: column == value."""
19 def __init__(self, field: str, value: object) -> None:
20 """Initialize EqualSpec with field name and value to match."""
21 self.field = field
22 self.value = value
24 def __and__(self, other: FilterSpec) -> CombinedSpec:
25 """Combine with another spec using AND."""
26 return CombinedSpec(specs=[self, other])
29class InSpec:
30 """Filter specification for IN query: column IN values."""
32 def __init__(self, field: str, values: list[object]) -> None:
33 """Initialize InSpec with field name and list of values."""
34 self.field = field
35 self.values = values
37 def __and__(self, other: FilterSpec) -> CombinedSpec:
38 """Combine with another spec using AND."""
39 return CombinedSpec(specs=[self, other])
42class GreaterThanOrEqualSpec:
43 """Filter specification for >= comparison: column >= value."""
45 def __init__(self, field: str, value: object) -> None:
46 """Initialize GreaterThanOrEqualSpec with field name and value."""
47 self.field = field
48 self.value = value
50 def __and__(self, other: FilterSpec) -> CombinedSpec:
51 """Combine with another spec using AND."""
52 return CombinedSpec(specs=[self, other])
55class LessThanOrEqualSpec:
56 """Filter specification for <= comparison: column <= value."""
58 def __init__(self, field: str, value: object) -> None:
59 """Initialize LessThanOrEqualSpec with field name and value."""
60 self.field = field
61 self.value = value
63 def __and__(self, other: FilterSpec) -> CombinedSpec:
64 """Combine with another spec using AND."""
65 return CombinedSpec(specs=[self, other])
68FilterSpec = EqualSpec | InSpec | GreaterThanOrEqualSpec | LessThanOrEqualSpec
71class CombinedSpec:
72 """Combined filter specification (AND of multiple specs)."""
74 def __init__(self, specs: list[FilterSpec]) -> None:
75 """Initialize CombinedSpec with list of filter specs."""
76 self.specs = specs
78 def __and__(self, other: FilterSpec) -> CombinedSpec:
79 """Combine with another spec using AND."""
80 return CombinedSpec(specs=[*self.specs, other])