Skip to content

Commit 33078a5

Browse files
committed
Now db is used correctly.
1 parent de2a410 commit 33078a5

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

src/index.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ var reserved = [
5353
'where'
5454
];
5555

56-
function filterQuery(r, resourceConfig, params) {
56+
function filterQuery(resourceConfig, params) {
57+
var r = this.r;
5758
params = params || {};
5859
params.where = params.where || {};
5960
params.orderBy = params.orderBy || params.sort;
@@ -74,7 +75,7 @@ function filterQuery(r, resourceConfig, params) {
7475
}
7576
});
7677

77-
var query = r.table(resourceConfig.endpoint);
78+
var query = r.db(this.defaults.db).table(resourceConfig.endpoint);
7879
var subQuery;
7980

8081
DSUtils.forOwn(params.where, function (criteria, field) {
@@ -159,7 +160,7 @@ function DSRethinkDBAdapter(options) {
159160
var dsRethinkDBAdapterPrototype = DSRethinkDBAdapter.prototype;
160161

161162
dsRethinkDBAdapterPrototype.find = function find(resourceConfig, id) {
162-
return this.r.table(resourceConfig.endpoint).get(id).run().then(function (item) {
163+
return this.r.db(this.defaults.db).table(resourceConfig.endpoint).get(id).run().then(function (item) {
163164
if (!item) {
164165
throw new Error('Not Found!');
165166
} else {
@@ -169,24 +170,24 @@ dsRethinkDBAdapterPrototype.find = function find(resourceConfig, id) {
169170
};
170171

171172
dsRethinkDBAdapterPrototype.findAll = function (resourceConfig, params) {
172-
return filterQuery(this.r, resourceConfig, params).run();
173+
return filterQuery.call(this, resourceConfig, params).run();
173174
};
174175

175176
dsRethinkDBAdapterPrototype.create = function (resourceConfig, attrs) {
176-
return this.r.table(resourceConfig.endpoint).insert(attrs, { returnChanges: true }).run().then(function (cursor) {
177+
return this.r.db(this.defaults.db).table(resourceConfig.endpoint).insert(attrs, { returnChanges: true }).run().then(function (cursor) {
177178
return cursor.changes[0].new_val;
178179
});
179180
};
180181

181182
dsRethinkDBAdapterPrototype.update = function (resourceConfig, id, attrs) {
182-
return this.r.table(resourceConfig.endpoint).get(id).update(attrs, { returnChanges: true }).run().then(function (cursor) {
183+
return this.r.db(this.defaults.db).table(resourceConfig.endpoint).get(id).update(attrs, { returnChanges: true }).run().then(function (cursor) {
183184
return cursor.changes[0].new_val;
184185
});
185186
};
186187

187188
dsRethinkDBAdapterPrototype.updateAll = function (resourceConfig, attrs, params) {
188189
params = params || {};
189-
return filterQuery(this.r, resourceConfig, params).update(attrs, { returnChanges: true }).run().then(function (cursor) {
190+
return filterQuery.call(this, resourceConfig, params).update(attrs, { returnChanges: true }).run().then(function (cursor) {
190191
var items = [];
191192
cursor.changes.forEach(function (change) {
192193
items.push(change.new_val);
@@ -196,14 +197,14 @@ dsRethinkDBAdapterPrototype.updateAll = function (resourceConfig, attrs, params)
196197
};
197198

198199
dsRethinkDBAdapterPrototype.destroy = function (resourceConfig, id) {
199-
return this.r.table(resourceConfig.endpoint).get(id).delete().run().then(function () {
200+
return this.r.db(this.defaults.db).table(resourceConfig.endpoint).get(id).delete().run().then(function () {
200201
return undefined;
201202
});
202203
};
203204

204205
dsRethinkDBAdapterPrototype.destroyAll = function (resourceConfig, params) {
205206
params = params || {};
206-
return filterQuery(this.r, resourceConfig, params).delete().run().then(function () {
207+
return filterQuery.call(this, resourceConfig, params).delete().run().then(function () {
207208
return undefined;
208209
});
209210
};

0 commit comments

Comments
 (0)