beerds/server/infra/db/abc.py

42 lines
997 B
Python

"""Abstract realiztion for DB"""
from typing import Any, AsyncContextManager, Awaitable, Callable, TypeAlias
from server.config import AppConfig
ExecuteFun: TypeAlias = Callable[[Any], Awaitable[None]]
class ConnectError(Exception):
"""Custom error wor failed connections"""
class AbstractSession:
async def __aenter__(self) -> "AbstractSession":
raise NotImplementedError
async def __aexit__(self, exc_type, exc, tb):
raise NotImplementedError
def begin(self) -> AsyncContextManager:
raise NotImplementedError
async def execute(self, data: Any):
raise NotImplementedError
async def commit(self):
raise NotImplementedError
class AbstractDB:
"""Abstract realiztion for DB"""
def __init__(self, cnf: AppConfig):
raise NotImplementedError
def session_master(self) -> AbstractSession:
raise NotImplementedError
def session_slave(self) -> AbstractSession:
raise NotImplementedError