Call a func on every part of SOQL query except nested (SELECT ...)
422120
def transform_except_subquery(sql, func):
    """"""
    start = 0
    out = []
    while sql.find('(SELECT', start) > -1:
        pos = sql.find('(SELECT', start)
        out.append(func(sql[start:pos]))
        start, pos = find_closing_parenthesis(sql, pos)
        out.append(sql[start:pos])
        start = pos
    out.append(func(sql[start:len(sql)]))
    return ''.join(out)
289426
def any2sql(func, definition_dict=None, **definition_kwargs):
    
    if definition_dict and definition_kwargs:
        raise InputError("Cannot process dict and kwargs input at the same time")

    definition = load_input(definition_dict or definition_kwargs)

    if definition.get('returning', '') == '*':
        definition['returning'] = mosql_raw('*')

    try:
        result = func(**definition)
    except (TypeError, AttributeError) as exc:
        raise ClauseError("Clause definition error: %s" % str(exc)) from exc
    except Exception as exc:
        import json2sql.errors as json2sql_errors

        if exc.__class__.__name__ not in json2sql_errors.__dict__.keys():
            raise json2sql_errors.Json2SqlInternalError("Unhandled error: %s" % str(exc)) from exc
        raise

    return result
784026
def filter(self, **kwargs):
        """"""
        assert not self._primary_keys
        self.queryset = self.queryset.filter(**kwargs)
        return self
183170
def selectnotnone(table, field, complement=False):
    """"""

    return select(table, field, lambda v: v is not None,
                  complement=complement)
1236206
def visit_FunctionBody(self, node):
        """"""
        for child in node.children:
            return_value = self.visit(child)

            if isinstance(child, ReturnStatement):
                return return_value

            if isinstance(child, (IfStatement, WhileStatement)):
                if return_value is not None:
                    return return_value

        return NoneType()
720010
def query_func_module(self, func):
        """"""
        exp = self.session.query(Export).filter_by(
            func=func).first()
        if exp:
            return exp
        logging.debug(_('Function not found: %s'), func)
        alt = func + 'A'
        exp = self.session.query(Export).filter_by(
            func=alt).first()
        if exp:
            logging.warning(_('Using ANSI version: %s'), alt)
            return exp
        logging.warning(_('Not handled: %s or %s'), func, alt)
        return None
312450
def _call_with_selection(func):
    """"""
    wrapped_kwonly_params = [
        param for param in inspect.signature(func).parameters.values()
        if param.kind == param.KEYWORD_ONLY]
    sel_sig = inspect.signature(Selection)
    default_sel_sig = sel_sig.replace(
        parameters=[param.replace(default=None) if param.default is param.empty
                    else param
                    for param in sel_sig.parameters.values()])

    @functools.wraps(func)
    def wrapper(*args, **kwargs):
        extra_kw = {param.name: kwargs.pop(param.name)
                    for param in wrapped_kwonly_params if param.name in kwargs}
        ba = default_sel_sig.bind(*args, **kwargs)
        # apply_defaults
        ba.arguments = ChainMap(
            ba.arguments,
            {name: param.default
             for name, param in default_sel_sig.parameters.items()
             if param.default is not param.empty})
        sel = Selection(*ba.args, **ba.kwargs)
        return func(sel, **extra_kw)

    wrapper.__signature__ = Signature(
        list(sel_sig.parameters.values()) + wrapped_kwonly_params)
    return wrapper
617332
def And(*predicates, **kwargs):
    
    if kwargs:
        predicates += Query(**kwargs),
    return _flatten(_And, *predicates)
402584
def query(request):
    """"""

    def inner(func, obj):
        result_code = func(obj, request)

        if result_code is not constants.OK:
            raise OpusError(result_code)

        return result_code

    return inner
310827
def query_all(**kwargs):
        '''
        
        '''
        kind = kwargs.get('kind', '1')
        limit = kwargs.get('limit', 10)

        return TabPost.select().where(
            (TabPost.kind == kind) &
            (TabPost.valid == 1)
        ).order_by(
            TabPost.time_update.desc()
        ).limit(limit)
982178
def query_params(*es_query_params):
    

    def _wrapper(func):
        @wraps(func)
        def _wrapped(*args, **kwargs):
            params = {}
            if "params" in kwargs:
                params = kwargs.pop("params").copy()
            for p in es_query_params + GLOBAL_PARAMS:
                if p in kwargs:
                    v = kwargs.pop(p)
                    if v is not None:
                        params[p] = _escape(v)

            # don't treat ignore and request_timeout as other params to avoid escaping
            for p in ("ignore", "request_timeout"):
                if p in kwargs:
                    params[p] = kwargs.pop(p)
            return func(*args, params=params, **kwargs)

        return _wrapped

    return _wrapper
665959
function(query) {
    var qparts = getQueryParts(goog.string.trim(query));

    // if it's trivial, avoid iteration and zipping costs
    if (qparts.length == 1) {
      // We optimize this case here to prevent dispatch further down the
      // chain, potentially slowing things down. We could more elegantly
      // handle this in filterDown(), but it's slower for simple things
      // that need to be fast (e.g., '#someId').
      var tef = getElementsFunc(qparts[0]);
      return function(root) {
        var r = tef(root, []);
        if (r) { r.nozip = true; }
        return r;
      }
    }

    // otherwise, break it up and return a runner that iterates over the parts
    // recursively
    return function(root) {
      return filterDown(root, qparts);
    }
  }
765311
def _query(options, collection_name, num_to_skip,
           num_to_return, query, field_selector, opts, check_keys):
    """"""
    encoded = _dict_to_bson(query, check_keys, opts)
    if field_selector:
        efs = _dict_to_bson(field_selector, False, opts)
    else:
        efs = b""
    max_bson_size = max(len(encoded), len(efs))
    return b"".join([
        _pack_int(options),
        _make_c_string(collection_name),
        _pack_int(num_to_skip),
        _pack_int(num_to_return),
        encoded,
        efs]), max_bson_size
896976
function(query,options) {
           for (var key in query) {
               if (query[key].$in) {
                   query[key]=query[key].$in;
               }
           }
           return this.inherited(arguments);
       }
397304
def filter_t(func):
    
    return Transformation('filter({0})'.format(name(func)),
                          partial(filter, func),
                          {ExecutionStrategies.PARALLEL})
1258812
function whereHandler (obj) {
  let result = {}

  Object.keys(obj).forEach(k => {
    if (this.attributes.some(field => k.startsWith(field))) {
      _queryField2where.call(this, result, k, obj[k])
    }
    if (k === 'limit' || k === 'offset') {
      return
    }
    if (k.match(/\.\w+/)) {
      includeHandler.call(this, k, obj[k])
    }
  })

  return result
}
1067586
def auto_consume(func):
    """"""
    def inner(*args, **kwargs):
        func(*args, **kwargs)
        args[0].consume_line()
    return inner