@@ -7,11 +7,7 @@ var contains = require('mout/array/contains');
7
7
var isObject = require ( 'mout/lang/isObject' ) ;
8
8
var isString = require ( 'mout/lang/isString' ) ;
9
9
var upperCase = require ( 'mout/string/upperCase' ) ;
10
-
11
- try {
12
- rethinkdbdash = require ( 'rethinkdbdash' ) ;
13
- } catch ( e ) {
14
- }
10
+ var underscore = require ( 'mout/string/underscore' ) ;
15
11
16
12
function Defaults ( ) {
17
13
@@ -55,7 +51,7 @@ function filterQuery(resourceConfig, params) {
55
51
}
56
52
} ) ;
57
53
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 ) ) ;
59
55
var subQuery ;
60
56
61
57
forOwn ( params . where , function ( criteria , field ) {
@@ -140,7 +136,7 @@ function DSRethinkDBAdapter(options) {
140
136
var dsRethinkDBAdapterPrototype = DSRethinkDBAdapter . prototype ;
141
137
142
138
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 ) {
144
140
if ( ! item ) {
145
141
throw new Error ( 'Not Found!' ) ;
146
142
} else {
@@ -154,13 +150,13 @@ dsRethinkDBAdapterPrototype.findAll = function (resourceConfig, params) {
154
150
} ;
155
151
156
152
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 ) {
158
154
return cursor . changes [ 0 ] . new_val ;
159
155
} ) ;
160
156
} ;
161
157
162
158
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 ) {
164
160
return cursor . changes [ 0 ] . new_val ;
165
161
} ) ;
166
162
} ;
@@ -177,7 +173,7 @@ dsRethinkDBAdapterPrototype.updateAll = function (resourceConfig, attrs, params)
177
173
} ;
178
174
179
175
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 ( ) {
181
177
return undefined ;
182
178
} ) ;
183
179
} ;
0 commit comments