Coverage for src/kwai/modules/identity/users/user_db_query.py: 100%
21 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 that implements the UserQuery interface for a database."""
3from kwai.core.db.database_query import DatabaseQuery
4from kwai.core.domain.value_objects.email_address import EmailAddress
5from kwai.core.domain.value_objects.unique_id import UniqueId
6from kwai.modules.identity.users.user import UserIdentifier
7from kwai.modules.identity.users.user_query import UserQuery
8from kwai.modules.identity.users.user_tables import UserRow
11class UserDbQuery(UserQuery, DatabaseQuery):
12 """A user query for a database."""
14 def init(self):
15 self._query.from_(UserRow.__table_name__)
17 @property
18 def columns(self):
19 return UserRow.get_aliases()
21 def filter_by_id(self, id_: UserIdentifier) -> UserQuery:
22 """Add a filter for a user with the given id."""
23 self._query.and_where(UserRow.field("id").eq(id_.value))
24 return self
26 def filter_by_uuid(self, uuid: UniqueId) -> UserQuery:
27 """Add a filter for a user with the given unique id."""
28 self._query.and_where(UserRow.field("uuid").eq(str(uuid)))
29 return self
31 def filter_by_email(self, email: EmailAddress) -> UserQuery:
32 """Add a filter for a user with the given email address."""
33 self._query.and_where(UserRow.field("email").eq(str(email)))
34 return self