88from c8y_api ._base_api import CumulocityRestApi
99
1010from c8y_api .model ._base import CumulocityResource , ComplexObject , SimpleObject , _DictWrapper
11- from c8y_api .model ._parser import ComplexObjectParser
11+ from c8y_api .model ._parser import ComplexObjectParser , as_tuples as parse_as_tuples
1212from c8y_api .model ._util import _DateUtil
1313
1414
@@ -161,6 +161,7 @@ def select(
161161 min_age : timedelta = None , max_age : timedelta = None ,
162162 reverse : bool = False , limit : int = None ,
163163 page_size : int = 1000 , page_number : int = None ,
164+ as_tuples : str | tuple | list [str | tuple ] = None ,
164165 ** kwargs
165166 ) -> Generator [Operation ]:
166167 """ Query the database for operations and iterate over the results.
@@ -199,6 +200,10 @@ def select(
199200 related setting.
200201 page_number (int): Pull a specific page; this effectively disables
201202 automatic follow-up page retrieval.
203+ as_tuples: (*str|tuple): Don't parse objects, but directly extract
204+ the values at certain JSON paths as tuples; If the path is not
205+ defined in a result, None is used; Specify a tuple to define
206+ a proper default value for each path.
202207
203208 Returns:
204209 Generator[Operation]: Iterable of matching Operation objects
@@ -211,7 +216,12 @@ def select(
211216 reverse = reverse , page_size = page_size ,
212217 ** kwargs
213218 )
214- return super ()._iterate (base_query , page_number , limit , Operation .from_json )
219+ return super ()._iterate (
220+ base_query ,
221+ page_number ,
222+ limit ,
223+ Operation .from_json if not as_tuples else
224+ lambda x : parse_as_tuples (x , as_tuples ))
215225
216226 def get_all (
217227 self ,
@@ -222,6 +232,7 @@ def get_all(
222232 min_age : timedelta = None , max_age : timedelta = None ,
223233 reverse : bool = False , limit : int = None ,
224234 page_size : int = 1000 , page_number : int = None ,
235+ as_tuples : str | tuple | list [str | tuple ] = None ,
225236 ** kwargs
226237 ) -> List [Operation ]:
227238 """ Query the database for operations and return the results
@@ -237,7 +248,7 @@ def get_all(
237248 expression = expression ,
238249 agent_id = agent_id , device_id = device_id , status = status , bulk_id = bulk_id ,
239250 fragment = fragment , before = before , after = after , min_age = min_age , max_age = max_age ,
240- reverse = reverse , limit = limit , page_size = page_size , page_number = page_number ,
251+ reverse = reverse , limit = limit , page_size = page_size , page_number = page_number , as_tuples = as_tuples ,
241252 ** kwargs
242253 ))
243254
0 commit comments