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
impl Query
pub fn new() -> Self
pub fn is_empty(&self) -> bool
pub fn push(&mut self, clause: Clause)
pub fn push_constraint(&mut self, constraint: Constraint)
Sourcepub fn extend(&mut self, other: Query)
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.
Sourcepub fn conjoin(&mut self, other: Query)
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.
Sourcepub fn constrains_field(&self, field: &str) -> bool
pub fn constrains_field(&self, field: &str) -> bool
Does a top-level clause constrain this field?
Sourcepub fn any_of(alternatives: Vec<Query>) -> Query
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.
pub fn from_constraints(constraints: Vec<Constraint>) -> Query
Sourcepub fn top_level_constraints(&self) -> impl Iterator<Item = &Constraint>
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.