@@ -53,7 +53,8 @@ var reserved = [
53
53
'where'
54
54
] ;
55
55
56
- function filterQuery ( r , resourceConfig , params ) {
56
+ function filterQuery ( resourceConfig , params ) {
57
+ var r = this . r ;
57
58
params = params || { } ;
58
59
params . where = params . where || { } ;
59
60
params . orderBy = params . orderBy || params . sort ;
@@ -74,7 +75,7 @@ function filterQuery(r, resourceConfig, params) {
74
75
}
75
76
} ) ;
76
77
77
- var query = r . table ( resourceConfig . endpoint ) ;
78
+ var query = r . db ( this . defaults . db ) . table ( resourceConfig . endpoint ) ;
78
79
var subQuery ;
79
80
80
81
DSUtils . forOwn ( params . where , function ( criteria , field ) {
@@ -159,7 +160,7 @@ function DSRethinkDBAdapter(options) {
159
160
var dsRethinkDBAdapterPrototype = DSRethinkDBAdapter . prototype ;
160
161
161
162
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 ) {
163
164
if ( ! item ) {
164
165
throw new Error ( 'Not Found!' ) ;
165
166
} else {
@@ -169,24 +170,24 @@ dsRethinkDBAdapterPrototype.find = function find(resourceConfig, id) {
169
170
} ;
170
171
171
172
dsRethinkDBAdapterPrototype . findAll = function ( resourceConfig , params ) {
172
- return filterQuery ( this . r , resourceConfig , params ) . run ( ) ;
173
+ return filterQuery . call ( this , resourceConfig , params ) . run ( ) ;
173
174
} ;
174
175
175
176
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 ) {
177
178
return cursor . changes [ 0 ] . new_val ;
178
179
} ) ;
179
180
} ;
180
181
181
182
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 ) {
183
184
return cursor . changes [ 0 ] . new_val ;
184
185
} ) ;
185
186
} ;
186
187
187
188
dsRethinkDBAdapterPrototype . updateAll = function ( resourceConfig , attrs , params ) {
188
189
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 ) {
190
191
var items = [ ] ;
191
192
cursor . changes . forEach ( function ( change ) {
192
193
items . push ( change . new_val ) ;
@@ -196,14 +197,14 @@ dsRethinkDBAdapterPrototype.updateAll = function (resourceConfig, attrs, params)
196
197
} ;
197
198
198
199
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 ( ) {
200
201
return undefined ;
201
202
} ) ;
202
203
} ;
203
204
204
205
dsRethinkDBAdapterPrototype . destroyAll = function ( resourceConfig , params ) {
205
206
params = params || { } ;
206
- return filterQuery ( this . r , resourceConfig , params ) . delete ( ) . run ( ) . then ( function ( ) {
207
+ return filterQuery . call ( this , resourceConfig , params ) . delete ( ) . run ( ) . then ( function ( ) {
207
208
return undefined ;
208
209
} ) ;
209
210
} ;
0 commit comments