@@ -15,6 +15,7 @@ class _QueryConditionOp(Enum):
1515 LTE = 9
1616 BETWEEN = 10
1717 NEAREST_NEIGHBOR = 11
18+ CONTAINS_KEY_VALUE = 12
1819
1920
2021class QueryCondition :
@@ -43,7 +44,8 @@ def _get_op_map(self):
4344 _QueryConditionOp .LT : self ._apply_lt ,
4445 _QueryConditionOp .LTE : self ._apply_lte ,
4546 _QueryConditionOp .BETWEEN : self ._apply_between ,
46- _QueryConditionOp .NEAREST_NEIGHBOR : self ._apply_nearest_neighbor
47+ _QueryConditionOp .NEAREST_NEIGHBOR : self ._apply_nearest_neighbor ,
48+ _QueryConditionOp .CONTAINS_KEY_VALUE : self ._contains_key_value
4749 # ... new query condition here ... :)
4850 }
4951
@@ -57,9 +59,6 @@ def _apply_eq(self, qb: 'QueryBuilder'):
5759 else :
5860 raise Exception (f"Unsupported type for 'EQ': { type (value )} " )
5961
60- if self ._alias is not None :
61- qb .alias (self ._alias )
62-
6362 def _apply_not_eq (self , qb : 'QueryBuilder' ):
6463 value = self ._args ['value' ]
6564 case_sensitive = self ._args ['case_sensitive' ]
@@ -70,9 +69,6 @@ def _apply_not_eq(self, qb: 'QueryBuilder'):
7069 else :
7170 raise Exception (f"Unsupported type for 'NOT_EQ': { type (value )} " )
7271
73- if self ._alias is not None :
74- qb .alias (self ._alias )
75-
7672 def _apply_contains (self , qb : 'QueryBuilder' ):
7773 value = self ._args ['value' ]
7874 case_sensitive = self ._args ['case_sensitive' ]
@@ -81,9 +77,6 @@ def _apply_contains(self, qb: 'QueryBuilder'):
8177 else :
8278 raise Exception (f"Unsupported type for 'CONTAINS': { type (value )} " )
8379
84- if self ._alias is not None :
85- qb .alias (self ._alias )
86-
8780 def _apply_starts_with (self , qb : 'QueryBuilder' ):
8881 value = self ._args ['value' ]
8982 case_sensitive = self ._args ['case_sensitive' ]
@@ -92,9 +85,6 @@ def _apply_starts_with(self, qb: 'QueryBuilder'):
9285 else :
9386 raise Exception (f"Unsupported type for 'STARTS_WITH': { type (value )} " )
9487
95- if self ._alias is not None :
96- qb .alias (self ._alias )
97-
9888 def _apply_ends_with (self , qb : 'QueryBuilder' ):
9989 value = self ._args ['value' ]
10090 case_sensitive = self ._args ['case_sensitive' ]
@@ -103,9 +93,6 @@ def _apply_ends_with(self, qb: 'QueryBuilder'):
10393 else :
10494 raise Exception (f"Unsupported type for 'ENDS_WITH': { type (value )} " )
10595
106- if self ._alias is not None :
107- qb .alias (self ._alias )
108-
10996 def _apply_gt (self , qb : 'QueryBuilder' ):
11097 value = self ._args ['value' ]
11198 case_sensitive = self ._args ['case_sensitive' ]
@@ -116,9 +103,6 @@ def _apply_gt(self, qb: 'QueryBuilder'):
116103 else :
117104 raise Exception (f"Unsupported type for 'GT': { type (value )} " )
118105
119- if self ._alias is not None :
120- qb .alias (self ._alias )
121-
122106 def _apply_gte (self , qb : 'QueryBuilder' ):
123107 value = self ._args ['value' ]
124108 case_sensitive = self ._args ['case_sensitive' ]
@@ -129,9 +113,6 @@ def _apply_gte(self, qb: 'QueryBuilder'):
129113 else :
130114 raise Exception (f"Unsupported type for 'GTE': { type (value )} " )
131115
132- if self ._alias is not None :
133- qb .alias (self ._alias )
134-
135116 def _apply_lt (self , qb : 'QueryCondition' ):
136117 value = self ._args ['value' ]
137118 case_sensitive = self ._args ['case_sensitive' ]
@@ -142,9 +123,6 @@ def _apply_lt(self, qb: 'QueryCondition'):
142123 else :
143124 raise Exception ("Unsupported type for 'LT': " + str (type (value )))
144125
145- if self ._alias is not None :
146- qb .alias (self ._alias )
147-
148126 def _apply_lte (self , qb : 'QueryBuilder' ):
149127 value = self ._args ['value' ]
150128 case_sensitive = self ._args ['case_sensitive' ]
@@ -155,9 +133,6 @@ def _apply_lte(self, qb: 'QueryBuilder'):
155133 else :
156134 raise Exception (f"Unsupported type for 'LTE': { type (value )} " )
157135
158- if self ._alias is not None :
159- qb .alias (self ._alias )
160-
161136 def _apply_between (self , qb : 'QueryBuilder' ):
162137 a = self ._args ['a' ]
163138 b = self ._args ['b' ]
@@ -166,9 +141,6 @@ def _apply_between(self, qb: 'QueryBuilder'):
166141 else :
167142 raise Exception (f"Unsupported type for 'BETWEEN': { type (a )} " )
168143
169- if self ._alias is not None :
170- qb .alias (self ._alias )
171-
172144 def _apply_nearest_neighbor (self , qb : 'QueryBuilder' ):
173145 query_vector = self ._args ['query_vector' ]
174146 element_count = self ._args ['element_count' ]
@@ -184,8 +156,15 @@ def _apply_nearest_neighbor(self, qb: 'QueryBuilder'):
184156 else :
185157 raise Exception (f"Unsupported type for 'NEAREST_NEIGHBOR': { type (query_vector )} " )
186158
187- if self ._alias is not None :
188- qb .alias (self ._alias )
159+ def _contains_key_value (self , qb : 'QueryBuilder' ):
160+ key = self ._args ['key' ]
161+ value = self ._args ['value' ]
162+ case_sensitive = self ._args ['case_sensitive' ]
163+ qb .contains_key_value (self ._property_id , key , value , case_sensitive )
189164
190165 def apply (self , qb : 'QueryBuilder' ):
166+ """ Applies the stored condition to the supplied query builder. """
191167 self ._get_op_map ()[self ._op ](qb )
168+
169+ if self ._alias is not None :
170+ qb .alias (self ._alias )
0 commit comments