1- import { IUpdateQuery , ISelectQuery , QUERY_OPTION , API , IWhereQuery , DATA_TYPE , ERROR_TYPE } from "@/common" ;
1+ import { IUpdateQuery , ISelectQuery , QUERY_OPTION , API , IWhereQuery , DATA_TYPE , ERROR_TYPE , promiseAll } from "@/common" ;
22import { IDBUtil } from "@/worker/idbutil" ;
3- import { DbMeta } from "@worker/model" ;
43import { QueryHelper } from "../query_helper" ;
54import { promiseReject , isArray , getDataType , variableFromPath , LogHelper } from "@worker/utils" ;
65import { BaseFetch } from "@executors/base_fetch" ;
@@ -15,6 +14,7 @@ export class Update extends BaseFetch {
1514
1615 constructor ( query : IUpdateQuery , util : IDBUtil ) {
1716 super ( ) ;
17+ query . returnImmediate = query . returnImmediate == null ? false : query . returnImmediate ;
1818 this . query = query as any ;
1919 this . util = util ;
2020 this . tableName = query . in ;
@@ -37,7 +37,7 @@ export class Update extends BaseFetch {
3737 const err = queryHelper . validate ( API . Update , query ) ;
3838 if ( err ) return promiseReject ( err ) ;
3939 return beforeExecute ( ) . then ( _ => {
40- this . initTransaction ( ) ;
40+ const txPromise = this . initTransaction ( ) ;
4141 let pResult : Promise < void > ;
4242 if ( query . where != null ) {
4343 if ( ( query . where as IWhereQuery ) . or || isArray ( query . where ) ) {
@@ -50,7 +50,11 @@ export class Update extends BaseFetch {
5050 else {
5151 pResult = this . executeWhereUndefinedLogic ( ) ;
5252 }
53- return pResult . then ( ( ) => {
53+ const promiseToUse = [ pResult ] ;
54+ if ( query . returnImmediate === false && txPromise ) {
55+ promiseToUse . push ( txPromise ) ;
56+ }
57+ return promiseAll ( promiseToUse ) . then ( ( ) => {
5458 return this . rowAffected ;
5559 } )
5660 } )
@@ -84,10 +88,12 @@ export class Update extends BaseFetch {
8488
8589 private initTransaction ( ) {
8690 const tableName = ( this . query as any ) . in ;
91+ let promise : Promise < void > ;
8792 if ( ! this . isTxQuery ) {
88- this . util . createTransaction ( [ tableName ] ) ;
93+ promise = this . util . createTransaction ( [ tableName ] ) ;
8994 }
9095 this . objectStore = this . util . objectStore ( tableName ) ;
96+ return promise ;
9197 }
9298}
9399
0 commit comments