def find(*query_criteria: Union[Tag, List[Tag], Tuple[Tag], QueryObject, TagSet], prefix: Optional[str]) -> QueryObject
Query for memo objects based on search criteria such as tags, types, or subqueries.
The primary way to search for objects. All top-level criteria are combined using AND logic - objects must satisfy all conditions to be included in the query result.
Parameters
-
*query_criteriaUnion[Tag, List[Tag], Tuple[Tag], QueryObject, TagSet]
Variable number of criteria to filter objects:- Type: A class to filter by type (includes subclasses)
- String tag: Simple string tag
- Object tag: Any memo object used as a tag
- List of tags (OR): Objects with at least one of the specified tags
- Tuple of tags (AND): Objects with all of the specified tags
- QueryObject: Result of another query
- TagSet: Set logical operation (e.g.,
dbzero.no()for negation)
-
prefixstr, optional
Optional data prefix to run the query on. If omitted, the prefix to run the query is resolved from query criteria.
Returns
A lazily-evaluated, iterable query object. The actual lookup is deferred until you iterate over the result.
A QueryObject is an iterable that also support:
len(): to check the size of the result set- Slicing: to get a range of elements from the result set
- Boolean evaluation: to test for empty result set in an
ifstatement
Examples
Find by type
# Finds all instances of MemoTestClass and its subclasses
results = db0.find(MemoTestClass)Find by tag
# Finds all objects with 'tag1'
results = db0.find("tag1")Find with multiple criteria (AND)
results = db0.find(MemoTestClass, "tag1")Find with OR tags
# Finds objects with 'tag1' OR 'tag2'
results = db0.find(['tag1', 'tag2'])Find with AND tags
# Finds objects with 'tag1' AND 'tag2'
results = db0.find(('tag1', 'tag2'))Find with subquery
# Finds objects of type MemoTestClass that also have 'tag1'
# and are within a specific index range.
index = db0.index()
# ... populate index ...
subquery = index.select(100, 200)
results = db0.find(MemoTestClass, "tag1", subquery)Find with negation
# Finds objects in snap2's query that were not in snap1's query
created_objects = snap2.find(query_2, db0.no(query_1))Find in specific prefix
# Finds objects with 'tag1' only within the 'customer-data' prefix
results = db0.find("tag1", prefix="customer-data")