summaryrefslogtreecommitdiff
path: root/app/node_modules/okdb/index.js
diff options
context:
space:
mode:
Diffstat (limited to 'app/node_modules/okdb/index.js')
-rw-r--r--app/node_modules/okdb/index.js56
1 files changed, 22 insertions, 34 deletions
diff --git a/app/node_modules/okdb/index.js b/app/node_modules/okdb/index.js
index f32627c..cf670c1 100644
--- a/app/node_modules/okdb/index.js
+++ b/app/node_modules/okdb/index.js
@@ -10,64 +10,52 @@ low.mixin(low.mixin(require('underscore-db')));
function OKDB(options) {
if (!(this instanceof OKDB)) return new OKDB(options);
options = options || {};
- this._db = options.db || JSONDown('db');
+ var type;
+ if (typeof options === 'string')
+ type = options;
+ else
+ type = options.type;
+ if (!type)
+ throw new Error('No DB type provided');
+ switch (type) {
+ case 'fs':
+ return FSDB(options);
+ default:
+ throw new Error('Invalid DB type');
+ }
}
-OKDB.prototype.getMeta = function() {
- return this._db.getMeta();
-};
-
-OKDB.prototype.putMeta = function(meta) {
- return this._db.putMeta(meta);
-}
-
-OKDB.prototype.get = function(collection, id) {
- return this._db.get(collection, id);
-};
-
-OKDB.prototype.getAll = function(collection) {
- return this._db.getAll(collection);
-};
-
-OKDB.prototype.put = function(collection, id) {
- return this._db.put(collection, id);
-};
-
-OKDB.prototype.putBatch = function(collection, data) {
- return this._db.putBatch(collection, data);
-};
-
/**
* DB implementation backed by a JSON file.
- * TODO Unfinished
+ * TODO Incomplete
*/
-function JSONDown(name, options) {
- if (!(this instanceof JSONDown)) return new JSONDown(name, options);
+function FSDB(options) {
+ if (!(this instanceof FSDB)) return new FSDB(options);
options = options || {};
+ var name = options.name || 'db';
var filename = name + '.json';
this._db = low(filename);
}
-JSONDown.prototype._resolve = function(data) {
+FSDB.prototype._resolve = function(data) {
return Q.Promise(function resolvePromise(resolve, reject) {
resolve(data);
});
};
-JSONDown.prototype.get = function(collection, id) {
+FSDB.prototype.get = function(collection, id) {
var data = this._db(collection).get(id);
- return this._resolve(data || {});
+ return this._resolve(data);
};
-JSONDown.prototype.getMeta = function() {
+FSDB.prototype.getMeta = function() {
var data = this._db('meta').first();
return this._resolve(data || {});
};
-JSONDown.prototype.getAll = function(collection) {
+FSDB.prototype.getAll = function(collection) {
var data = this._db(collection).toArray();
return this._resolve(data || []);
};
module.exports = OKDB;
-module.exports.JSONDown = JSONDown;