MCPcopy
hub / github.com/msiemens/tinydb / any

Method any

tinydb/queries.py:393–426  ·  view source on GitHub ↗

Check if a condition is met by any document in a list, where a condition can also be a sequence (e.g. list). >>> Query().f1.any(Query().f2 == 1) Matches:: {'f1': [{'f2': 1}, {'f2': 0}]} >>> Query().f1.any([1, 2, 3]) Matches::

(self, cond: Union[QueryInstance, List[Any]])

Source from the content-addressed store, hash-verified

391 )
392
393 def any(self, cond: Union[QueryInstance, List[Any]]) -> QueryInstance:
394 """
395 Check if a condition is met by any document in a list,
396 where a condition can also be a sequence (e.g. list).
397
398 >>> Query().f1.any(Query().f2 == 1)
399
400 Matches::
401
402 {'f1': [{'f2': 1}, {'f2': 0}]}
403
404 >>> Query().f1.any([1, 2, 3])
405
406 Matches::
407
408 {'f1': [1, 2]}
409 {'f1': [3, 4, 5]}
410
411 :param cond: Either a query that at least one document has to match or
412 a list of which at least one document has to be contained
413 in the tested document.
414 """
415 if callable(cond):
416 def test(value):
417 return is_sequence(value) and any(cond(e) for e in value)
418
419 else:
420 def test(value):
421 return is_sequence(value) and any(e in cond for e in value)
422
423 return self._generate_test(
424 lambda value: test(value),
425 ('any', self._path, freeze(cond))
426 )
427
428 def all(self, cond: Union['QueryInstance', List[Any]]) -> QueryInstance:
429 """

Callers 1

test_anyFunction · 0.80

Calls 3

_generate_testMethod · 0.95
testFunction · 0.85
freezeFunction · 0.85

Tested by 1

test_anyFunction · 0.64