-
Notifications
You must be signed in to change notification settings - Fork 393
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update dbs to support using transactions
added pytz
- Loading branch information
Showing
9 changed files
with
362 additions
and
173 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 36 additions & 8 deletions
44
aiogram_bot_template/db/db_api/storages/basestorage/storage.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,54 @@ | ||
from typing import Any, Optional, Type, TypeVar | ||
import typing | ||
from typing import Any, Optional, TypeVar | ||
|
||
T = TypeVar("T") | ||
|
||
|
||
class SingleQueryResult: | ||
def __init__(self, result: Optional[typing.Mapping[str, Any]]): | ||
self._data = {**result} if result else None | ||
|
||
@property | ||
def data(self) -> Optional[dict[str, Any]]: | ||
return self._data | ||
|
||
def convert(self, model: type[T]) -> Optional[T]: | ||
return model(**self.data) if self._data else None | ||
|
||
|
||
class MultipleQueryResults: | ||
def __init__(self, results: list[typing.Mapping[str, Any]]): | ||
self._data: list[dict[str, Any]] = [{**i} for i in results] | ||
|
||
@property | ||
def data(self) -> list[dict[str, Any]]: | ||
return self._data | ||
|
||
def convert(self, model: type[T]) -> list[T]: | ||
return [model(**i) for i in self._data] | ||
|
||
|
||
class RawConnection: | ||
async def _fetch( | ||
self, | ||
sql: str, | ||
params: Optional[tuple[Any, ...] | list[tuple[Any, ...]]], | ||
model_type: Type[T], | ||
) -> Optional[list[T]]: | ||
params: Optional[tuple[Any, ...] | list[tuple[Any, ...]]] = None, | ||
con: Optional[Any] = None, | ||
) -> MultipleQueryResults: | ||
raise NotImplementedError | ||
|
||
async def _fetchrow( | ||
self, | ||
sql: str, | ||
params: Optional[tuple[Any, ...] | list[tuple[Any, ...]]], | ||
model_type: Type[T], | ||
) -> Optional[T]: | ||
params: Optional[tuple[Any, ...] | list[tuple[Any, ...]]] = None, | ||
con: Optional[Any] = None, | ||
) -> SingleQueryResult: | ||
raise NotImplementedError | ||
|
||
async def _execute( | ||
self, sql: str, params: Optional[tuple[Any, ...] | list[tuple[Any, ...]]] | ||
self, | ||
sql: str, | ||
params: Optional[tuple[Any, ...] | list[tuple[Any, ...]]] = None, | ||
con: Optional[Any] = None, | ||
) -> None: | ||
raise NotImplementedError |
Oops, something went wrong.