31 lines
853 B
Python
31 lines
853 B
Python
from sqlalchemy import insert, select
|
|
from sqlalchemy.ext.asyncio.session import AsyncSession
|
|
|
|
from api.models import UserModel
|
|
from api.repositories import AbstractRepository
|
|
|
|
|
|
class UserRepository(AbstractRepository):
|
|
def __init__(self, session: AsyncSession):
|
|
self.session = session
|
|
|
|
async def add_one(self, data: dict):
|
|
stmt = insert(UserModel).values(**data)
|
|
res = await self.session.execute(stmt)
|
|
return res.scalar_one()
|
|
|
|
async def find_all(self):
|
|
stmt = select(UserModel)
|
|
res = await self.session.execute(stmt)
|
|
res = [row[0].to_read_model() for row in res.all()]
|
|
return res
|
|
|
|
async def find_one(self, filter: dict):
|
|
return
|
|
|
|
async def update_one(self, filter: dict, data: dict):
|
|
return
|
|
|
|
async def delete_one(self, filter: dict):
|
|
return
|