Coverage for src/kwai/modules/club/repositories/coach_db_repository.py: 100%
13 statements
« prev ^ index » next coverage.py v7.6.10, created at 2024-01-01 00:00 +0000
« prev ^ index » next coverage.py v7.6.10, created at 2024-01-01 00:00 +0000
1"""Module for defining a coach repository using a database."""
3from kwai.core.db.database import Database
4from kwai.core.domain.entity import Entity
5from kwai.modules.club.domain.coach import CoachEntity, CoachIdentifier
6from kwai.modules.club.repositories._tables import CoachRow
7from kwai.modules.club.repositories.coach_repository import CoachRepository
10class CoachDbRepository(CoachRepository):
11 """A coach repository using a database."""
13 def __init__(self, database: Database) -> None:
14 self._database = database
16 async def create(self, coach: CoachEntity):
17 new_coach_id = await self._database.insert(
18 CoachRow.__table_name__, CoachRow.persist(coach)
19 )
20 return Entity.replace(coach, id_=CoachIdentifier(new_coach_id))
22 async def delete(self, coach: CoachEntity):
23 await self._database.delete(coach.id.value, CoachRow.__table_name__)