This repository has been archived on 2022-10-22. You can view files and clone it, but cannot push or open issues or pull requests.
2022-10-16 12:37:29 +00:00
|
|
|
from asyncpg.connection import Connection
|
|
|
|
|
|
|
|
|
2022-09-16 05:48:10 +00:00
|
|
|
class Repo:
|
|
|
|
"""Db abstraction layer"""
|
|
|
|
|
2022-10-16 12:37:29 +00:00
|
|
|
def __init__(self, conn: Connection):
|
|
|
|
self.conn = conn
|
2022-10-16 13:30:57 +00:00
|
|
|
|
|
|
|
async def add_user(self, user_id: int, chat_id: int):
|
|
|
|
await self.conn.execute(
|
|
|
|
"INSERT INTO users (user_id, chat_id) "
|
|
|
|
"VALUES ($1, $2) ON CONFLICT (user_id) DO NOTHING",
|
|
|
|
user_id, chat_id
|
|
|
|
)
|
2022-10-16 14:06:45 +00:00
|
|
|
|
|
|
|
async def get_user(self, user_id: int):
|
|
|
|
return await self.conn.fetchval(
|
|
|
|
"SELECT user_id FROM users WHERE user_id = $1", user_id
|
|
|
|
)
|