Skip to content

Commit f2ac23c

Browse files
committed
Add LogicalQueryOperator
1 parent af022ed commit f2ac23c

1 file changed

Lines changed: 45 additions & 0 deletions

File tree

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
//
2+
// LogicalQueryOperator.swift
3+
//
4+
//
5+
// Created by Alsey Coleman Miller on 8/21/23.
6+
//
7+
8+
import Foundation
9+
import Predicate
10+
11+
/// Logical Query Operators
12+
///
13+
/// Logical operators return data based on expressions that evaluate to true or false.
14+
///
15+
/// [Documentation](https://www.mongodb.com/docs/v7.0/reference/operator/query-comparison/)
16+
public enum LogicalQueryOperator: String, Codable, CaseIterable {
17+
18+
/// Joins query clauses with a logical AND returns all documents that match the conditions of both clauses.
19+
case and = "$and"
20+
21+
/// Joins query clauses with a logical OR returns all documents that match the conditions of either clause.
22+
case or = "$or"
23+
24+
/// Inverts the effect of a query expression and returns documents that do not match the query expression.
25+
case not = "$not"
26+
27+
/// Joins query clauses with a logical NOR returns all documents that fail to match both clauses.
28+
case nor = "$nor"
29+
}
30+
31+
// MARK: - Predicate
32+
33+
public extension LogicalQueryOperator {
34+
35+
init(predicate: Compound.Logical​Type) {
36+
switch predicate {
37+
case .and:
38+
self = .and
39+
case .or:
40+
self = .or
41+
case .not:
42+
self = .not
43+
}
44+
}
45+
}

0 commit comments

Comments
 (0)