RETURN ORDER BY CLAUSE
354807
def _sort2sql(self, sort):
        
        if not sort:
            return ""
        return SQL_ORDERBY + sql_list([quote_column(o.field) + (" DESC" if o.sort == -1 else "") for o in sort])
703621
def get_find_all_query(self, table_name, constraints=None, *, columns=None, order_by=None,
                         limiting=(None, None)):
    
    where, params = self.parse_constraints(constraints)

    if columns:
      if isinstance(columns, str):
        pass
      else:
        columns = ", ".join(columns)
    else:
      columns = "*"

    if order_by:
      order = " order by {0}".format(order_by)
    else:
      order = ""

    paging = ""
    if limiting is not None:
      limit, offset = limiting
      if limit is not None:
        paging += " limit {0}".format(limit)
      if offset is not None:
        paging += " offset {0}".format(offset)

    return ("select {0} from {1} where {2}{3}{4}".format(
      columns,
      table_name,
      where or "1 = 1",
      order,
      paging
    ), params)
1226286
def order_by(self, order_attribute):
        '''  '''
        to_return = []
        for f in sorted(self.items, key=lambda i: getattr(i, order_attribute)):
            to_return.append(f)
        return to_return
1093678
def order_by(self, field_name=None):
        
        assert self.query.can_filter(), "Cannot reorder a query once a slice has been taken."

        clone = self._clone()
        clone.query.clear_ordering()

        if field_name is not None:
            clone.query.add_ordering(field_name)

        return clone
197240
def order_by(self, *field_names):
        
        if not self._search_ordered:
            self._search_ordered = len(self._search_terms) > 0
        return super(SearchableQuerySet, self).order_by(*field_names)
1178573
def order_by(self, *criterion):
        
        query = self._copy()
        query._order_by = criterion
        return query
149210
function orderby (args, order) {
    if (this.typecheck) t.typecheck('orderby', [args, order]);
    
    var o = (order&&'string'===typeof order) ? order : '';
    var result = [];

    if ('string'===typeof args) {
        result = o ? [args+' '+o] : [args];
    }
    else if (args instanceof Array) {
        for (var i=0; i < args.length; i++) {
            if ('string'===typeof args[i]) {
                o ? result.push(args[i]+' '+o) : result.push(args[i]);
            }
            else if ('object'===typeof args[i]) {
                var key = Object.keys(args[i])[0];
                result.push(key+' '+args[i][key]);
            }
        }
    }
    else if (args instanceof Object) {
        var key = Object.keys(args)[0];
        result = [key+' '+args[key]];
    }

    return 'order by '+result.join();
}
867410
def top(self, sort_by):
        """"""
        sort = sorted(self.results, key=sort_by)
        return sort
1319936
def _order_as_range(order):
    """"""
    order = order.split('-')
    order = [int(o) for o in order]
    if len(order) > 1:
        order = range(order[0], (order[-1] + 1))
    return order
188714
function sortQueryresults(matches, order) {
  const orderArray = order.split(',').map(k => {
    let dir = 'asc';
    let key = k;

    if (k.charAt(0) === '-') {
      key = k.substring(1);
      dir = 'desc';
    }

    return [item => deserializeQueryParam(item[key]), dir];
  });

  const keys = orderArray.map(_.first);
  const orders = orderArray.map(_.last);

  return _.orderBy(matches, keys, orders);
}
267441
public function reverseOrderBy()
    {
        $order = $this->getOrderBy();
        $this->orderby = array();

        foreach ($order as $clause => $dir) {
            $dir = (strtoupper($dir) == 'DESC') ? 'ASC' : 'DESC';
            $this->addOrderBy($clause, $dir);
        }

        return $this;
    }
353440
def all(self, order_by=None, limit=0):
        
        with rconnect() as conn:
            try:
                query = self._base()
                if order_by is not None:
                    query = self._order_by(query, order_by)
                if limit > 0:
                    query = self._limit(query, limit)

                log.debug(query)
                rv = query.run(conn)
            except Exception as e:
                log.warn(e)
                raise
            else:
                data = [self._model(_) for _ in rv]
                return data
762400
def _get_formatted_query(self, fields, limit, order_by, offset):
        

        if not isinstance(order_by, list):
            raise InvalidUsage("Argument order_by should be a `list` of fields")

        if not isinstance(fields, list):
            raise InvalidUsage("Argument fields should be a `list` of fields")

        if isinstance(self.query, QueryBuilder):
            sysparm_query = str(self.query)
        elif isinstance(self.query, dict):  # Dict-type query
            sysparm_query = '^'.join(['%s=%s' % (k, v) for k, v in six.iteritems(self.query)])
        elif isinstance(self.query, six.string_types):  # String-type query
            sysparm_query = self.query
        else:
            raise InvalidUsage("Query must be instance of %s, %s or %s" % (QueryBuilder, str, dict))

        for field in order_by:
            if field[0] == '-':
                sysparm_query += "^ORDERBYDESC%s" % field[1:]
            else:
                sysparm_query += "^ORDERBY%s" % field

        params = {'sysparm_query': sysparm_query}
        params.update(self.request_params)

        if limit is not None:
            params.update({'sysparm_limit': limit, 'sysparm_suppress_pagination_header': True})

        if offset is not None:
            params.update({'sysparm_offset': offset})

        if len(fields) > 0:
            params.update({'sysparm_fields': ",".join(fields)})

        return params
348979
public function order($query)
    {
        $clause = '';

        if (!empty($query->order)) {
            $clause = 'ORDER BY ';
            $list = array();
            foreach ($query->order as $order) {
                $columns = AnDomainQueryHelper::parseColumns($query, $order['column']);
                foreach ($columns as $column) {
                    $list[] = $column.' '.$order['direction'];
                }
            }

            $clause .= implode(' , ', $list);
        }

        return $clause;
    }
1020335
def sort(self, request, reverse=False):
        """"""
        field = self.model._meta.fields.get(self.columns_sort)
        if not field:
            return self.collection

        if reverse:
            field = field.desc()

        return self.collection.order_by(field)
124202
def fetch_order(self, order_id: str) -> Order:
        """"""
        return self._fetch(f'order id={order_id}', exc=OrderNotFound)(self._order)(order_id)
1337698
def get_order(self, codes):
        """"""
        return sorted(codes, key=lambda e: [self.ev2idx.get(e)])