Skip to content

Commit 7309561

Browse files
committed
Closes #2.
Stable Version 0.2.0.
1 parent 17effd1 commit 7309561

File tree

3 files changed

+12
-11
lines changed

3 files changed

+12
-11
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
##### 0.2.0 - 03 October 2014
2+
3+
###### Breaking API changes
4+
- #2 - use something other than resourceConfig.endpoint for determining the table for a resource
5+
16
##### 0.1.1 - 03 October 2014
27

38
- Now using db correctly

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "js-data-rethinkdb",
33
"description": "RethinkDB adapter for js-data.",
4-
"version": "0.1.1",
4+
"version": "0.2.0",
55
"homepage": "http://www.js-data.io/js-data-rethinkdb",
66
"repository": {
77
"type": "git",

src/index.js

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,7 @@ var contains = require('mout/array/contains');
77
var isObject = require('mout/lang/isObject');
88
var isString = require('mout/lang/isString');
99
var upperCase = require('mout/string/upperCase');
10-
11-
try {
12-
rethinkdbdash = require('rethinkdbdash');
13-
} catch (e) {
14-
}
10+
var underscore = require('mout/string/underscore');
1511

1612
function Defaults() {
1713

@@ -55,7 +51,7 @@ function filterQuery(resourceConfig, params) {
5551
}
5652
});
5753

58-
var query = r.db(this.defaults.db).table(resourceConfig.endpoint);
54+
var query = r.db(this.defaults.db).table(resourceConfig.table || underscore(resourceConfig.name));
5955
var subQuery;
6056

6157
forOwn(params.where, function (criteria, field) {
@@ -140,7 +136,7 @@ function DSRethinkDBAdapter(options) {
140136
var dsRethinkDBAdapterPrototype = DSRethinkDBAdapter.prototype;
141137

142138
dsRethinkDBAdapterPrototype.find = function find(resourceConfig, id) {
143-
return this.r.db(this.defaults.db).table(resourceConfig.endpoint).get(id).run().then(function (item) {
139+
return this.r.db(this.defaults.db).table(resourceConfig.table || underscore(resourceConfig.name)).get(id).run().then(function (item) {
144140
if (!item) {
145141
throw new Error('Not Found!');
146142
} else {
@@ -154,13 +150,13 @@ dsRethinkDBAdapterPrototype.findAll = function (resourceConfig, params) {
154150
};
155151

156152
dsRethinkDBAdapterPrototype.create = function (resourceConfig, attrs) {
157-
return this.r.db(this.defaults.db).table(resourceConfig.endpoint).insert(attrs, { returnChanges: true }).run().then(function (cursor) {
153+
return this.r.db(this.defaults.db).table(resourceConfig.table || underscore(resourceConfig.name)).insert(attrs, { returnChanges: true }).run().then(function (cursor) {
158154
return cursor.changes[0].new_val;
159155
});
160156
};
161157

162158
dsRethinkDBAdapterPrototype.update = function (resourceConfig, id, attrs) {
163-
return this.r.db(this.defaults.db).table(resourceConfig.endpoint).get(id).update(attrs, { returnChanges: true }).run().then(function (cursor) {
159+
return this.r.db(this.defaults.db).table(resourceConfig.table || underscore(resourceConfig.name)).get(id).update(attrs, { returnChanges: true }).run().then(function (cursor) {
164160
return cursor.changes[0].new_val;
165161
});
166162
};
@@ -177,7 +173,7 @@ dsRethinkDBAdapterPrototype.updateAll = function (resourceConfig, attrs, params)
177173
};
178174

179175
dsRethinkDBAdapterPrototype.destroy = function (resourceConfig, id) {
180-
return this.r.db(this.defaults.db).table(resourceConfig.endpoint).get(id).delete().run().then(function () {
176+
return this.r.db(this.defaults.db).table(resourceConfig.table || underscore(resourceConfig.name)).get(id).delete().run().then(function () {
181177
return undefined;
182178
});
183179
};

0 commit comments

Comments
 (0)