Skip to main content

Query

Enum Query 

Source
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 point
  • WithinBounds: 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

Fields

§field: String
§value: Value
§

Lt

Less than: field < value

Fields

§field: String
§value: Value
§

Gt

Greater than: field > value

Fields

§field: String
§value: 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

§center: GeoPoint

Center point for the radius search

§radius_meters: f64

Radius in meters

§lat_field: Option<String>

Field name for latitude (default: “lat”)

§lon_field: Option<String>

Field name for longitude (default: “lon”)

§

WithinBounds

Documents within a rectangular bounding box

Requires documents to have lat and lon fields (or fields specified by lat_field and lon_field).

Fields

§min: GeoPoint

Southwest corner (minimum lat/lon)

§max: GeoPoint

Northeast corner (maximum lat/lon)

§lat_field: Option<String>

Field name for latitude (default: “lat”)

§lon_field: Option<String>

Field name for longitude (default: “lon”)

Implementations§

Source§

impl Query

Source

pub fn includes_deleted(&self) -> bool

Check if this query includes deleted documents

Returns true if the query is IncludeDeleted or DeletedOnly.

Source

pub fn is_deleted_only(&self) -> bool

Check if this query only matches deleted documents

Source

pub fn with_deleted(self) -> Self

Wrap this query to include deleted documents

If already IncludeDeleted or DeletedOnly, returns self unchanged.

Source

pub fn inner_query(&self) -> &Query

Get the inner query if this is an IncludeDeleted wrapper

Source

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 _deleted value
  • For DeletedOnly: document MUST have _deleted=true

Trait Implementations§

Source§

impl Clone for Query

Source§

fn clone(&self) -> Query

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Query

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more