def _makeparams(self): params = [utils.escape('%s:@"%s"' % target) for target in self._target.items()] param = Expression.OR.join(params) exprs = [utils.escape(self._makeexpr(expr)) for expr in self._expr] expr = Expression.OR.join(exprs) result = param and '(%s)' % param if result and expr: result += Expression.AND result += expr return '--query "%s"' % result if result else ''
def _makeparams(self): params = ['%s:@%s' % (k, utils.escape(v, True)) for k, v in sorted(self._target.items())] op = QueryExpression.operator[Operator.BIT_OR] param = op.join(params) expr = op.join(expr.build(QueryExpression) for expr in self._exprs) result = param and '(%s)' % param if result and expr: result += QueryExpression.operator[Operator.BIT_AND] result += expr return '--query %s' % utils.escape(result, True) if result else ''
def __str__(self): value = self.value if value is True: expr_str = 'true' elif value is False: expr_str = 'false' elif value is None: expr_str = 'null' elif isinstance(value, (datetime, date)): expr_str = utils.escape(value.strftime('%Y/%m/%d %H:%M:%S.%f')) else: expr_str = utils.escape(utils.to_text(value)) # TODO: Geo point, Array return expr_str
def _make_match_columns(self): if self._match_columns: exprs = (e.build(MatchColumn) for e in self._match_columns) result = MatchColumn.operator[Operator.OR].join(exprs) return '--match_columns %s' % utils.escape(result, True) else: return ''
def __str__(self): return ' '.join(( 'load', '--table', self._table.__tablename__, '--input_type', 'json', '--each', "'suggest_preparer(_id, type, item, sequence, time, pair_query)'", utils.escape(self._makejson(), True)))
def __str__(self): return ' '.join(( 'suggest', '--table', '"%s"' % self._table.__tablename__, '--column', '"%s"' % self._table.kana.name, '--types', '"%s"' % self._types, self._condition(), '--query', utils.escape(self._query, True)))
def __str__(self): return 'suggest --table "%(table)s" --column "%(column)s" --types ' \ '"%(types)s" %(condition)s --query "%(query)s"' % \ dict(table=self._table.__tablename__, column=self._table.kana.name, types=self._types, condition=self._condition(), query=utils.escape(self._query))
def delete(self, key=None, id=None, filter=None): """Get the 'delete' query :param table: Table class :param key: string of key of record, default is None :param id: string of id of record, default is None :param filter: instance of ExpressionTree or string of filter, default is None :returns: :class:`SimpleQuery` object """ query = ['delete', '--table', self._table.__tablename__] if key is not None: query.extend(('--key', key)) if id is not None: query.extend(('--id', str(id))) if filter is not None: query.extend(('--filter', utils.escape(str(filter), True))) self._query.extend(query) return self
def __str__(self): return ' '.join(( 'load', '--table', self._table.__tablename__, '--input-type', 'json', '--values', utils.escape(self._makejson(), True)))
def __str__(self): expr_str = utils.to_text(getattr(self.value, 'lvalue', self.value)) return utils.escape(expr_str)
def _makefilters(self): if not self._filters: return '' exprs = (e.build(FilterExpression) for e in self._filters) result = FilterExpression.operator[Operator.OR].join(exprs) return '--filter %s' % utils.escape(result, True)
def _makejson(self): return utils.escape(json.dumps([v.asdict() for v in self._data]))
def test_escape(values, expected): result = utils.escape(*values) assert result == expected