| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -26,6 +26,7 @@ jobs: | |||
| 26 | 26 | - '3.8' | |
| 27 | 27 | - '3.9' | |
| 28 | 28 | - '3.10' | |
| 29 | + - '3.11' | ||
| 29 | 30 | runs-on: ubuntu-latest | |
| 30 | 31 | steps: | |
| 31 | 32 | - uses: actions/checkout@v2 | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -14,13 +14,15 @@ | |||
| 14 | 14 | """Helps build SQL for complex Spanner queries.""" | |
| 15 | 15 | ||
| 16 | 16 | import abc | |
| 17 | - from typing import Any, Dict, Iterable, List, Sequence, Tuple, Type | ||
| 17 | + from typing import Any, Dict, Generic, Iterable, List, Sequence, Tuple, Type, TypeVar | ||
| 18 | 18 | ||
| 19 | 19 | from spanner_orm import condition | |
| 20 | 20 | from spanner_orm import error | |
| 21 | 21 | ||
| 22 | + ResultType = TypeVar('ResultType') | ||
| 22 | 23 | ||
| 23 | - class SpannerQuery(abc.ABC): | ||
| 24 | + | ||
| 25 | + class SpannerQuery(abc.ABC, Generic[ResultType]): | ||
| 24 | 26 | """Helps build SQL for complex Spanner queries.""" | |
| 25 | 27 | ||
| 26 | 28 | def __init__(self, model: Type[Any], | |
@@ -46,7 +48,7 @@ def types(self) -> Dict[str, Any]: | |||
| 46 | 48 | return self._types | |
| 47 | 49 | ||
| 48 | 50 | @abc.abstractmethod | |
| 49 | - def process_results(self, results: List[Sequence[Any]]) -> None: | ||
| 51 | + def process_results(self, results: List[Sequence[Any]]) -> ResultType: | ||
| 50 | 52 | pass | |
| 51 | 53 | ||
| 52 | 54 | def _segments(self, | |
@@ -133,7 +135,7 @@ def _limit(self) -> Tuple[str, Dict[str, Any], Dict[str, Any]]: | |||
| 133 | 135 | return (sql, parameters, types) | |
| 134 | 136 | ||
| 135 | 137 | ||
| 136 | - class CountQuery(SpannerQuery): | ||
| 138 | + class CountQuery(SpannerQuery[int]): | ||
| 137 | 139 | """Handles COUNT Spanner queries.""" | |
| 138 | 140 | ||
| 139 | 141 | def __init__(self, model: Type[Any], | |
@@ -151,7 +153,7 @@ def process_results(self, results: List[Sequence[Any]]) -> int: | |||
| 151 | 153 | return int(results[0][0]) | |
| 152 | 154 | ||
| 153 | 155 | ||
| 154 | - class SelectQuery(SpannerQuery): | ||
| 156 | + class SelectQuery(SpannerQuery[List[Type[Any]]]): | ||
| 155 | 157 | """Handles SELECT Spanner queries.""" | |
| 156 | 158 | ||
| 157 | 159 | def __init__(self, model: Type[Any], | |
@@ -188,7 +190,7 @@ def _select(self) -> Tuple[str, Dict[str, Any], Dict[str, Any]]: | |||
| 188 | 190 | def process_results(self, results: List[Sequence[Any]]) -> List[Type[Any]]: | |
| 189 | 191 | return [self._process_row(result) for result in results] | |
| 190 | 192 | ||
| 191 | - def _process_row(self, row: List[Any]) -> Type[Any]: | ||
| 193 | + def _process_row(self, row: Sequence[Any]) -> Type[Any]: | ||
| 192 | 194 | """Parses a row of results from a Spanner query based on the conditions.""" | |
| 193 | 195 | values = dict(zip(self._model.columns, row)) | |
| 194 | 196 | join_values = row[len(self._model.columns):] | |
| Back | FazBrowse Home | New Git URL |
0 commit comments