Skip to main content

Query

Struct Query 

Source
pub struct Query {
    pub clauses: Vec<Clause>,
}
Expand description

A conjunction of clauses. An empty query matches everything.

Fields§

§clauses: Vec<Clause>

Implementations§

Source§

impl Query

Source

pub fn new() -> Self

Source

pub fn is_empty(&self) -> bool

Source

pub fn push(&mut self, clause: Clause)

Source

pub fn push_constraint(&mut self, constraint: Constraint)

Source

pub fn extend(&mut self, other: Query)

Conjoin another query into this one.

Splicing the other query’s clauses in rather than nesting an And keeps the common case flat, which matters because the compiled Mongo document is snapshot-compared. Nesting would be equally correct and would change every fixture.

Only safe when the two queries cannot name the same field. Two constraints on one field spliced side by side either merge, which silently drops one, or collide and fail; Query::conjoin is the one to reach for when a server-imposed predicate meets a client-supplied one.

Source

pub fn conjoin(&mut self, other: Query)

Conjoin another query into this one without letting either predicate be lost.

A field the receiver already constrains at top level is nested under And instead of spliced in beside the existing constraint. Upstream does the same thing and for the same reason: addPointerPermissions tests hasOwnProperty(query, key) and falls back to reduceAndOperation({$and: [queryClause, query]}) when it holds (DatabaseController.js:1807-1811).

Splicing instead is not a cosmetic difference. A client that queries owner explicitly on a class whose find CLP names owner as a pointer field produces two equalities on one field, which merge_constraint reports as INVALID_QUERY rather than answering the query.

Top level only, matching hasOwnProperty: a field named inside an $or is a different key as far as the compiled document is concerned and cannot collide.

Source

pub fn constrains_field(&self, field: &str) -> bool

Does a top-level clause constrain this field?

Source

pub fn any_of(alternatives: Vec<Query>) -> Query

A disjunction of alternatives, simplified the way reduceOrOperation does (DatabaseController.js:1657-1724): an $or with a single element collapses into that element rather than staying wrapped.

Source

pub fn from_constraints(constraints: Vec<Constraint>) -> Query

Source

pub fn top_level_constraints(&self) -> impl Iterator<Item = &Constraint>

Every top-level field constraint, ignoring nested logical clauses.

Used by the pieces that need to know whether a query is pinned to one objectId. It is deliberately not a general “find the constraint on field X”, because inside an $or no such thing exists.

Trait Implementations§

Source§

impl Clone for Query

Source§

fn clone(&self) -> Query

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · 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
Source§

impl Default for Query

Source§

fn default() -> Query

Returns the “default value” for a type. Read more
Source§

impl From<Vec<Constraint>> for Query

Source§

fn from(constraints: Vec<Constraint>) -> Self

Converts to this type from the input type.

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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, 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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V