Internal structure used to generate SQL Queries.
| 185 | |
| 186 | |
| 187 | class QueryModifier: |
| 188 | """ |
| 189 | Internal structure used to generate SQL Queries. |
| 190 | """ |
| 191 | |
| 192 | def __init__( |
| 193 | self, |
| 194 | where_criterion: Criterion | None = None, |
| 195 | joins: list[TableCriterionTuple] | None = None, |
| 196 | having_criterion: Criterion | None = None, |
| 197 | ) -> None: |
| 198 | self.where_criterion: Criterion = where_criterion or EmptyCriterion() |
| 199 | self.joins = joins or [] |
| 200 | self.having_criterion: Criterion = having_criterion or EmptyCriterion() |
| 201 | |
| 202 | def __and__(self, other: QueryModifier) -> QueryModifier: |
| 203 | return self.__class__( |
| 204 | where_criterion=_and(self.where_criterion, other.where_criterion), |
| 205 | joins=self.joins + other.joins, |
| 206 | having_criterion=_and(self.having_criterion, other.having_criterion), |
| 207 | ) |
| 208 | |
| 209 | def _and_criterion(self) -> Criterion: |
| 210 | return _and(self.where_criterion, self.having_criterion) |
| 211 | |
| 212 | def __or__(self, other: QueryModifier) -> QueryModifier: |
| 213 | where_criterion = having_criterion = None |
| 214 | if self.having_criterion or other.having_criterion: |
| 215 | having_criterion = _or(self._and_criterion(), other._and_criterion()) |
| 216 | else: |
| 217 | where_criterion = ( |
| 218 | (self.where_criterion | other.where_criterion) |
| 219 | if self.where_criterion and other.where_criterion |
| 220 | else (self.where_criterion or other.where_criterion) |
| 221 | ) |
| 222 | return self.__class__(where_criterion, self.joins + other.joins, having_criterion) |
| 223 | |
| 224 | def __invert__(self) -> QueryModifier: |
| 225 | where_criterion = having_criterion = None |
| 226 | if self.having_criterion: |
| 227 | having_criterion = (self.where_criterion & self.having_criterion).negate() |
| 228 | elif self.where_criterion: |
| 229 | where_criterion = self.where_criterion.negate() |
| 230 | return self.__class__(where_criterion, self.joins, having_criterion) |
| 231 | |
| 232 | |
| 233 | class Prefetch: |
no outgoing calls
no test coverage detected
searching dependent graphs…