FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Fix tests and add support for newer python · 7dracoder/python-spanner-orm@d04420f · GitHub

Commit d04420f

Browse files
committed
Fix tests and add support for newer python
1 parent e2f103b commit d04420f

2 files changed

Lines changed: 9 additions & 6 deletions

File tree

‎.github/workflows/test.yaml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ jobs:
2626
- '3.8'
2727
- '3.9'
2828
- '3.10'
29+
- '3.11'
2930
runs-on: ubuntu-latest
3031
steps:
3132
- uses: actions/checkout@v2

‎spanner_orm/query.py‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@
1414
"""Helps build SQL for complex Spanner queries."""
1515

1616
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
1818

1919
from spanner_orm import condition
2020
from spanner_orm import error
2121

22+
ResultType = TypeVar('ResultType')
2223

23-
class SpannerQuery(abc.ABC):
24+
25+
class SpannerQuery(abc.ABC, Generic[ResultType]):
2426
"""Helps build SQL for complex Spanner queries."""
2527

2628
def __init__(self, model: Type[Any],
@@ -46,7 +48,7 @@ def types(self) -> Dict[str, Any]:
4648
return self._types
4749

4850
@abc.abstractmethod
49-
def process_results(self, results: List[Sequence[Any]]) -> None:
51+
def process_results(self, results: List[Sequence[Any]]) -> ResultType:
5052
pass
5153

5254
def _segments(self,
@@ -133,7 +135,7 @@ def _limit(self) -> Tuple[str, Dict[str, Any], Dict[str, Any]]:
133135
return (sql, parameters, types)
134136

135137

136-
class CountQuery(SpannerQuery):
138+
class CountQuery(SpannerQuery[int]):
137139
"""Handles COUNT Spanner queries."""
138140

139141
def __init__(self, model: Type[Any],
@@ -151,7 +153,7 @@ def process_results(self, results: List[Sequence[Any]]) -> int:
151153
return int(results[0][0])
152154

153155

154-
class SelectQuery(SpannerQuery):
156+
class SelectQuery(SpannerQuery[List[Type[Any]]]):
155157
"""Handles SELECT Spanner queries."""
156158

157159
def __init__(self, model: Type[Any],
@@ -188,7 +190,7 @@ def _select(self) -> Tuple[str, Dict[str, Any], Dict[str, Any]]:
188190
def process_results(self, results: List[Sequence[Any]]) -> List[Type[Any]]:
189191
return [self._process_row(result) for result in results]
190192

191-
def _process_row(self, row: List[Any]) -> Type[Any]:
193+
def _process_row(self, row: Sequence[Any]) -> Type[Any]:
192194
"""Parses a row of results from a Spanner query based on the conditions."""
193195
values = dict(zip(self._model.columns, row))
194196
join_values = row[len(self._model.columns):]

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL