API Reference
find

def find(*query_criteria: Union[Tag, List[Tag], Tuple[Tag], QueryObject, TagSet], prefix: Optional[str]) -> QueryObject

Open SourceStandard

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_criteria Union[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
    • Composite tag: A structured tag created with db0.as_tag(...) dbzero-procommercial edition
    • 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)
  • prefix str, 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 if statement
⚠️

Passive tags are a dbzero-pro feature. A query that may read passive tag entries must include at least one positive non-passive predicate, such as a memo type, a regular tag, an enum tag, a direct object predicate, or an anchored query. For example, db0.find(Document, "passive-tag") is valid, while db0.find("passive-tag") raises.


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 composite tags

dbzero-procommercial edition
# Finds documents readable by a user in one workspace
results = db0.find(Document, db0.as_tag("GRANT-READ", workspace, user))
 
# Finds overdue invoices within one tenant
overdue = db0.find(Invoice, db0.as_tag("CATEGORY", tenant, "invoice", "overdue"))

Find with passive tags

dbzero-procommercial edition
# Valid: the regular tag anchors the passive predicate
results = db0.find("active", "visible-to-current-user")
 
# Valid: the memo type anchors the passive predicate
documents = db0.find(Document, "visible-to-current-user")
 
# Invalid: passive-only queries raise
list(db0.find("visible-to-current-user"))

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")