pub enum Comparison {
Equal(ParseValue),
EqualOperator(ParseValue),
NotEqual(ParseValue),
GreaterThan(ParseValue),
GreaterThanOrEqual(ParseValue),
LessThan(ParseValue),
LessThanOrEqual(ParseValue),
In(Vec<ParseValue>),
NotIn(Vec<ParseValue>),
Exists(bool),
All(Vec<ParseValue>),
Regex {
pattern: String,
options: Option<String>,
},
}Expand description
How one field is compared to one value.
Variants§
Equal(ParseValue)
Bare equality: {"field": value}. Lowers to the value itself, with no operator wrapper.
EqualOperator(ParseValue)
Explicit $eq: {"field": {"$eq": value}}.
Deliberately not the same variant as Comparison::Equal, because the two do not lower
the same way. Bare equality puts the value directly under the field, so it cannot share
the field with another operator: {"n": 5} and {"n": {"$gt": 1}} are two whole documents
for one key and merging them means one overwrites the other. $eq is an operator like any
other and composes, which is the entire reason upstream’s replaceEquality rewrites a
mixed constraint into this form rather than leaving it bare (RestQuery.js:828-849).
Folding the two together compiles, passes a round-trip test, and silently undoes that rewrite one layer below where it was applied.
It also must not pin an objectId. ParsedWhere::pinned_object_id reads the shorthand form
only, matching upstream’s direct query.objectId read (DatabaseController.js:1838), and
a separate variant is what keeps {"objectId": {"$eq": "x"}} out of that path.
NotEqual(ParseValue)
GreaterThan(ParseValue)
GreaterThanOrEqual(ParseValue)
LessThan(ParseValue)
LessThanOrEqual(ParseValue)
In(Vec<ParseValue>)
NotIn(Vec<ParseValue>)
Exists(bool)
All(Vec<ParseValue>)
$all: the array field contains every listed value.
Regex
$regex, with $options folded in.
The two arrive as separate keys and upstream keeps them separate all the way down, relying
on reverse-alphabetical key iteration so that $regex is handled before $options
(MongoTransform.js:670-675). Folding them into one variant here removes the ordering
dependency without changing what reaches the backend, because a lone $options is
meaningless and a lone $regex gets None.
Implementations§
Source§impl Comparison
impl Comparison
Sourcepub fn from_operator(op: &str, value: ParseValue) -> Result<Self, ParseError>
pub fn from_operator(op: &str, value: ParseValue) -> Result<Self, ParseError>
Map a Parse $ operator onto a comparison.
Returns INVALID_QUERY for anything unsupported. That is the whole point: the alternative,
ignoring it, returns more rows than the caller asked for.
$regex and $options are not handled here, because they are two keys producing one
comparison. The caller assembles them; see parse_operators in parse-rust-rest.
Trait Implementations§
Source§impl Clone for Comparison
impl Clone for Comparison
Source§fn clone(&self) -> Comparison
fn clone(&self) -> Comparison
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more