24 lines
614 B
Python
24 lines
614 B
Python
from api.repositories import UserRepository
|
|
|
|
|
|
class UnitOfWork:
|
|
def __init__(self, session_factory):
|
|
self.session_factory = session_factory
|
|
|
|
async def __aenter__(self):
|
|
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()
|
|
await self.session.close()
|
|
|
|
async def commit(self):
|
|
await self.session.commit()
|
|
|
|
async def rollback(self):
|
|
await self.session.rollback()
|