@@ -21,7 +21,8 @@ export class SQLitePluginTurboModule extends TurboModule implements TM.SQLitePlu
21
21
this . context = ctx ;
22
22
}
23
23
24
- echoStringValue ( openargs : Object , mysuccess : ( testValue : Object ) => void , myerror : ( e : Object ) => void ) : void {
24
+ echoStringValue ( openargs : Object , mysuccess : ( testValue : Object ) => void ,
25
+ myerror : ( e : Object ) => void ) : Promise < void > {
25
26
26
27
try {
27
28
this . execute ( Action . echoStringValue , openargs , mysuccess , myerror ) ;
@@ -30,9 +31,10 @@ export class SQLitePluginTurboModule extends TurboModule implements TM.SQLitePlu
30
31
31
32
myerror ( err ) ;
32
33
}
34
+ return Promise . resolve ( )
33
35
}
34
36
35
- open ( openargs : Object , opensuccesscb : ( ) => void , openerrorcb : ( e : Object ) => void ) : void {
37
+ open ( openargs : Object , opensuccesscb : ( ) => void , openerrorcb : ( e : Object ) => void ) : Promise < void > {
36
38
37
39
try {
38
40
this . execute ( Action . open , openargs , opensuccesscb , openerrorcb ) ;
@@ -41,9 +43,10 @@ export class SQLitePluginTurboModule extends TurboModule implements TM.SQLitePlu
41
43
42
44
openerrorcb ( err ) ;
43
45
}
46
+ return Promise . resolve ( )
44
47
}
45
48
46
- close ( closeargs : Object , mysuccess : ( t : Object , r : Object ) => void , myerror : ( e : Object ) => void ) : void {
49
+ close ( closeargs : Object , mysuccess : ( t : Object , r : Object ) => void , myerror : ( e : Object ) => void ) : Promise < void > {
47
50
48
51
try {
49
52
this . execute ( Action . close , closeargs , mysuccess , myerror ) ;
@@ -52,9 +55,10 @@ export class SQLitePluginTurboModule extends TurboModule implements TM.SQLitePlu
52
55
53
56
myerror ( err ) ;
54
57
}
58
+ return Promise . resolve ( )
55
59
}
56
60
57
- delete ( args : Object , mysuccess : ( r : Object ) => void , myerror : ( e : Object ) => void ) : void {
61
+ delete ( args : Object , mysuccess : ( r : Object ) => void , myerror : ( e : Object ) => void ) : Promise < void > {
58
62
59
63
try {
60
64
this . execute ( Action . delete , args , mysuccess , myerror ) ;
@@ -63,9 +67,10 @@ export class SQLitePluginTurboModule extends TurboModule implements TM.SQLitePlu
63
67
64
68
myerror ( err ) ;
65
69
}
70
+ return Promise . resolve ( )
66
71
}
67
72
68
- attach ( attachargs : Object , mysuccess : ( t : Object , r : Object ) => void , myerror : ( e : Object ) => void ) : void {
73
+ attach ( attachargs : Object , mysuccess : ( t : Object , r : Object ) => void , myerror : ( e : Object ) => void ) : Promise < void > {
69
74
70
75
try {
71
76
this . execute ( Action . attach , attachargs , mysuccess , myerror ) ;
@@ -74,10 +79,11 @@ export class SQLitePluginTurboModule extends TurboModule implements TM.SQLitePlu
74
79
75
80
myerror ( err ) ;
76
81
}
77
-
82
+ return Promise . resolve ( )
78
83
}
79
84
80
- backgroundExecuteSqlBatch ( args : Object , mysuccess : ( result : Object ) => void , myerror : ( e : Object ) => void ) : void {
85
+ backgroundExecuteSqlBatch ( args : Object , mysuccess : ( result : Object ) => void ,
86
+ myerror : ( e : Object ) => void ) : Promise < void > {
81
87
82
88
try {
83
89
this . execute ( Action . backgroundExecuteSqlBatch , args , mysuccess , myerror ) ;
@@ -86,10 +92,12 @@ export class SQLitePluginTurboModule extends TurboModule implements TM.SQLitePlu
86
92
87
93
myerror ( err ) ;
88
94
}
95
+ return Promise . resolve ( )
89
96
}
90
97
91
98
//桥接执行方法
92
- execute ( actionAsString : string , args : Object , success : ( result ?: Object , tx ?: Object ) => void , error : ( e : Object ) => void ) : boolean {
99
+ execute ( actionAsString : string , args : Object , success : ( result ?: Object , tx ?: Object ) => void ,
100
+ error : ( e : Object ) => void ) : boolean {
93
101
let dbname : string = '' ;
94
102
const argsmap = args as Map < string , Object > ;
95
103
const map = new Map ( Object . entries ( JSON . parse ( json . stringify ( argsmap ) ) ) ) ;
@@ -155,7 +163,8 @@ export class SQLitePluginTurboModule extends TurboModule implements TM.SQLitePlu
155
163
156
164
relationalStore . getRdbStore ( this . context . uiAbilityContext , STORE_CONFIG , ( err , store ) => {
157
165
if ( err ) {
158
- Logger . debug ( CommonConstants . TAG , 'test--SQLitePlugin=Failed to getRdbStore code:' + err . code + ", message:" + err . message ) ;
166
+ Logger . debug ( CommonConstants . TAG ,
167
+ 'test--SQLitePlugin=Failed to getRdbStore code:' + err . code + ", message:" + err . message ) ;
159
168
const e = { "code" : err . code , "message" : err . message }
160
169
161
170
error ( e ) ;
@@ -206,7 +215,8 @@ export class SQLitePluginTurboModule extends TurboModule implements TM.SQLitePlu
206
215
}
207
216
208
217
//SQL执行数据库方法
209
- async executeSqlBatchDatabase ( args : Object , success : ( result ?: Object ) => void , error : ( e : Object ) => void ) : Promise < void > {
218
+ async executeSqlBatchDatabase ( args : Object , success : ( result ?: Object ) => void ,
219
+ error : ( e : Object ) => void ) : Promise < void > {
210
220
const argsmap = args as Map < string , Object > ;
211
221
const map = new Map ( Object . entries ( JSON . parse ( json . stringify ( argsmap ) ) ) ) ;
212
222
const dbArgs = map . get ( 'dbargs' ) ;
@@ -245,7 +255,8 @@ export class SQLitePluginTurboModule extends TurboModule implements TM.SQLitePlu
245
255
queryResultcall = { 'rowsAffected' : 1 }
246
256
} catch ( e ) {
247
257
errorMessage = e . message ;
248
- Logger . debug ( CommonConstants . TAG , 'test--SQLitePlugin=backgroundExecuteSqlBatch>>>>>>创建表失败=' + errorMessage ) ;
258
+ Logger . debug ( CommonConstants . TAG ,
259
+ 'test--SQLitePlugin=backgroundExecuteSqlBatch>>>>>>创建表失败=' + errorMessage ) ;
249
260
}
250
261
251
262
} else if ( queryType == 'INSERT' ) {
@@ -257,7 +268,8 @@ export class SQLitePluginTurboModule extends TurboModule implements TM.SQLitePlu
257
268
queryResultcall = { 'insertId' : rowId , 'rowsAffected' : 1 }
258
269
} catch ( e ) {
259
270
errorMessage = e . message ;
260
- Logger . debug ( CommonConstants . TAG , 'test--SQLitePlugin=backgroundExecuteSqlBatch>>>>>>插入数据失败=' + errorMessage ) ;
271
+ Logger . debug ( CommonConstants . TAG ,
272
+ 'test--SQLitePlugin=backgroundExecuteSqlBatch>>>>>>插入数据失败=' + errorMessage ) ;
261
273
}
262
274
263
275
} else if ( queryType == 'UPDATE' || queryType == 'DELETE' || queryType == 'ALTER' ) {
@@ -270,7 +282,8 @@ export class SQLitePluginTurboModule extends TurboModule implements TM.SQLitePlu
270
282
queryResultcall = { 'rowsAffected' : rowsAffected }
271
283
} catch ( e ) {
272
284
errorMessage = e . message ;
273
- Logger . debug ( CommonConstants . TAG , 'test--SQLitePlugin=backgroundExecuteSqlBatch>>>>>>插入数据失败=' + errorMessage ) ;
285
+ Logger . debug ( CommonConstants . TAG ,
286
+ 'test--SQLitePlugin=backgroundExecuteSqlBatch>>>>>>插入数据失败=' + errorMessage ) ;
274
287
}
275
288
276
289
} else if ( queryType == 'BEGIN' ) {
@@ -282,7 +295,8 @@ export class SQLitePluginTurboModule extends TurboModule implements TM.SQLitePlu
282
295
queryResultcall = { 'rowsAffected' : 0 }
283
296
} catch ( e ) {
284
297
errorMessage = e . message ;
285
- Logger . debug ( CommonConstants . TAG , 'test--SQLitePlugin=backgroundExecuteSqlBatch>>>>>>开始事务失败=' + errorMessage ) ;
298
+ Logger . debug ( CommonConstants . TAG ,
299
+ 'test--SQLitePlugin=backgroundExecuteSqlBatch>>>>>>开始事务失败=' + errorMessage ) ;
286
300
}
287
301
} else if ( queryType == 'COMMIT' ) {
288
302
needRawQuery = false ;
@@ -293,7 +307,8 @@ export class SQLitePluginTurboModule extends TurboModule implements TM.SQLitePlu
293
307
queryResultcall = { 'rowsAffected' : 0 }
294
308
} catch ( e ) {
295
309
errorMessage = e . message ;
296
- Logger . debug ( CommonConstants . TAG , 'test--SQLitePlugin=backgroundExecuteSqlBatch>>>>>>结束事务失败=' + errorMessage ) ;
310
+ Logger . debug ( CommonConstants . TAG ,
311
+ 'test--SQLitePlugin=backgroundExecuteSqlBatch>>>>>>结束事务失败=' + errorMessage ) ;
297
312
}
298
313
} else if ( queryType == 'ROLLBACK' ) {
299
314
needRawQuery = false ;
@@ -304,15 +319,17 @@ export class SQLitePluginTurboModule extends TurboModule implements TM.SQLitePlu
304
319
queryResultcall = { 'rowsAffected' : 0 }
305
320
} catch ( e ) {
306
321
errorMessage = e . message ;
307
- Logger . debug ( CommonConstants . TAG , 'test--SQLitePlugin=backgroundExecuteSqlBatch>>>>>>回滚事务失败=' + errorMessage ) ;
322
+ Logger . debug ( CommonConstants . TAG ,
323
+ 'test--SQLitePlugin=backgroundExecuteSqlBatch>>>>>>回滚事务失败=' + errorMessage ) ;
308
324
}
309
325
}
310
326
311
327
if ( needRawQuery ) {
312
328
try {
313
329
let resultSet = await rdbStore . querySql ( querySql , queryParams )
314
330
const count = resultSet . columnCount ;
315
- Logger . debug ( CommonConstants . TAG , 'test--SQLitePlugin=backgroundExecuteSqlBatch>>>>>>查询数据个数====' + count ) ;
331
+ Logger . debug ( CommonConstants . TAG ,
332
+ 'test--SQLitePlugin=backgroundExecuteSqlBatch>>>>>>查询数据个数====' + count ) ;
316
333
let results : Array < relationalStore . ValuesBucket > = new Array < relationalStore . ValuesBucket > ( ) ;
317
334
318
335
while ( resultSet . goToNextRow ( ) ) {
@@ -343,7 +360,8 @@ export class SQLitePluginTurboModule extends TurboModule implements TM.SQLitePlu
343
360
success ( callvalue ) ;
344
361
}
345
362
346
- async attachDatabase ( dbname : string , dbNameToAttach : string , dbAlias : string , success : ( t : Object , r : Object ) => void , error : ( e : Object ) => void ) : Promise < void > {
363
+ async attachDatabase ( dbname : string , dbNameToAttach : string , dbAlias : string , success : ( t : Object , r : Object ) => void ,
364
+ error : ( e : Object ) => void ) : Promise < void > {
347
365
348
366
const rdbStore = this . rdbMap . get ( dbname ) as relationalStore . RdbStore ;
349
367
@@ -381,23 +399,26 @@ export class SQLitePluginTurboModule extends TurboModule implements TM.SQLitePlu
381
399
try {
382
400
fs . mkdirSync ( dirPath ) ;
383
401
} catch ( error ) {
384
- Logger . debug ( CommonConstants . TAG , 'test--SQLitePlugin=mkdir dirPath failed,error code:' + error . code + ", message:" + error . message ) ;
402
+ Logger . debug ( CommonConstants . TAG ,
403
+ 'test--SQLitePlugin=mkdir dirPath failed,error code:' + error . code + ", message:" + error . message ) ;
385
404
}
386
405
387
406
try {
388
407
dirPath = dirPath + "/rdb"
389
408
390
409
fs . mkdirSync ( dirPath ) ;
391
410
} catch ( error ) {
392
- Logger . debug ( CommonConstants . TAG , 'test--SQLitePlugin=mkdir dirPathrdbPath failed,error code:' + error . code + ", message:" + error . message ) ;
411
+ Logger . debug ( CommonConstants . TAG ,
412
+ 'test--SQLitePlugin=mkdir dirPathrdbPath failed,error code:' + error . code + ", message:" + error . message ) ;
393
413
}
394
414
395
415
try {
396
416
let result = this . context . uiAbilityContext . resourceManager . getRawFdSync ( 'rdb/' + dbName ) ;
397
417
398
418
this . saveFileToCache ( result , dbName )
399
419
} catch ( error ) {
400
- Logger . debug ( CommonConstants . TAG , 'test--SQLitePlugin=callback getRawFd failed,error code:' + error . code + ", message:" + error . message )
420
+ Logger . debug ( CommonConstants . TAG ,
421
+ 'test--SQLitePlugin=callback getRawFd failed,error code:' + error . code + ", message:" + error . message )
401
422
}
402
423
}
403
424
0 commit comments