Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
Specify either the __query or the kwargs. If __query is
specified it is returned unchanged. If kwargs is passed these
are used to build a new MongoQ object. The rationale for this
is so that build_query can be used without an if statement in
the calling code (i.e. this methods wraps the if statement on
whether to build a new MongoQ object or to use the existing,
making for more readable code).
:param __query: the MongoQ object to use
:param kwargs: the filter as a dict of column__op=value pairs
:return: the MongoQ object
"""
if __query:
q = __query
else:
q = MongoQ(**kwargs)
return q
stop -= int(self.positional)
flt_kwargs['{}__lte'.format(col)] = stop
elif isinstance(spec, enumerable_types) and isscalar(spec[0]):
self._from_range = True
# single column index with list of scalar values
# -- convert to list for PyMongo serialization
if isinstance(spec, np.ndarray):
spec = spec.tolist()
flt_kwargs['{}__in'.format(col)] = spec
elif isscalar(col):
flt_kwargs[col] = spec
else:
# we're out of index columns, let's look at columns
projection.extend(self._get_projection(spec))
if flt_kwargs:
filterq.append(MongoQ(**flt_kwargs))
finalq = None
for q in filterq:
if finalq:
finalq |= q
else:
finalq = q
return finalq, projection
def _get_filter_criteria(self, *args, **kwargs):
"""
return mongo query from filter specs
this uses a Filter to produce the query from the kwargs.
:param args: a Q object or logical combination of Q objects
(optional)
:param kwargs: all AND filter criteria
"""
if len(args) > 0:
q = args[0]
if isinstance(q, MongoQ):
filter_criteria = Filter(self.collection, q).query
elif isinstance(q, Filter):
filter_criteria = Filter(self.collection, q.q).query
else:
filter_criteria = Filter(self.collection, **kwargs).query
return filter_criteria