js-data-rethinkdb
Advanced tools
Comparing version 0.1.0 to 0.2.0
@@ -0,3 +1,12 @@ | ||
##### 0.2.0 - 03 October 2014 | ||
###### Breaking API changes | ||
- #2 - use something other than resourceConfig.endpoint for determining the table for a resource | ||
##### 0.1.1 - 03 October 2014 | ||
- Now using db correctly | ||
##### 0.1.0 - 03 October 2014 | ||
- Initial Release |
{ | ||
"name": "js-data-rethinkdb", | ||
"description": "RethinkDB adapter for js-data.", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"homepage": "http://www.js-data.io/js-data-rethinkdb", | ||
@@ -31,2 +31,3 @@ "repository": { | ||
"devDependencies": { | ||
"chai": "1.9.2", | ||
"grunt": "0.4.5", | ||
@@ -36,4 +37,5 @@ "grunt-contrib-jshint": "0.10.0", | ||
"grunt-karma-coveralls": "2.5.2", | ||
"grunt-mocha-test": "^0.12.1", | ||
"grunt-mocha-test": "0.12.1", | ||
"jit-grunt": "0.8.0", | ||
"sinon": "1.10.3", | ||
"time-grunt": "1.0.0" | ||
@@ -40,0 +42,0 @@ }, |
@@ -10,5 +10,2 @@ <img src="https://raw.githubusercontent.com/js-data/js-data/master/js-data.png" alt="js-data logo" title="js-data" align="right" width="64" height="64" /> | ||
## Demo | ||
[https://js-data-rethinkdb.firebaseapp.com/](https://js-data-rethinkdb.firebaseapp.com/) | ||
## Project Status | ||
@@ -15,0 +12,0 @@ |
@@ -1,35 +0,12 @@ | ||
var JSData, rethinkdbdash; | ||
var rethinkdbdash = require('rethinkdbdash'); | ||
var forOwn = require('mout/object/forOwn'); | ||
var keys = require('mout/object/keys'); | ||
var deepMixIn = require('mout/object/deepMixIn'); | ||
var forEach = require('mout/array/forEach'); | ||
var contains = require('mout/array/contains'); | ||
var isObject = require('mout/lang/isObject'); | ||
var isString = require('mout/lang/isString'); | ||
var upperCase = require('mout/string/upperCase'); | ||
var underscore = require('mout/string/underscore'); | ||
try { | ||
JSData = require('js-data'); | ||
} catch (e) { | ||
} | ||
try { | ||
rethinkdbdash = require('rethinkdbdash'); | ||
} catch (e) { | ||
} | ||
if (!JSData) { | ||
try { | ||
JSData = window.JSData; | ||
} catch (e) { | ||
} | ||
} | ||
if (!rethinkdbdash) { | ||
try { | ||
rethinkdbdash = window.rethinkdbdash; | ||
} catch (e) { | ||
} | ||
} | ||
if (!JSData) { | ||
throw new Error('js-data must be loaded!'); | ||
} else if (!rethinkdbdash) { | ||
throw new Error('rethinkdbdash must be loaded!'); | ||
} | ||
var DSUtils = JSData.DSUtils; | ||
function Defaults() { | ||
@@ -56,3 +33,4 @@ | ||
function filterQuery(r, resourceConfig, params) { | ||
function filterQuery(resourceConfig, params) { | ||
var r = this.r; | ||
params = params || {}; | ||
@@ -63,7 +41,6 @@ params.where = params.where || {}; | ||
var keys = Object.keys(params); | ||
keys.forEach(function (k) { | ||
forEach(keys(params), function (k) { | ||
var v = params[k]; | ||
if (!DSUtils.contains(reserved, k)) { | ||
if (DSUtils.isObject(v)) { | ||
if (!contains(reserved, k)) { | ||
if (isObject(v)) { | ||
params.where[k] = v; | ||
@@ -79,7 +56,7 @@ } else { | ||
var query = r.table(resourceConfig.endpoint); | ||
var query = r.db(this.defaults.db).table(resourceConfig.table || underscore(resourceConfig.name)); | ||
var subQuery; | ||
DSUtils.forOwn(params.where, function (criteria, field) { | ||
if (!DSUtils.isObject(criteria)) { | ||
forOwn(params.where, function (criteria, field) { | ||
if (!isObject(criteria)) { | ||
params.where[field] = { | ||
@@ -89,3 +66,3 @@ '==': criteria | ||
} | ||
DSUtils.forOwn(criteria, function (v, op) { | ||
forOwn(criteria, function (v, op) { | ||
if (op === '==' || op === '===') { | ||
@@ -132,3 +109,3 @@ subQuery = subQuery ? subQuery.and(r.row(field).eq(v)) : r.row(field).eq(v); | ||
if (params.orderBy) { | ||
if (utils.isString(params.orderBy)) { | ||
if (isString(params.orderBy)) { | ||
params.orderBy = [ | ||
@@ -139,6 +116,6 @@ [params.orderBy, 'asc'] | ||
for (var i = 0; i < params.orderBy.length; i++) { | ||
if (utils.isString(params.orderBy[i])) { | ||
if (isString(params.orderBy[i])) { | ||
params.orderBy[i] = [params.orderBy[i], 'asc']; | ||
} | ||
query = utils.upperCase(params.orderBy[i][1]) === 'DESC' ? query.orderBy(r.desc(params.orderBy[i][0])) : query.orderBy(params.orderBy[i][0]); | ||
query = upperCase(params.orderBy[i][1]) === 'DESC' ? query.orderBy(r.desc(params.orderBy[i][0])) : query.orderBy(params.orderBy[i][0]); | ||
} | ||
@@ -161,3 +138,3 @@ } | ||
this.defaults = new Defaults(); | ||
DSUtils.deepMixIn(this.defaults, options); | ||
deepMixIn(this.defaults, options); | ||
this.r = rethinkdbdash(this.defaults); | ||
@@ -169,3 +146,3 @@ } | ||
dsRethinkDBAdapterPrototype.find = function find(resourceConfig, id) { | ||
return this.r.table(resourceConfig.endpoint).get(id).run().then(function (item) { | ||
return this.r.db(this.defaults.db).table(resourceConfig.table || underscore(resourceConfig.name)).get(id).run().then(function (item) { | ||
if (!item) { | ||
@@ -180,7 +157,7 @@ throw new Error('Not Found!'); | ||
dsRethinkDBAdapterPrototype.findAll = function (resourceConfig, params) { | ||
return filterQuery(this.r, resourceConfig, params).run(); | ||
return filterQuery.call(this, resourceConfig, params).run(); | ||
}; | ||
dsRethinkDBAdapterPrototype.create = function (resourceConfig, attrs) { | ||
return this.r.table(resourceConfig.endpoint).insert(attrs, { returnChanges: true }).run().then(function (cursor) { | ||
return this.r.db(this.defaults.db).table(resourceConfig.table || underscore(resourceConfig.name)).insert(attrs, { returnChanges: true }).run().then(function (cursor) { | ||
return cursor.changes[0].new_val; | ||
@@ -191,3 +168,3 @@ }); | ||
dsRethinkDBAdapterPrototype.update = function (resourceConfig, id, attrs) { | ||
return this.r.table(resourceConfig.endpoint).get(id).update(attrs, { returnChanges: true }).run().then(function (cursor) { | ||
return this.r.db(this.defaults.db).table(resourceConfig.table || underscore(resourceConfig.name)).get(id).update(attrs, { returnChanges: true }).run().then(function (cursor) { | ||
return cursor.changes[0].new_val; | ||
@@ -199,3 +176,3 @@ }); | ||
params = params || {}; | ||
return filterQuery(this.r, resourceConfig, params).update(attrs, { returnChanges: true }).run().then(function (cursor) { | ||
return filterQuery.call(this, resourceConfig, params).update(attrs, { returnChanges: true }).run().then(function (cursor) { | ||
var items = []; | ||
@@ -210,3 +187,3 @@ cursor.changes.forEach(function (change) { | ||
dsRethinkDBAdapterPrototype.destroy = function (resourceConfig, id) { | ||
return this.r.table(resourceConfig.endpoint).get(id).delete().run().then(function () { | ||
return this.r.db(this.defaults.db).table(resourceConfig.table || underscore(resourceConfig.name)).get(id).delete().run().then(function () { | ||
return undefined; | ||
@@ -218,3 +195,3 @@ }); | ||
params = params || {}; | ||
return filterQuery(this.r, resourceConfig, params).delete().run().then(function () { | ||
return filterQuery.call(this, resourceConfig, params).delete().run().then(function () { | ||
return undefined; | ||
@@ -221,0 +198,0 @@ }); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
25178
9
18
491
82