Query System¶
AutoCRUD provides a flexible query system for searching resources.
The recommended method is the Query Builder (QB) syntax, which allows expressive queries using a safe AST-based parser.
This page describes:
- the Query Builder (
QB) - how to query resource metadata and data fields
- logical operators
- how queries are passed through HTTP APIs
Query Builder (QB)¶
The QB class provides a Python-style syntax for building queries.
Example:
Example with multiple conditions:
This syntax is parsed safely using an AST parser rather than eval.
Data field queries¶
Data fields are accessed using bracket notation.
Examples:
Nested fields are supported:
Field names with special characters are supported:
Resource metadata fields¶
QB also provides built-in accessors for resource metadata.
These correspond to fields stored in ResourceMeta.
| Field | Description |
|---|---|
QB.resource_id() |
Resource identifier |
QB.revision_id() |
Current revision ID |
QB.created_time() |
Resource creation timestamp |
QB.updated_time() |
Resource last update timestamp |
QB.created_by() |
Creator |
QB.updated_by() |
Last updater |
QB.is_deleted() |
Soft delete status |
QB.schema_version() |
Resource schema version |
QB.total_revision_count() |
Number of revisions |
Examples:
QB.resource_id().eq("abc-123")
QB.created_time() >= datetime(2024, 1, 1)
QB.updated_by().ne("guest")
QB.is_deleted() == False
Logical operators¶
QB supports logical combinations.
AND (&)¶
Equivalent to:
OR (|)¶
Equivalent to:
QB.all() and QB.any()¶
These helper functions combine multiple conditions.
AND group¶
Equivalent to:
If no conditions are provided:
This matches all resources.
OR group¶
Equivalent to:
QB.any() requires at least one condition.
HTTP usage¶
Queries are passed via the qb query parameter.
Example:
Example with multiple conditions:
Example using metadata fields:
Limit and offset¶
Pagination is controlled separately:
These parameters override defaults defined in the query builder.
QB vs JSON conditions¶
AutoCRUD also supports structured JSON query parameters:
data_conditionsconditionssorts
However QB is recommended because:
- it is easier to read
- it supports nested logic
- it avoids complex JSON encoding
- it is parsed safely using AST
If qb is provided, it cannot be combined with:
Examples¶
Basic filter¶
Multiple conditions¶
Metadata query¶
Date filter¶
Complex query¶
Summary¶
Key points:
QBis the recommended query interface- data fields use
QB["field"] - metadata fields use
QB.resource_id()etc. - conditions can be combined with
&,|,QB.all(),QB.any() - queries are passed via the
qbHTTP parameter
See also: - Search indexing