@@ -142,16 +142,18 @@ class RQLQuery: # noqa: WPS214
142142 rql = RQLQuery().nested.field.eq('value')
143143 """
144144
145- AND = "and" # noqa: WPS115
146- OR = "or" # noqa: WPS115
147- EXPRESSION = "expr" # noqa: WPS115
145+ OP_AND = "and" # noqa: WPS115
146+ OP_OR = "or" # noqa: WPS115
147+ OP_ANY = "any" # noqa: WPS115
148+ OP_ALL = "all" # noqa: WPS115
149+ OP_EXPRESSION = "expr" # noqa: WPS115
148150
149151 def __init__ ( # noqa: WPS211
150152 self ,
151153 namespace_ : str | None = None , # noqa: WPS120
152154 ** kwargs : QueryValue ,
153155 ) -> None :
154- self .op : str = self .EXPRESSION
156+ self .op : str = self .OP_EXPRESSION
155157 self .children : list [RQLQuery ] = []
156158 self .negated : bool = False
157159 self .expr : str | None = None
@@ -160,10 +162,10 @@ def __init__( # noqa: WPS211
160162 if namespace_ :
161163 self .n (namespace_ )
162164 if len (kwargs ) == 1 :
163- self .op = self .EXPRESSION
165+ self .op = self .OP_EXPRESSION
164166 self .expr = parse_kwargs (kwargs )[0 ]
165167 if len (kwargs ) > 1 :
166- self .op = self .AND
168+ self .op = self .OP_AND
167169 for token in parse_kwargs (kwargs ):
168170 self .children .append (self .new (expr = token ))
169171
@@ -180,14 +182,14 @@ def new(
180182 if isinstance (children , set ):
181183 children = list (children )
182184 query = cls ()
183- query .op = op or cls .EXPRESSION
185+ query .op = op or cls .OP_EXPRESSION
184186 query .children = children or []
185187 query .negated = negated
186188 query .expr = expr
187189 return query
188190
189191 def __len__ (self ) -> int :
190- if self .op == self .EXPRESSION :
192+ if self .op == self .OP_EXPRESSION :
191193 if self .expr :
192194 return 1
193195 return 0
@@ -220,23 +222,23 @@ def __hash__(self) -> int:
220222
221223 @override
222224 def __repr__ (self ) -> str :
223- if self .op == self .EXPRESSION :
225+ if self .op == self .OP_EXPRESSION :
224226 return f"<RQLQuery({ self .op } ) { self .expr } >"
225227 return f"<RQLQuery({ self .op } )>"
226228
227229 def __and__ (self , other : object ) -> Self :
228230 if not isinstance (other , type (self )):
229231 return NotImplemented
230- return self ._join (other , self .AND )
232+ return self ._join (other , self .OP_AND )
231233
232234 def __or__ (self , other : object ) -> Self :
233235 if not isinstance (other , type (self )):
234236 return NotImplemented
235- return self ._join (other , self .OR )
237+ return self ._join (other , self .OP_OR )
236238
237239 def __invert__ (self ) -> Self :
238240 inverted_query = self .new (
239- op = self .AND ,
241+ op = self .OP_AND ,
240242 expr = self .expr ,
241243 negated = True ,
242244 )
@@ -250,6 +252,29 @@ def __getattr__(self, name: str) -> Self:
250252 def __str__ (self ) -> str :
251253 return self ._to_string (self )
252254
255+ def any (self ) -> Self :
256+ """Any nested objects have to match the filter condition.
257+
258+ Returns:
259+ RQLQuery: RQLQuery with new condition
260+
261+ Examples:
262+ RQLQuery(saleDetails__orderQty__gt=11).any()
263+ will result: any(saleDetails,orderQty=11)
264+ """
265+ return self .new (op = self .OP_ANY , children = [self ])
266+
267+ def all (self ) -> Self :
268+ """All nested objects have to match the filter condition.
269+
270+ Returns:
271+ RQLQuery: RQLQuery with new condition
272+
273+ Example:
274+ RQLQuery(saleDetails__orderQty__gt=1).all()
275+ """
276+ return self .new (op = self .OP_ALL , children = [self ])
277+
253278 def n (self , name : str ) -> Self : # noqa: WPS111
254279 """Set the current field for this `RQLQuery` object.
255280
@@ -485,7 +510,7 @@ def _join(self, other: "RQLQuery", op: str) -> Self:
485510 def _append (self , query : "RQLQuery" ) -> "RQLQuery" | Self :
486511 if query in self .children :
487512 return query
488- single_operation = len (query ) == 1 and query .op != self .EXPRESSION
513+ single_operation = len (query ) == 1 and query .op != self .OP_EXPRESSION
489514 if (query .op == self .op or single_operation ) and not query .negated :
490515 self .children .extend (query .children )
491516 return self
0 commit comments