diff options
| -rw-r--r-- | app/node_modules/okdb/index.js | 11 | ||||
| -rw-r--r-- | app/node_modules/okquery/index.js | 3 | ||||
| -rw-r--r-- | app/node_modules/okresource/index.js | 11 |
3 files changed, 23 insertions, 2 deletions
diff --git a/app/node_modules/okdb/index.js b/app/node_modules/okdb/index.js index 7639ec6..c00087c 100644 --- a/app/node_modules/okdb/index.js +++ b/app/node_modules/okdb/index.js @@ -117,6 +117,17 @@ FSDB.prototype.remove = function(collection, id) { } }; +FSDB.prototype.sortBy = function(collection, prop, descend) { + var schema = this._schemas[collection]; + if (!schema) + return resolve(null, new Error('No such collection type')); + if (!prop) + return resolve(null, new Error('Bad input')); + + var result = this._db(collection).sortByOrder([prop], [!descend]); + return resolve(result); +}; + FSDB.prototype.find = function(collection, id) { var schema = this._schemas[collection]; if (!schema) diff --git a/app/node_modules/okquery/index.js b/app/node_modules/okquery/index.js index 89c8b73..9cc8b78 100644 --- a/app/node_modules/okquery/index.js +++ b/app/node_modules/okquery/index.js @@ -96,7 +96,8 @@ function queryDynamic(resource) { function queryAll(resource) { return function() { - return resource.all(); + // Always return sorted results + return resource.sortBy('__index'); }; } diff --git a/app/node_modules/okresource/index.js b/app/node_modules/okresource/index.js index df89617..8c0bb16 100644 --- a/app/node_modules/okresource/index.js +++ b/app/node_modules/okresource/index.js @@ -122,12 +122,21 @@ OKResource.prototype.update = function(id, data) { reject(new Error('No resource ID provided')); } else if (!data) { reject(new Error('No data provided')); - }else { + } else { db.update(type, id, data).then(resolve).fail(reject);; } }); }; + +/** + * Get all documents in collection sorted by property, + * optionally in descending order + */ +OKResource.prototype.sortBy = function(prop, descend) { + return this._db.sortBy(this.type, prop, descend); +}; + /** * Update all resources with the given ids with the given data */ |
