Coverage for kwai/core/domain/repository/query.py: 100%

3 statements  

« prev     ^ index     » next       coverage.py v7.3.0, created at 2023-09-05 17:55 +0000

1"""Module that defines an interface for a query.""" 

2from abc import abstractmethod 

3from typing import Any, AsyncIterator 

4 

5 

6class Query: 

7 """Interface for a query.""" 

8 

9 @abstractmethod 

10 async def count(self) -> int: 

11 """Get the numbers of rows to be returned.""" 

12 raise NotImplementedError 

13 

14 @abstractmethod 

15 async def fetch_one(self) -> dict[str, Any]: 

16 """Fetch just one row.""" 

17 raise NotImplementedError 

18 

19 @abstractmethod 

20 def fetch( 

21 self, limit: int | None = None, offset: int | None = None 

22 ) -> AsyncIterator[dict[str, Any]]: 

23 """Fetch all rows. 

24 

25 A generator should be returned to avoid reading all rows at once. 

26 """ 

27 raise NotImplementedError