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" ;
2
2
import { IDBUtil } from "@/worker/idbutil" ;
3
- import { DbMeta } from "@worker/model" ;
4
3
import { QueryHelper } from "../query_helper" ;
5
4
import { promiseReject , isArray , getDataType , variableFromPath , LogHelper } from "@worker/utils" ;
6
5
import { BaseFetch } from "@executors/base_fetch" ;
@@ -15,6 +14,7 @@ export class Update extends BaseFetch {
15
14
16
15
constructor ( query : IUpdateQuery , util : IDBUtil ) {
17
16
super ( ) ;
17
+ query . returnImmediate = query . returnImmediate == null ? false : query . returnImmediate ;
18
18
this . query = query as any ;
19
19
this . util = util ;
20
20
this . tableName = query . in ;
@@ -37,7 +37,7 @@ export class Update extends BaseFetch {
37
37
const err = queryHelper . validate ( API . Update , query ) ;
38
38
if ( err ) return promiseReject ( err ) ;
39
39
return beforeExecute ( ) . then ( _ => {
40
- this . initTransaction ( ) ;
40
+ const txPromise = this . initTransaction ( ) ;
41
41
let pResult : Promise < void > ;
42
42
if ( query . where != null ) {
43
43
if ( ( query . where as IWhereQuery ) . or || isArray ( query . where ) ) {
@@ -50,7 +50,11 @@ export class Update extends BaseFetch {
50
50
else {
51
51
pResult = this . executeWhereUndefinedLogic ( ) ;
52
52
}
53
- return pResult . then ( ( ) => {
53
+ const promiseToUse = [ pResult ] ;
54
+ if ( query . returnImmediate === false && txPromise ) {
55
+ promiseToUse . push ( txPromise ) ;
56
+ }
57
+ return promiseAll ( promiseToUse ) . then ( ( ) => {
54
58
return this . rowAffected ;
55
59
} )
56
60
} )
@@ -84,10 +88,12 @@ export class Update extends BaseFetch {
84
88
85
89
private initTransaction ( ) {
86
90
const tableName = ( this . query as any ) . in ;
91
+ let promise : Promise < void > ;
87
92
if ( ! this . isTxQuery ) {
88
- this . util . createTransaction ( [ tableName ] ) ;
93
+ promise = this . util . createTransaction ( [ tableName ] ) ;
89
94
}
90
95
this . objectStore = this . util . objectStore ( tableName ) ;
96
+ return promise ;
91
97
}
92
98
}
93
99
0 commit comments