Coverage for src/fluree_py/http/mixin/where.py: 100%

11 statements  

« prev     ^ index     » next       coverage.py v7.8.0, created at 2025-04-02 03:03 +0000

1"""Mixin for handling where clause operations in Fluree queries.""" 

2 

3from typing import Generic, TypeVar, cast 

4 

5from fluree_py.http.mixin.utils import resolve_base_class_reference 

6from fluree_py.http.protocol.mixin.where import HasWhereData 

7from fluree_py.types.query.where import WhereClause 

8 

9T = TypeVar("T", bound="HasWhereData") 

10 

11 

12class WithWhereMixin(Generic[T]): 

13 """Provides where clause capabilities for Fluree queries.""" 

14 

15 def with_where(self: T, clause: WhereClause) -> T: 

16 """Updates the query with a new where clause. 

17 

18 Exceptions: 

19 TypeError: If the type parameter cannot be resolved. 

20 """ 

21 resolved_type = resolve_base_class_reference(self.__class__, "WithWhereMixin") 

22 

23 # Create a new instance of the resolved type 

24 updated_fields = self.__dict__.copy() 

25 updated_fields["where"] = clause 

26 return cast(T, resolved_type(**updated_fields))