1
0
Fork 0

Add db.py

This commit is contained in:
Trueold89 2024-09-04 19:44:08 +03:00
parent 0c5ab590c4
commit 4b09cd91b5
1 changed files with 28 additions and 0 deletions

28
u232ping/db.py Normal file
View File

@ -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()