Coverage for src/kwai/modules/portal/applications/application_db_query.py: 100%

25 statements  

« prev     ^ index     » next       coverage.py v7.6.10, created at 2024-01-01 00:00 +0000

1"""Module that implements an ApplicationQuery for a database.""" 

2 

3from kwai.core.db.database_query import DatabaseQuery 

4from kwai.modules.portal.applications.application import ApplicationIdentifier 

5from kwai.modules.portal.applications.application_query import ApplicationQuery 

6from kwai.modules.portal.applications.application_tables import ApplicationsTable 

7 

8 

9class ApplicationDbQuery(ApplicationQuery, DatabaseQuery): 

10 """A database query for an application.""" 

11 

12 def init(self): 

13 return self._query.from_(ApplicationsTable.table_name) 

14 

15 @property 

16 def columns(self): 

17 return ApplicationsTable.aliases() 

18 

19 def filter_by_id(self, id_: ApplicationIdentifier) -> "ApplicationQuery": 

20 self._query.and_where(ApplicationsTable.field("id").eq(id_.value)) 

21 return self 

22 

23 def filter_by_name(self, name: str) -> "ApplicationQuery": 

24 self._query.and_where(ApplicationsTable.field("name").eq(name)) 

25 return self 

26 

27 def filter_only_news(self) -> "ApplicationQuery": 

28 self._query.and_where(ApplicationsTable.field("news").eq(True)) 

29 return self 

30 

31 def filter_only_pages(self) -> "ApplicationQuery": 

32 self._query.and_where(ApplicationsTable.field("pages").eq(True)) 

33 return self 

34 

35 def filter_only_events(self) -> "ApplicationQuery": 

36 self._query.and_where(ApplicationsTable.field("events").eq(True)) 

37 return self