From 68fc2c92fad18c1685f5d67048d3147bb38d55c7 Mon Sep 17 00:00:00 2001 From: Sean Fridman Date: Tue, 7 Apr 2015 23:05:44 -0400 Subject: ID fields for resources now determined by app config --- app/node_modules/okdb/index.js | 48 +++++++++++++++++++++++++++++++++++------- 1 file changed, 40 insertions(+), 8 deletions(-) (limited to 'app/node_modules/okdb/index.js') diff --git a/app/node_modules/okdb/index.js b/app/node_modules/okdb/index.js index 6c01df0..3089411 100644 --- a/app/node_modules/okdb/index.js +++ b/app/node_modules/okdb/index.js @@ -37,19 +37,51 @@ function FSDB(options) { this._db = low(filename); } -FSDB.prototype._resolve = function(data, success) { - success = typeof success === 'undefined' ? true : success; +FSDB.prototype._resolve = function(data, error) { return Q.Promise(function resolvePromise(resolve, reject) { - if (success) + if (error) { + reject(error); + } else { resolve(data); - else - reject(data); + } }); }; -FSDB.prototype.get = function(collection, id) { - var data = this._db(collection).get(id); - return this._resolve(data); +FSDB.prototype.get = function(collection, query) { + var data = this._db(collection).find(query); + if (!query) { + return this._resolve(null, new Error('No query given')); + } else { + return this._resolve(data); + } +}; + +FSDB.prototype.put = function(collection, query, data) { + data = data || {}; + if (!query) { + return this._resolve(null, new Error('No query given')); + } else if (this._db(collection).find(query)) { + var updated = this._db(collection) + .chain() + .find(query) + .assign(data) + .value(); + return this._resolve(updated); + } else { + return this._resolve(null, new Error('Cannot update nonexistent entry')); + } +}; + +FSDB.prototype.create = function(collection, id, data) { + throw new Error('Not implemented!'); +}; + +FSDB.prototype.remove = function(collection, id, data) { + throw new Error('Not implemented!'); +}; + +FSDB.prototype.find = function(collection, id, data) { + throw new Error('Not implemented!'); }; FSDB.prototype.getMeta = function() { -- cgit v1.2.3-70-g09d2