diff --git a/u232ping/db.py b/u232ping/db.py new file mode 100644 index 0000000..9e98e0e --- /dev/null +++ b/u232ping/db.py @@ -0,0 +1,28 @@ +from u232ping.abc.db import DataBase +from u232ping.types import Group +from aiosqlite import connect as sq +from os import environ + +class Sqlite(DataBase): + + path: str + + def __init__(self): + self.path = environ["DB_PATH"] + + async def _get(self, group: int | None = None) -> Group: + req = "SELECT telegram FROM u232" + if group is not None: + where = f" WHERE group = {group}" + req += where + async with sq(self.path) as db: + cursor = await db.cursor() + await cursor.execute(req) + fetch = await cursor.fetchall() + return Group(fetch) + + async def get_group(self, group_idx: int): + return await self._get(group_idx) + + async def get_all(self): + return await self._get()