File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ //
2+ // ComparisonQueryOperator.swift
3+ //
4+ //
5+ // Created by Alsey Coleman Miller on 8/21/23.
6+ //
7+
8+ import Foundation
9+ import Predicate
10+
11+ /// Comparison Query Operators
12+ ///
13+ /// Comparison operators return data based on value comparisons.
14+ ///
15+ /// [Documentation](https://www.mongodb.com/docs/v7.0/reference/operator/query-comparison/)
16+ public enum ComparisonQueryOperator : String , Codable , CaseIterable {
17+
18+ /// Matches values that are equal to a specified value.
19+ case equalTo = " $eq "
20+
21+ /// Matches all values that are not equal to a specified value.
22+ case notEqualTo = " $ne "
23+
24+ /// Matches values that are greater than a specified value.
25+ case greaterThan = " $gt "
26+
27+ /// Matches values that are greater than or equal to a specified value.
28+ case greaterThanOrEqualTo = " $gte "
29+
30+ /// Matches values that are less than a specified value.
31+ case lessThan = " $lt "
32+
33+ /// Matches values that are less than or equal to a specified value.
34+ case lessThanOrEqualTo = " $lte "
35+
36+ /// Matches any of the values specified in an array.
37+ case `in` = " $in "
38+
39+ /// Matches none of the values specified in an array.
40+ case notIn = " $nin "
41+ }
42+
43+ // MARK: - Predicate
44+
45+ public extension ComparisonQueryOperator {
46+
47+ init ? ( predicate: Comparison . Operator ) {
48+ switch predicate {
49+ case . equalTo:
50+ self = . equalTo
51+ case . greaterThan:
52+ self = . greaterThan
53+ case . greaterThanOrEqualTo:
54+ self = . greaterThanOrEqualTo
55+ case . in:
56+ self = . in
57+ case . lessThan:
58+ self = . lessThan
59+ case . lessThanOrEqualTo:
60+ self = . lessThanOrEqualTo
61+ case . notEqualTo:
62+ self = . notEqualTo
63+ default :
64+ return nil
65+ }
66+ }
67+ }
You can’t perform that action at this time.
0 commit comments