# -*- coding: utf-8 -*- #################################### # DataBase module abstract classes # #################################### # Imports from abc import ABC, abstractmethod from tubot.static.abc import IValidatable from tubot.db.types import CacheDBTypes, User class CacheDB(IValidatable, ABC): """ Abstract class for CacheDB """ _ctype: CacheDBTypes def __init__(self) -> None: if self._ctype is None: raise NotImplementedError("CacheDB type not implemented") # Users @abstractmethod async def write_user(self, tg_id: int, user: User) -> None: """ Writes user to cache db :param tg_id: User telegram id :param user: User object """ raise NotImplementedError @abstractmethod async def read_user(self, tg_id: int) -> User: """ Writes user to cache db :param tg_id: User telegram id :return: User object """ raise NotImplementedError # Dirs @abstractmethod async def cache_dirs(self, dirs: dict, expire: int) -> None: """ Cache dirs from DirectoryGetter :param dirs: Dirs dict :param expire: Expire time (in seconds) """ raise NotImplementedError @property @abstractmethod async def get_dirs(self) -> dict: """ Returns precached dirs :return: Dirs dict """ raise NotImplementedError