@@ -7,11 +7,7 @@ var contains = require('mout/array/contains');
77var isObject = require ( 'mout/lang/isObject' ) ;
88var isString = require ( 'mout/lang/isString' ) ;
99var upperCase = require ( 'mout/string/upperCase' ) ;
10-
11- try {
12- rethinkdbdash = require ( 'rethinkdbdash' ) ;
13- } catch ( e ) {
14- }
10+ var underscore = require ( 'mout/string/underscore' ) ;
1511
1612function 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) {
140136var dsRethinkDBAdapterPrototype = DSRethinkDBAdapter . prototype ;
141137
142138dsRethinkDBAdapterPrototype . 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
156152dsRethinkDBAdapterPrototype . 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
162158dsRethinkDBAdapterPrototype . 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
179175dsRethinkDBAdapterPrototype . 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