Coverage for geoparser/db/crud/context.py: 100%

15 statements  

« prev     ^ index     » next       coverage.py v7.17.3, created at 2026-11-20 18:08 +0000

1import typing as t 

2import uuid 

3 

4from sqlmodel import Session, select 

5 

6from geoparser.db.crud.base import BaseRepository 

7from geoparser.db.models.context import Context 

8 

9 

10class ContextRepository(BaseRepository[Context]): 

11 """ 

12 Repository for Context model operations. 

13 """ 

14 

15 model = Context 

16 

17 @classmethod 

18 def get_by_project(cls, db: Session, project_id: uuid.UUID) -> t.List[Context]: 

19 """ 

20 Get all context records for a project. 

21 

22 Args: 

23 db: Database session 

24 project_id: ID of the project 

25 

26 Returns: 

27 List of context records 

28 """ 

29 statement = select(Context).where(Context.project_id == project_id) 

30 return db.exec(statement).unique().all() 

31 

32 @classmethod 

33 def get_by_project_and_tag( 

34 cls, db: Session, project_id: uuid.UUID, tag: str 

35 ) -> t.Optional[Context]: 

36 """ 

37 Get a specific context record by project and tag. 

38 

39 Args: 

40 db: Database session 

41 project_id: ID of the project 

42 tag: Tag identifier 

43 

44 Returns: 

45 Context record if found, None otherwise 

46 """ 

47 statement = select(Context).where( 

48 Context.project_id == project_id, 

49 Context.tag == tag, 

50 ) 

51 return db.exec(statement).unique().first()