Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def and_also(self):
if len(self._where_tokens) > 0:
last = self._where_tokens[-1]
if last:
if isinstance(self.query_parameters[last.value], QueryOperator):
raise InvalidOperationException("Cannot add AND, previous token was already an QueryOperator.")
self._where_tokens.append(_Token(value=QueryOperator.AND, write="AND"))
return self
def _add_operator_if_needed(self):
self.assert_no_raw_query()
if len(self._where_tokens) > 0:
query_operator = None
last_token = self._where_tokens[-1]
if last_token is not None and last_token.token in Query.where_operators:
query_operator = QueryOperator.AND if self.default_operator == QueryOperator.AND else QueryOperator.OR
search_operator = getattr(last_token, "search_operator", None)
if search_operator and search_operator != QueryOperator.OR:
# default to OR operator after search if AND was not specified explicitly
query_operator = QueryOperator.OR
if query_operator:
self._where_tokens.append(_Token(write=str(query_operator)))
elif token.token == "equals":
write = " = $" + token.value
elif token.token == "not_equals":
write = " != $" + token.value
elif token.token == "greater_than":
write = " > $" + token.value
elif token.token == "greater_than_or_equal":
write = " >= $" + token.value
elif token.token == "less_than":
write = " < $" + token.value
elif token.token == "less_than_or_equal":
write = " <= $" + token.value
elif token.token == "search":
write_builder = [", $", token.value]
search_operator = getattr(token, "search_operator", None)
if search_operator and search_operator == QueryOperator.AND:
write_builder.append(", AND")
write_builder.append(")")
write = "".join(write_builder)
elif token.token == "lucene":
write = ", $" + token.value + ")"
elif token.token == "startsWith":
write = ", $" + token.value + ")"
elif token.token == "endsWith":
write = ", $" + token.value + ")"
elif token.token == "exists":
write = ")"
elif token.token == "select":
write_builder = []
for value in token.value:
if len(write_builder) > 0:
write_builder.append(", ")