diff options
Diffstat (limited to 'app/node_modules/okdb')
| -rw-r--r-- | app/node_modules/okdb/index.js | 48 |
1 files changed, 40 insertions, 8 deletions
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() { |
