pub enum Query {
Eq {
field: String,
value: Value,
},
Lt {
field: String,
value: Value,
},
Gt {
field: String,
value: Value,
},
And(Vec<Query>),
Or(Vec<Query>),
Not(Box<Query>),
All,
Custom(String),
IncludeDeleted(Box<Query>),
DeletedOnly,
WithinRadius {
center: GeoPoint,
radius_meters: f64,
lat_field: Option<String>,
lon_field: Option<String>,
},
WithinBounds {
min: GeoPoint,
max: GeoPoint,
lat_field: Option<String>,
lon_field: Option<String>,
},
}Expand description
Query abstraction that works across backends
Provides a simple query language that can be translated to backend-specific query formats (Ditto DQL, Automerge queries, etc).
§Spatial Queries (Issue #356)
Spatial queries filter documents by geographic location:
WithinRadius: Documents within a specified distance of a center pointWithinBounds: Documents within a rectangular bounding box
Documents must have lat and lon fields (or configurable field names) for
spatial queries to match.
Variants§
Eq
Simple equality match: field == value
Lt
Less than: field < value
Gt
Greater than: field > value
And(Vec<Query>)
Multiple conditions combined with AND
Or(Vec<Query>)
Multiple conditions combined with OR
Not(Box<Query>)
Negation of a query (Issue #357)
Matches documents that do NOT match the inner query.
All
All documents in collection (no filter)
Custom(String)
Custom backend-specific query string Use sparingly - limits backend portability
IncludeDeleted(Box<Query>)
Include soft-deleted documents in query results
By default, queries exclude documents with _deleted=true (soft-deleted).
This modifier includes those documents in the results.
§Example
// Default: excludes deleted documents
let query = Query::All;
// Include deleted documents
let query_with_deleted = Query::IncludeDeleted(Box::new(Query::All));
// With a filter
let filtered_with_deleted = Query::IncludeDeleted(Box::new(Query::Eq {
field: "type".to_string(),
value: Value::String("contact_report".to_string()),
}));DeletedOnly
Only return soft-deleted documents
Matches only documents where _deleted=true.
Useful for auditing or restoring deleted records.
WithinRadius
Documents within a radius of a center point
Requires documents to have lat and lon fields (or fields specified
by lat_field and lon_field).
Fields
WithinBounds
Documents within a rectangular bounding box
Requires documents to have lat and lon fields (or fields specified
by lat_field and lon_field).
Implementations§
Source§impl Query
impl Query
Sourcepub fn includes_deleted(&self) -> bool
pub fn includes_deleted(&self) -> bool
Check if this query includes deleted documents
Returns true if the query is IncludeDeleted or DeletedOnly.
Sourcepub fn is_deleted_only(&self) -> bool
pub fn is_deleted_only(&self) -> bool
Check if this query only matches deleted documents
Sourcepub fn with_deleted(self) -> Self
pub fn with_deleted(self) -> Self
Wrap this query to include deleted documents
If already IncludeDeleted or DeletedOnly, returns self unchanged.
Sourcepub fn inner_query(&self) -> &Query
pub fn inner_query(&self) -> &Query
Get the inner query if this is an IncludeDeleted wrapper
Sourcepub fn matches_deletion_state(&self, doc: &Document) -> bool
pub fn matches_deletion_state(&self, doc: &Document) -> bool
Check if a document matches the soft-delete filter
- For normal queries: document must NOT have
_deleted=true - For
IncludeDeleted: document can have any_deletedvalue - For
DeletedOnly: document MUST have_deleted=true