Coverage for kwai/modules/identity/users/user_db_query.py: 100%
21 statements
« prev ^ index » next coverage.py v7.3.0, created at 2023-09-05 17:55 +0000
« prev ^ index » next coverage.py v7.3.0, created at 2023-09-05 17:55 +0000
1"""Module that implements the UserQuery interface for a database."""
2from kwai.core.db.database_query import DatabaseQuery
3from kwai.core.domain.value_objects.email_address import EmailAddress
4from kwai.core.domain.value_objects.unique_id import UniqueId
5from kwai.modules.identity.users.user import UserIdentifier
6from kwai.modules.identity.users.user_query import UserQuery
7from kwai.modules.identity.users.user_tables import UsersTable
10class UserDbQuery(UserQuery, DatabaseQuery):
11 """A user query for a database."""
13 def init(self):
14 self._query.from_(UsersTable.table_name)
16 @property
17 def columns(self):
18 return UsersTable.aliases()
20 def filter_by_id(self, id_: UserIdentifier) -> UserQuery:
21 """Add a filter for a user with the given id."""
22 self._query.and_where(UsersTable.field("id").eq(id_.value))
23 return self
25 def filter_by_uuid(self, uuid: UniqueId) -> UserQuery:
26 """Add a filter for a user with the given unique id."""
27 self._query.and_where(UsersTable.field("uuid").eq(str(uuid)))
28 return self
30 def filter_by_email(self, email: EmailAddress) -> UserQuery:
31 """Add a filter for a user with the given email address."""
32 self._query.and_where(UsersTable.field("email").eq(str(email)))
33 return self