Get projects by name

This commit is contained in:
LoRiot 2022-10-21 21:02:20 +03:00
parent c38ddcb01c
commit aaf3330d22
1 changed files with 6 additions and 4 deletions

View File

@ -1,6 +1,7 @@
from loguru import logger
from typing import Type, TypeVar
from asyncpg.connection import Connection
from asyncpg import Record
class BaseRepo:
@ -25,7 +26,7 @@ class UserRepo(BaseRepo):
chat_id,
)
async def get(self, user_id: int):
async def get(self, user_id: int) -> Record:
return await self.conn.fetchval(
"SELECT user_id FROM users WHERE user_id = $1", user_id
)
@ -41,7 +42,8 @@ class ProjectRepo(BaseRepo):
user_id, *args
)
async def get(self, user_id: int):
return await self.conn.fetchval(
"SELECT name, description FROM projects WHERE creator = $1", user_id
async def get(self, name: str) -> Record:
return await self.conn.fetch(
"SELECT id, name, description FROM projects WHERE name LIKE $1",
f"%{name}%"
)