@@ -19,9 +19,10 @@ function getTable (resourceConfig) {
1919 return resourceConfig . table || underscore ( resourceConfig . name )
2020}
2121
22- function filterQuery ( resourceConfig , params ) {
22+ function filterQuery ( resourceConfig , params , options ) {
2323 let table = getTable ( resourceConfig )
24- let query = this . query . select ( `${ table } .*` ) . from ( table )
24+ let query = options && options . transaction || this . query
25+ query = query . select ( `${ table } .*` ) . from ( table )
2526 params = params || { }
2627 params . where = params . where || { }
2728 params . orderBy = params . orderBy || params . sort
@@ -301,7 +302,8 @@ class DSSqlAdapter {
301302 let instance
302303 options = options || { }
303304 options . with = options . with || [ ]
304- return this . query
305+ let query = options && options . transaction || this . query
306+ return query
305307 . select ( '*' )
306308 . from ( getTable ( resourceConfig ) )
307309 . where ( resourceConfig . idAttribute , toString ( id ) )
@@ -328,7 +330,8 @@ class DSSqlAdapter {
328330
329331 create ( resourceConfig , attrs , options ) {
330332 attrs = DSUtils . removeCircular ( DSUtils . omit ( attrs , resourceConfig . relationFields || [ ] ) )
331- return this . query ( getTable ( resourceConfig ) )
333+ let query = options && options . transaction || this . query
334+ return query ( getTable ( resourceConfig ) )
332335 . insert ( attrs , resourceConfig . idAttribute )
333336 . then ( ids => {
334337 if ( attrs [ resourceConfig . idAttribute ] ) {
@@ -343,7 +346,8 @@ class DSSqlAdapter {
343346
344347 update ( resourceConfig , id , attrs , options ) {
345348 attrs = DSUtils . removeCircular ( DSUtils . omit ( attrs , resourceConfig . relationFields || [ ] ) )
346- return this . query ( getTable ( resourceConfig ) )
349+ let query = options && options . transaction || this . query
350+ return query ( getTable ( resourceConfig ) )
347351 . where ( resourceConfig . idAttribute , toString ( id ) )
348352 . update ( attrs )
349353 . then ( ( ) => this . find ( resourceConfig , id , options ) )
@@ -364,8 +368,9 @@ class DSSqlAdapter {
364368 } )
365369 }
366370
367- destroy ( resourceConfig , id ) {
368- return this . query ( getTable ( resourceConfig ) )
371+ destroy ( resourceConfig , id , options ) {
372+ let query = options && options . transaction || this . query
373+ return query ( getTable ( resourceConfig ) )
369374 . where ( resourceConfig . idAttribute , toString ( id ) )
370375 . del ( ) . then ( ( ) => undefined )
371376 }
0 commit comments