summaryrefslogtreecommitdiff
path: root/app/node_modules/okquery/index.js
diff options
context:
space:
mode:
authorSean Fridman <fridman@mail.sfsu.edu>2015-04-08 14:06:30 -0400
committerSean Fridman <fridman@mail.sfsu.edu>2015-04-08 14:06:39 -0400
commit0fc380788157779a39fe630b2464280eea9f5088 (patch)
treef4f2f88c3bd098dd8ec083e56ec64f5340e2c445 /app/node_modules/okquery/index.js
parentb91c88be52170a7c9a8b133ef72052bec8caccba (diff)
Add resource instance concept
Can now define resource classes bound to particular data points, in particular they can be static data defined by app config and not even in DB
Diffstat (limited to 'app/node_modules/okquery/index.js')
-rw-r--r--app/node_modules/okquery/index.js26
1 files changed, 19 insertions, 7 deletions
diff --git a/app/node_modules/okquery/index.js b/app/node_modules/okquery/index.js
index a64f0f2..9748067 100644
--- a/app/node_modules/okquery/index.js
+++ b/app/node_modules/okquery/index.js
@@ -14,14 +14,19 @@ function OKQuery(options) {
var resource = options.resource;
var type = resource.type;
var query = options.query || '*';
+
Object.defineProperty(this, 'resource', {
value: resource,
- writable: false
+ writable: false,
+ enumerable: true
});
+
Object.defineProperty(this, 'type', {
value: resource.type,
- writable: false
+ writable: false,
+ enumerable: true
});
+
this.get = createQuery(resource, query, {
default: options.default
});
@@ -29,8 +34,9 @@ function OKQuery(options) {
function createQuery(resource, query, options) {
options = options || {};
- var query;
- if (isDynamic(query)) {
+ if (resource.bound) {
+ query = queryBound(resource);
+ } else if (isDynamic(query)) {
query = queryDynamic(resource);
} else if (isSet(query)) {
query = queryAll(resource);
@@ -46,19 +52,25 @@ function createQuery(resource, query, options) {
function queryDynamic(resource) {
return function(id) {
return resource.get(id);
- }
+ };
}
function queryAll(resource) {
return function() {
return resource.all();
- }
+ };
}
function querySingle(resource, id) {
return function() {
return resource.get(id);
- }
+ };
+}
+
+function queryBound(resource) {
+ return function() {
+ return resource.get();
+ };
}
function withDefault(queryFn, resultDefault) {