summaryrefslogtreecommitdiff
path: root/app/node_modules/okquery/index.js
diff options
context:
space:
mode:
authorjulie lala <jules@okfoc.us>2015-04-11 11:42:27 -0400
committerjulie lala <jules@okfoc.us>2015-04-11 11:42:27 -0400
commit65c1c6541f98eb863f9a19533f4bdb4bd9e38514 (patch)
tree84cbe0902cc355b9e1556c346f217d1a4cafd552 /app/node_modules/okquery/index.js
parent0b6afc1d5aa8a2f33b1c21e04a10c3eaa43870c1 (diff)
parent2b95bcf414f02551a384ef2020958e90431814dd (diff)
merge
Diffstat (limited to 'app/node_modules/okquery/index.js')
-rw-r--r--app/node_modules/okquery/index.js12
1 files changed, 11 insertions, 1 deletions
diff --git a/app/node_modules/okquery/index.js b/app/node_modules/okquery/index.js
index 2d93e2a..9cc8b78 100644
--- a/app/node_modules/okquery/index.js
+++ b/app/node_modules/okquery/index.js
@@ -1,3 +1,4 @@
+var cloneDeep = require('lodash.clonedeep');
var assign = require('object-assign');
var isobject = require('lodash.isobject');
var Q = require('q');
@@ -16,6 +17,9 @@ function OKQuery(options) {
var resource = options.resource;
var type = resource.type;
var query = options.query || '*';
+ // Ensure immutability
+ if (isobject(query))
+ query = cloneDeep(query);
Object.defineProperty(this, 'resource', {
value: resource,
@@ -55,6 +59,9 @@ function createQuery(resource, query, options) {
function queryComplex(resource, query) {
var dynamicProp;
+ // Query is an object specifying key value pairs against which
+ // to match DB entries. Iterate through and check if any of the values
+ // is unbound e.g. :id
var notDynamic = Object.keys(query).every(function(prop) {
var matcher = query[prop];
if (isDynamic(matcher)) {
@@ -71,6 +78,8 @@ function queryComplex(resource, query) {
}
} else {
return function(id) {
+ // Bind the dynamic property to its value
+ // and add the pair to the query
var dynamicQuery = {};
dynamicQuery[dynamicProp] = id;
var query = assign({}, query, dynamicQuery);
@@ -87,7 +96,8 @@ function queryDynamic(resource) {
function queryAll(resource) {
return function() {
- return resource.all();
+ // Always return sorted results
+ return resource.sortBy('__index');
};
}