20
20
using firebase::firestore::model::FieldPath;
21
21
using firebase::firestore::util::MakeString;
22
22
using firebase::firestore::core::FieldFilter;
23
+ using firebase::firestore::core::CompositeFilter;
23
24
24
25
NS_ASSUME_NONNULL_BEGIN
25
26
31
32
32
33
} // namespace
33
34
34
- @interface FIRFilter ()
35
+ @interface FSTUnaryFilter ()
35
36
36
37
@property (nonatomic , strong , readwrite ) FIRFieldPath *fieldPath;
37
- @property (nonatomic , readwrite ) FieldFilter::Operator op ;
38
+ @property (nonatomic , readwrite ) FieldFilter::Operator unaryOp ;
38
39
@property (nonatomic , strong , readwrite ) id value;
39
40
40
41
@end
41
42
42
- @implementation FIRFilter
43
-
44
- #pragma mark - Constructor Methods
43
+ @implementation FSTUnaryFilter
45
44
46
45
- (instancetype )initWithFIRFieldPath : (nonnull FIRFieldPath *)fieldPath
47
46
op : (FieldFilter::Operator)op
48
47
value : (nonnull id )value {
49
48
if (self = [super init ]) {
50
49
self.fieldPath = fieldPath;
51
- self.op = op;
50
+ self.unaryOp = op;
52
51
self.value = value;
53
52
}
54
53
return self;
55
54
}
56
55
56
+ @end
57
+
58
+ @interface FSTCompositeFilter ()
59
+
60
+ @property (nonatomic , strong , readwrite ) NSArray <FIRFilter *> *filters;
61
+ @property (nonatomic , readwrite ) CompositeFilter::Operator compOp;
62
+
63
+ @end
64
+
65
+ @implementation FSTCompositeFilter
66
+
67
+ - (instancetype )initWithFilters : (nonnull NSArray <FIRFilter *> *)filters
68
+ op : (CompositeFilter::Operator)op {
69
+ if (self = [super init ]) {
70
+ self.filters = filters;
71
+ self.compOp = op;
72
+ }
73
+ return self;
74
+ }
75
+
76
+ @end
77
+
78
+ @implementation FIRFilter
79
+
80
+ #pragma mark - Constructor Methods
81
+
57
82
+ (FIRFilter *)filterWhereField : (nonnull NSString *)field isEqualTo : (nonnull id )value {
58
83
return [self filterWhereFieldPath: MakeFIRFieldPath (field) isEqualTo: value];
59
84
}
60
85
61
86
+ (FIRFilter *)filterWhereFieldPath : (nonnull FIRFieldPath *)field isEqualTo : (nonnull id )value {
62
- return [[FIRFilter alloc ] initWithFIRFieldPath: field op:FieldFilter: :Operator: :Equal value: value];
87
+ return [[FSTUnaryFilter alloc ] initWithFIRFieldPath: field
88
+ op:FieldFilter: :Operator: :Equal
89
+ value: value];
63
90
}
64
91
65
92
+ (FIRFilter *)filterWhereField : (nonnull NSString *)field isNotEqualTo : (nonnull id )value {
66
93
return [self filterWhereFieldPath: MakeFIRFieldPath (field) isNotEqualTo: value];
67
94
}
68
95
69
96
+ (FIRFilter *)filterWhereFieldPath : (nonnull FIRFieldPath *)field isNotEqualTo : (nonnull id )value {
70
- return [[FIRFilter alloc ] initWithFIRFieldPath: field
71
- op:FieldFilter: :Operator: :NotEqual
72
- value: value];
97
+ return [[FSTUnaryFilter alloc ] initWithFIRFieldPath: field
98
+ op:FieldFilter: :Operator: :NotEqual
99
+ value: value];
73
100
}
74
101
75
102
+ (FIRFilter *)filterWhereField : (nonnull NSString *)field isGreaterThan : (nonnull id )value {
76
103
return [self filterWhereFieldPath: MakeFIRFieldPath (field) isGreaterThan: value];
77
104
}
78
105
79
106
+ (FIRFilter *)filterWhereFieldPath : (nonnull FIRFieldPath *)field isGreaterThan : (nonnull id )value {
80
- return [[FIRFilter alloc ] initWithFIRFieldPath: field
81
- op:FieldFilter: :Operator: :GreaterThan
82
- value: value];
107
+ return [[FSTUnaryFilter alloc ] initWithFIRFieldPath: field
108
+ op:FieldFilter: :Operator: :GreaterThan
109
+ value: value];
83
110
}
84
111
85
112
+ (FIRFilter *)filterWhereField : (nonnull NSString *)field isGreaterThanOrEqualTo : (nonnull id )value {
@@ -88,19 +115,19 @@ + (FIRFilter *)filterWhereField:(nonnull NSString *)field isGreaterThanOrEqualTo
88
115
89
116
+ (FIRFilter *)filterWhereFieldPath : (nonnull FIRFieldPath *)field
90
117
isGreaterThanOrEqualTo : (nonnull id )value {
91
- return [[FIRFilter alloc ] initWithFIRFieldPath: field
92
- op:FieldFilter: :Operator: :GreaterThanOrEqual
93
- value: value];
118
+ return [[FSTUnaryFilter alloc ] initWithFIRFieldPath: field
119
+ op:FieldFilter: :Operator: :GreaterThanOrEqual
120
+ value: value];
94
121
}
95
122
96
123
+ (FIRFilter *)filterWhereField : (nonnull NSString *)field isLessThan : (nonnull id )value {
97
124
return [self filterWhereFieldPath: MakeFIRFieldPath (field) isLessThan: value];
98
125
}
99
126
100
127
+ (FIRFilter *)filterWhereFieldPath : (nonnull FIRFieldPath *)field isLessThan : (nonnull id )value {
101
- return [[FIRFilter alloc ] initWithFIRFieldPath: field
102
- op:FieldFilter: :Operator: :LessThan
103
- value: value];
128
+ return [[FSTUnaryFilter alloc ] initWithFIRFieldPath: field
129
+ op:FieldFilter: :Operator: :LessThan
130
+ value: value];
104
131
}
105
132
106
133
+ (FIRFilter *)filterWhereField : (nonnull NSString *)field isLessThanOrEqualTo : (nonnull id )value {
@@ -109,19 +136,19 @@ + (FIRFilter *)filterWhereField:(nonnull NSString *)field isLessThanOrEqualTo:(n
109
136
110
137
+ (FIRFilter *)filterWhereFieldPath : (nonnull FIRFieldPath *)field
111
138
isLessThanOrEqualTo : (nonnull id )value {
112
- return [[FIRFilter alloc ] initWithFIRFieldPath: field
113
- op:FieldFilter: :Operator: :LessThanOrEqual
114
- value: value];
139
+ return [[FSTUnaryFilter alloc ] initWithFIRFieldPath: field
140
+ op:FieldFilter: :Operator: :LessThanOrEqual
141
+ value: value];
115
142
}
116
143
117
144
+ (FIRFilter *)filterWhereField : (nonnull NSString *)field arrayContains : (nonnull id )value {
118
145
return [self filterWhereFieldPath: MakeFIRFieldPath (field) arrayContains: value];
119
146
}
120
147
121
148
+ (FIRFilter *)filterWhereFieldPath : (nonnull FIRFieldPath *)field arrayContains : (nonnull id )value {
122
- return [[FIRFilter alloc ] initWithFIRFieldPath: field
123
- op:FieldFilter: :Operator: :ArrayContains
124
- value: value];
149
+ return [[FSTUnaryFilter alloc ] initWithFIRFieldPath: field
150
+ op:FieldFilter: :Operator: :ArrayContains
151
+ value: value];
125
152
}
126
153
127
154
+ (FIRFilter *)filterWhereField : (nonnull NSString *)field
@@ -131,17 +158,19 @@ + (FIRFilter *)filterWhereField:(nonnull NSString *)field
131
158
132
159
+ (FIRFilter *)filterWhereFieldPath : (nonnull FIRFieldPath *)field
133
160
arrayContainsAny : (nonnull NSArray <id> *)values {
134
- return [[FIRFilter alloc ] initWithFIRFieldPath: field
135
- op:FieldFilter: :Operator: :ArrayContainsAny
136
- value: values];
161
+ return [[FSTUnaryFilter alloc ] initWithFIRFieldPath: field
162
+ op:FieldFilter: :Operator: :ArrayContainsAny
163
+ value: values];
137
164
}
138
165
139
166
+ (FIRFilter *)filterWhereField : (nonnull NSString *)field in : (nonnull NSArray <id> *)values {
140
167
return [self filterWhereFieldPath: MakeFIRFieldPath (field) in: values];
141
168
}
142
169
143
170
+ (FIRFilter *)filterWhereFieldPath : (nonnull FIRFieldPath *)field in : (nonnull NSArray <id> *)values {
144
- return [[FIRFilter alloc ] initWithFIRFieldPath: field op:FieldFilter: :Operator: :In value: values];
171
+ return [[FSTUnaryFilter alloc ] initWithFIRFieldPath: field
172
+ op:FieldFilter: :Operator: :In
173
+ value: values];
145
174
}
146
175
147
176
+ (FIRFilter *)filterWhereField : (nonnull NSString *)field notIn : (nonnull NSArray <id> *)values {
@@ -150,11 +179,18 @@ + (FIRFilter *)filterWhereField:(nonnull NSString *)field notIn:(nonnull NSArray
150
179
151
180
+ (FIRFilter *)filterWhereFieldPath : (nonnull FIRFieldPath *)field
152
181
notIn : (nonnull NSArray <id> *)values {
153
- return [[FIRFilter alloc ] initWithFIRFieldPath: field
154
- op:FieldFilter: :Operator: :NotIn
155
- value: values];
182
+ return [[FSTUnaryFilter alloc ] initWithFIRFieldPath: field
183
+ op:FieldFilter: :Operator: :NotIn
184
+ value: values];
156
185
}
157
186
187
+ + (FIRFilter *)orFilterWithFilters : (NSArray <FIRFilter *> *)filters {
188
+ return [[FSTCompositeFilter alloc ] initWithFilters: filters op:CompositeFilter: :Operator: :Or];
189
+ }
190
+
191
+ + (FIRFilter *)andFilterWithFilters : (NSArray <FIRFilter *> *)filters {
192
+ return [[FSTCompositeFilter alloc ] initWithFilters: filters op:CompositeFilter: :Operator: :And];
193
+ }
158
194
@end
159
195
160
196
NS_ASSUME_NONNULL_END
0 commit comments