summaryrefslogtreecommitdiff
path: root/app/node_modules/okquery
diff options
context:
space:
mode:
Diffstat (limited to 'app/node_modules/okquery')
-rw-r--r--app/node_modules/okquery/index.js54
1 files changed, 27 insertions, 27 deletions
diff --git a/app/node_modules/okquery/index.js b/app/node_modules/okquery/index.js
index f5db3f0..cfc8d0b 100644
--- a/app/node_modules/okquery/index.js
+++ b/app/node_modules/okquery/index.js
@@ -1,59 +1,59 @@
/**
* OKQuery!
- * Takes configuration and gives you something that can run a DB query
- * based on the configurations.
+ * Takes a query spec for a resource and maps it the proper read
+ * methods of that resource. This is simply to separate the notions
+ * of queries and resources.
*/
-function OKQuery(db, options) {
+function OKQuery(options) {
if (!(this instanceof OKQuery)) return new OKQuery(db, options);
options = options || {};
- if (!db)
- throw new Error('No DB provided to query.');
- if (!options.type)
- throw new Error('No resource type provided to query');
- var type = options.type;
- var id = options.id || '*';
+ if (!options.resource)
+ throw new Error('No resource provided to query');
+ var resource = options.resource;
+ var type = resource.type;
+ var query = options.query || '*';
Object.defineProperty(this, 'type', {
- value: type,
+ value: resource.type,
writable: false
});
- this.get = createQuery(db, type, id);
+ this.get = createQuery(resource, query);
}
-function createQuery(db, type, id) {
- if (isDynamic(id)) {
- return queryDynamic(db, type);
- } else if (isSet(id)) {
- return queryAll(db, type);
+function createQuery(resource, query) {
+ if (isDynamic(query)) {
+ return queryDynamic(resource);
+ } else if (isSet(query)) {
+ return queryAll(resource);
} else {
- return querySingle(db, type, id);
+ return querySingle(resource, query);
}
}
-function queryDynamic(db, type) {
+function queryDynamic(resource) {
return function(options) {
options = options || {};
- return db.get(type, options.id);
+ return resource.get(options.id);
}
}
-function queryAll(db, type) {
+function queryAll(resource) {
return function() {
- return db.getAll(type);
+ return resource.all();
}
}
-function querySingle(db, type, id) {
+function querySingle(resource, id) {
return function() {
- return db.get(type, id);
+ return resource.get(id);
}
}
-function isDynamic(id) {
- return id && id.charAt(0) === ':';
+function isDynamic(query) {
+ return query && query.charAt(0) === ':';
}
-function isSet(id) {
- return id && id === '*';
+function isSet(query) {
+ return query && query === '*';
}
module.exports = OKQuery;