gitignore
This commit is contained in:
@@ -1,26 +0,0 @@
|
||||
from typing import Generic, TypeVar
|
||||
|
||||
from sqlalchemy import insert, select
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
import api.models as models
|
||||
|
||||
ModelType = TypeVar("ModelType", bound=models.Base)
|
||||
|
||||
|
||||
class SQLAlchemyRepository(Generic[ModelType]):
|
||||
model: type[ModelType]
|
||||
|
||||
def __init__(self, session: AsyncSession):
|
||||
self.session = session
|
||||
|
||||
async def add_one(self, data: dict) -> ModelType:
|
||||
stmt = insert(self.model).values(**data)
|
||||
res = await self.session.execute(stmt)
|
||||
return res.scalar_one()
|
||||
|
||||
async def find_all(self) -> list[ModelType]:
|
||||
stmt = select(self.model)
|
||||
res = await self.session.execute(stmt)
|
||||
res = [row[0].to_read_model() for row in res.all()]
|
||||
return res
|
@@ -1,4 +1,4 @@
|
||||
from api.repository.user import UserRepository
|
||||
from api.repositories import UserRepository
|
||||
|
||||
|
||||
class UnitOfWork:
|
||||
@@ -9,6 +9,8 @@ class UnitOfWork:
|
||||
self.session = self.session_factory()
|
||||
|
||||
self.users = UserRepository(self.session)
|
||||
print("session id:", id(self.session))
|
||||
print("UoW obj id:", id(self))
|
||||
|
||||
async def __aexit__(self, *args):
|
||||
await self.session.rollback()
|
||||
|
Reference in New Issue
Block a user