Coverage for kwai/modules/portal/applications/application_db_query.py: 100%
25 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 an ApplicationQuery for a database."""
2from kwai.core.db.database_query import DatabaseQuery
3from kwai.modules.portal.applications.application import ApplicationIdentifier
4from kwai.modules.portal.applications.application_query import ApplicationQuery
5from kwai.modules.portal.applications.application_tables import ApplicationsTable
8class ApplicationDbQuery(ApplicationQuery, DatabaseQuery):
9 """A database query for an application."""
11 def init(self):
12 return self._query.from_(ApplicationsTable.table_name)
14 @property
15 def columns(self):
16 return ApplicationsTable.aliases()
18 def filter_by_id(self, id_: ApplicationIdentifier) -> "ApplicationQuery":
19 self._query.and_where(ApplicationsTable.field("id").eq(id_.value))
20 return self
22 def filter_by_name(self, name: str) -> "ApplicationQuery":
23 self._query.and_where(ApplicationsTable.field("name").eq(name))
24 return self
26 def filter_only_news(self) -> "ApplicationQuery":
27 self._query.and_where(ApplicationsTable.field("news").eq(True))
28 return self
30 def filter_only_pages(self) -> "ApplicationQuery":
31 self._query.and_where(ApplicationsTable.field("pages").eq(True))
32 return self
34 def filter_only_events(self) -> "ApplicationQuery":
35 self._query.and_where(ApplicationsTable.field("events").eq(True))
36 return self