mekanika/query

View on GitHub
lib/proto/sort.js

Summary

Maintainability
A
0 mins
Test Coverage
/**
  Setup exports reference
*/

module.exports = exports;

/**
  Specify sorting order based on string keys (including `-` prefix strings)

  ```
  query().sort( "-age name" );
  ```

  @param {String} [keys] The space separated names of the field to sort on

  @return {Query}
  @public
*/

exports.sort = function (keys) {
  if (!this.qe.sort) this.qe.sort = keys.split(' ');
  else this.qe.sort.push.apply(this.qe.sort, keys.split(' '));

  return this;
};