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.
§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) -> Query
pub fn with_deleted(self) -> Query
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
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Query
impl RefUnwindSafe for Query
impl Send for Query
impl Sync for Query
impl Unpin for Query
impl UnsafeUnpin for Query
impl UnwindSafe for Query
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more