from fluxcrud.transactions import UnitOfWork
async def register_user(user_data: dict):
uow = UnitOfWork()
try:
async with uow:
# Get repositories bound to the same transaction
user_repo = uow.repository(User, UserSchema)
profile_repo = uow.repository(Profile, ProfileSchema)
# 1. Create User
user = await user_repo.create(user_data)
# 2. Create Profile
await profile_repo.create({"user_id": user.id, "bio": "New user"})
# Transaction commits automatically at the end of the block
# if no exception is raised
except Exception as e:
# Rollback happens automatically on exception
print(f"Registration failed: {e}")
raise