From aaf3330d22d232c0e408d6fee5c63e2606d18b9d Mon Sep 17 00:00:00 2001 From: LoRiot Date: Fri, 21 Oct 2022 21:02:20 +0300 Subject: [PATCH] Get projects by name --- services/repositories.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/services/repositories.py b/services/repositories.py index 6a09d3c..4b34053 100644 --- a/services/repositories.py +++ b/services/repositories.py @@ -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}%" )