summaryrefslogtreecommitdiff
path: root/app/node_modules/okdb/index.js
diff options
context:
space:
mode:
authorSean Fridman <fridman@mail.sfsu.edu>2015-04-07 23:05:44 -0400
committerSean Fridman <fridman@mail.sfsu.edu>2015-04-07 23:05:44 -0400
commit68fc2c92fad18c1685f5d67048d3147bb38d55c7 (patch)
tree7418995f1ff084b9a92349547ae4f2e9a9ae3c13 /app/node_modules/okdb/index.js
parent007384de007844e865bf906b8cb6eadaed4027e6 (diff)
ID fields for resources now determined by app config
Diffstat (limited to 'app/node_modules/okdb/index.js')
-rw-r--r--app/node_modules/okdb/index.js48
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() {