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
« prev ^ index » next coverage.py v7.17.3, created at 2026-11-20 18:08 +0000
1import typing as t
2import uuid
4from sqlmodel import Session, select
6from geoparser.db.crud.base import BaseRepository
7from geoparser.db.models.context import Context
10class ContextRepository(BaseRepository[Context]):
11 """
12 Repository for Context model operations.
13 """
15 model = Context
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.
22 Args:
23 db: Database session
24 project_id: ID of the project
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()
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.
39 Args:
40 db: Database session
41 project_id: ID of the project
42 tag: Tag identifier
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()