summaryrefslogtreecommitdiff
path: root/app/node_modules/okdb
diff options
context:
space:
mode:
Diffstat (limited to 'app/node_modules/okdb')
-rw-r--r--app/node_modules/okdb/index.js73
-rw-r--r--app/node_modules/okdb/package.json16
2 files changed, 89 insertions, 0 deletions
diff --git a/app/node_modules/okdb/index.js b/app/node_modules/okdb/index.js
new file mode 100644
index 0000000..f32627c
--- /dev/null
+++ b/app/node_modules/okdb/index.js
@@ -0,0 +1,73 @@
+var Q = require('q');
+var format = require('util').format;
+var low = require('lowdb');
+low.mixin(low.mixin(require('underscore-db')));
+
+/**
+ * OKDB!
+ * Minimal interface over a database of named collections of documents.
+ */
+function OKDB(options) {
+ if (!(this instanceof OKDB)) return new OKDB(options);
+ options = options || {};
+ this._db = options.db || JSONDown('db');
+}
+
+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
+ */
+function JSONDown(name, options) {
+ if (!(this instanceof JSONDown)) return new JSONDown(name, options);
+ options = options || {};
+ var filename = name + '.json';
+ this._db = low(filename);
+}
+
+JSONDown.prototype._resolve = function(data) {
+ return Q.Promise(function resolvePromise(resolve, reject) {
+ resolve(data);
+ });
+};
+
+JSONDown.prototype.get = function(collection, id) {
+ var data = this._db(collection).get(id);
+ return this._resolve(data || {});
+};
+
+JSONDown.prototype.getMeta = function() {
+ var data = this._db('meta').first();
+ return this._resolve(data || {});
+};
+
+JSONDown.prototype.getAll = function(collection) {
+ var data = this._db(collection).toArray();
+ return this._resolve(data || []);
+};
+
+module.exports = OKDB;
+module.exports.JSONDown = JSONDown;
diff --git a/app/node_modules/okdb/package.json b/app/node_modules/okdb/package.json
new file mode 100644
index 0000000..659422e
--- /dev/null
+++ b/app/node_modules/okdb/package.json
@@ -0,0 +1,16 @@
+{
+ "name": "okdb",
+ "version": "1.0.0",
+ "description": "nice",
+ "main": "index.js",
+ "scripts": {
+ "test": "echo \"Error: no test specified\" && exit 1"
+ },
+ "author": "OKFocus",
+ "license": "None",
+ "dependencies": {
+ "lowdb": "^0.7.2",
+ "q": "^1.2.0",
+ "underscore-db": "^0.8.1"
+ }
+}