@@ -67,9 +67,10 @@ module.exports =
6767 return resourceConfig . table || underscore ( resourceConfig . name ) ;
6868 }
6969
70- function filterQuery ( resourceConfig , params ) {
70+ function filterQuery ( resourceConfig , params , options ) {
7171 var table = getTable ( resourceConfig ) ;
72- var query = this . query . select ( table + '.*' ) . from ( table ) ;
72+ var query = options && options . transaction || this . query ;
73+ query = query . select ( table + '.*' ) . from ( table ) ;
7374 params = params || { } ;
7475 params . where = params . where || { } ;
7576 params . orderBy = params . orderBy || params . sort ;
@@ -378,7 +379,8 @@ module.exports =
378379 var instance = undefined ;
379380 options = options || { } ;
380381 options [ 'with' ] = options [ 'with' ] || [ ] ;
381- return this . query . select ( '*' ) . from ( getTable ( resourceConfig ) ) . where ( resourceConfig . idAttribute , toString ( id ) ) . then ( function ( rows ) {
382+ var query = options && options . transaction || this . query ;
383+ return query . select ( '*' ) . from ( getTable ( resourceConfig ) ) . where ( resourceConfig . idAttribute , toString ( id ) ) . then ( function ( rows ) {
382384 if ( ! rows . length ) {
383385 return DSUtils . Promise . reject ( new Error ( 'Not Found!' ) ) ;
384386 } else {
@@ -410,7 +412,8 @@ module.exports =
410412 var _this4 = this ;
411413
412414 attrs = DSUtils . removeCircular ( DSUtils . omit ( attrs , resourceConfig . relationFields || [ ] ) ) ;
413- return this . query ( getTable ( resourceConfig ) ) . insert ( attrs , resourceConfig . idAttribute ) . then ( function ( ids ) {
415+ var query = options && options . transaction || this . query ;
416+ return query ( getTable ( resourceConfig ) ) . insert ( attrs , resourceConfig . idAttribute ) . then ( function ( ids ) {
414417 if ( attrs [ resourceConfig . idAttribute ] ) {
415418 return _this4 . find ( resourceConfig , attrs [ resourceConfig . idAttribute ] , options ) ;
416419 } else if ( ids . length ) {
@@ -426,7 +429,8 @@ module.exports =
426429 var _this5 = this ;
427430
428431 attrs = DSUtils . removeCircular ( DSUtils . omit ( attrs , resourceConfig . relationFields || [ ] ) ) ;
429- return this . query ( getTable ( resourceConfig ) ) . where ( resourceConfig . idAttribute , toString ( id ) ) . update ( attrs ) . then ( function ( ) {
432+ var query = options && options . transaction || this . query ;
433+ return query ( getTable ( resourceConfig ) ) . where ( resourceConfig . idAttribute , toString ( id ) ) . update ( attrs ) . then ( function ( ) {
430434 return _this5 . find ( resourceConfig , id , options ) ;
431435 } ) ;
432436 }
@@ -452,8 +456,9 @@ module.exports =
452456 }
453457 } , {
454458 key : 'destroy' ,
455- value : function destroy ( resourceConfig , id ) {
456- return this . query ( getTable ( resourceConfig ) ) . where ( resourceConfig . idAttribute , toString ( id ) ) . del ( ) . then ( function ( ) {
459+ value : function destroy ( resourceConfig , id , options ) {
460+ var query = options && options . transaction || this . query ;
461+ return query ( getTable ( resourceConfig ) ) . where ( resourceConfig . idAttribute , toString ( id ) ) . del ( ) . then ( function ( ) {
457462 return undefined ;
458463 } ) ;
459464 }
0 commit comments