@capacitor-community/sqlite 4.6.1 → 4.6.2-1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,2020 @@
1
+ //import { Capacitor } from '@capacitor/core';
2
+
3
+ /**
4
+ * CapacitorSQLitePlugin Interface
5
+ */
6
+ export interface CapacitorSQLitePlugin {
7
+ /**
8
+ * Initialize the web store
9
+ *
10
+ * @return Promise<void>
11
+ * @since 3.2.3-1
12
+ */
13
+
14
+ initWebStore(): Promise<void>;
15
+ /**
16
+ * Save database to the web store
17
+ *
18
+ * @param options: capSQLiteOptions
19
+ * @return Promise<void>
20
+ * @since 3.2.3-1
21
+ */
22
+
23
+ saveToStore(options: capSQLiteOptions): Promise<void>;
24
+ /**
25
+ * Check if a passphrase exists in a secure store
26
+ *
27
+ * @return Promise<capSQLiteResult>
28
+ * @since 3.0.0-beta.13
29
+ */
30
+ isSecretStored(): Promise<capSQLiteResult>;
31
+ /**
32
+ * Store a passphrase in a secure store
33
+ * Update the secret of previous encrypted databases with GlobalSQLite
34
+ * !!! Only to be used once if you wish to encrypt database !!!
35
+ *
36
+ * @param options capSetSecretOptions
37
+ * @return Promise<void>
38
+ * @since 3.0.0-beta.13
39
+ */
40
+ setEncryptionSecret(options: capSetSecretOptions): Promise<void>;
41
+ /**
42
+ * Change the passphrase in a secure store
43
+ * Update the secret of previous encrypted databases with passphrase
44
+ * in secure store
45
+ *
46
+ * @param options capChangeSecretOptions
47
+ * @return Promise<void>
48
+ * @since 3.0.0-beta.13
49
+ */
50
+ changeEncryptionSecret(options: capChangeSecretOptions): Promise<void>;
51
+ /**
52
+ * Clear the passphrase in the secure store
53
+ *
54
+ * @return Promise<void>
55
+ * @since 3.5.1
56
+ */
57
+ clearEncryptionSecret(): Promise<void>;
58
+ /**
59
+ * Check encryption passphrase
60
+ *
61
+ * @return Promise<capSQLiteResult>
62
+ * @since 4.6.1
63
+ */
64
+
65
+ checkEncryptionSecret(options: capSetSecretOptions): Promise<capSQLiteResult>;
66
+
67
+ /**
68
+ * create a database connection
69
+ * @param options capConnectionOptions
70
+ * @return Promise<void>
71
+ * @since 2.9.0 refactor
72
+ */
73
+ createConnection(options: capConnectionOptions): Promise<void>;
74
+ /**
75
+ * close a database connection
76
+ * @param options capSQLiteOptions
77
+ * @return Promise<void>
78
+ * @since 2.9.0 refactor
79
+ */
80
+ closeConnection(options: capSQLiteOptions): Promise<void>;
81
+ /**
82
+ * Echo a given string
83
+ *
84
+ * @param options: capEchoOptions
85
+ * @return Promise<capEchoResult>
86
+ * @since 0.0.1
87
+ */
88
+ echo(options: capEchoOptions): Promise<capEchoResult>;
89
+ /**
90
+ * Opens a SQLite database.
91
+ * Attention: This re-opens a database if it's already open!
92
+ *
93
+ * @param options: capSQLiteOptions
94
+ * @returns Promise<void>
95
+ * @since 0.0.1
96
+ */
97
+ open(options: capSQLiteOptions): Promise<void>;
98
+ /**
99
+ * Close a SQLite database
100
+ * @param options: capSQLiteOptions
101
+ * @returns Promise<void>
102
+ * @since 0.0.1
103
+ */
104
+ close(options: capSQLiteOptions): Promise<void>;
105
+ /**
106
+ * GetUrl get the database Url
107
+ * @param options: capSQLiteOptions
108
+ * @returns Promise<capSQLiteUrl>
109
+ * @since 3.3.3-4
110
+ */
111
+ getUrl(options: capSQLiteOptions): Promise<capSQLiteUrl>;
112
+ /**
113
+ * Get a SQLite database version
114
+ * @param options: capSQLiteOptions
115
+ * @returns Promise<void>
116
+ * @since 3.2.0
117
+ */
118
+ getVersion(options: capSQLiteOptions): Promise<capVersionResult>;
119
+ /**
120
+ * Execute a Batch of Raw Statements as String
121
+ * @param options: capSQLiteExecuteOptions
122
+ * @returns Promise<capSQLiteChanges>
123
+ * @since 0.0.1
124
+ */
125
+ execute(options: capSQLiteExecuteOptions): Promise<capSQLiteChanges>;
126
+ /**
127
+ * Execute a Set of Raw Statements as Array of CapSQLiteSet
128
+ * @param options: capSQLiteSetOptions
129
+ * @returns Promise<capSQLiteChanges>
130
+ * @since 2.2.0-2
131
+ */
132
+ executeSet(options: capSQLiteSetOptions): Promise<capSQLiteChanges>;
133
+ /**
134
+ * Execute a Single Statement
135
+ * @param options: capSQLiteRunOptions
136
+ * @returns Promise<capSQLiteChanges>
137
+ * @since 0.0.1
138
+ */
139
+ run(options: capSQLiteRunOptions): Promise<capSQLiteChanges>;
140
+ /**
141
+ * Query a Single Statement
142
+ * @param options: capSQLiteQueryOptions
143
+ * @returns Promise<capSQLiteValues>
144
+ * @since 0.0.1
145
+ */
146
+ query(options: capSQLiteQueryOptions): Promise<capSQLiteValues>;
147
+ /**
148
+ * Check if a SQLite database exists with opened connection
149
+ * @param options: capSQLiteOptions
150
+ * @returns Promise<capSQLiteResult>
151
+ * @since 2.0.1-1
152
+ */
153
+ isDBExists(options: capSQLiteOptions): Promise<capSQLiteResult>;
154
+ /**
155
+ * Check if a SQLite database is opened
156
+ * @param options: capSQLiteOptions
157
+ * @returns Promise<capSQLiteResult>
158
+ * @since 3.0.0-beta.5
159
+ */
160
+ isDBOpen(options: capSQLiteOptions): Promise<capSQLiteResult>;
161
+ /**
162
+ * Check if a SQLite database exists without connection
163
+ * @param options: capSQLiteOptions
164
+ * @returns Promise<capSQLiteResult>
165
+ * @since 3.0.0-beta.5
166
+ */
167
+ isDatabase(options: capSQLiteOptions): Promise<capSQLiteResult>;
168
+ /**
169
+ * Check if a table exists in a SQLite database
170
+ * @param options: capSQLiteTableOptions
171
+ * @returns Promise<capSQLiteResult>
172
+ * @since 3.0.0-beta.5
173
+ */
174
+ isTableExists(options: capSQLiteTableOptions): Promise<capSQLiteResult>;
175
+ /**
176
+ * Delete a SQLite database
177
+ * @param options: capSQLiteOptions
178
+ * @returns Promise<void>
179
+ * @since 0.0.1
180
+ */
181
+ deleteDatabase(options: capSQLiteOptions): Promise<void>;
182
+ /**
183
+ * Is Json Object Valid
184
+ * @param options: capSQLiteImportOptions
185
+ * @returns Promise<capSQLiteResult>
186
+ * @since 2.0.1-1
187
+ */
188
+ isJsonValid(options: capSQLiteImportOptions): Promise<capSQLiteResult>;
189
+ /**
190
+ * Import from Json Object
191
+ * @param options: capSQLiteImportOptions
192
+ * @returns Promise<capSQLiteChanges>
193
+ * @since 2.0.0-3
194
+ */
195
+ importFromJson(options: capSQLiteImportOptions): Promise<capSQLiteChanges>;
196
+ /**
197
+ * Export to Json Object
198
+ * @param options: capSQLiteExportOptions
199
+ * @returns Promise<capSQLiteJson>
200
+ * @since 2.0.1-1
201
+ */
202
+ exportToJson(options: capSQLiteExportOptions): Promise<capSQLiteJson>;
203
+ /**
204
+ * Create a synchronization table
205
+ * @param options: capSQLiteOptions
206
+ * @returns Promise<capSQLiteChanges>
207
+ * @since 2.0.1-1
208
+ */
209
+ createSyncTable(options: capSQLiteOptions): Promise<capSQLiteChanges>;
210
+ /**
211
+ * Set the synchronization date
212
+ * @param options: capSQLiteSyncDateOptions
213
+ * @returns Promise<void>
214
+ * @since 2.0.1-1
215
+ */
216
+ setSyncDate(options: capSQLiteSyncDateOptions): Promise<void>;
217
+ /**
218
+ * Get the synchronization date
219
+ * @param options: capSQLiteOptions
220
+ * @returns Promise<capSQLiteSyncDate>
221
+ * @since 2.9.0
222
+ */
223
+ getSyncDate(options: capSQLiteOptions): Promise<capSQLiteSyncDate>;
224
+ /**
225
+ * Remove rows with sql_deleted = 1 after an export
226
+ * @param options
227
+ * @returns Promise<void>
228
+ * @since 3.4.3-2
229
+ */
230
+ deleteExportedRows(options: capSQLiteOptions): Promise<void>;
231
+ /**
232
+ * Add the upgrade Statement for database version upgrading
233
+ * @param options: capSQLiteUpgradeOptions
234
+ * @returns Promise<void>
235
+ * @since 2.4.2-6 iOS & Electron 2.4.2-7 Android
236
+ */
237
+ addUpgradeStatement(options: capSQLiteUpgradeOptions): Promise<void>;
238
+ /**
239
+ * Copy databases from public/assets/databases folder to application databases folder
240
+ * @param options: capSQLiteFromAssets since 3.2.5-2
241
+ * @returns Promise<void>
242
+ * @since 2.9.0 refactor
243
+ */
244
+ copyFromAssets(options: capSQLiteFromAssetsOptions): Promise<void>;
245
+ /**
246
+ * Get database or zipped database(s) from url
247
+ * @param options: capSQLiteHTTPOptions
248
+ * @returns Promise<void>
249
+ * @since 4.1.1
250
+ */
251
+ getFromHTTPRequest(options: capSQLiteHTTPOptions): Promise<void>;
252
+ /**
253
+ * Get the database list
254
+ * @returns Promise<capSQLiteValues>
255
+ * @since 3.0.0-beta.5
256
+ */
257
+ getDatabaseList(): Promise<capSQLiteValues>;
258
+ /**
259
+ * Get the database's table list
260
+ * @param options
261
+ * @returns Promise<capSQLiteValues>
262
+ * @since 3.4.2-3
263
+ */
264
+ getTableList(options: capSQLiteOptions): Promise<capSQLiteValues>;
265
+ /**
266
+ * Get the Migratable database list
267
+ * @param options: capSQLitePathOptions // only iOS & Android since 3.2.4-2
268
+ * @returns Promise<capSQLiteValues>
269
+ * @since 3.0.0-beta.5
270
+ */
271
+ getMigratableDbList(options: capSQLitePathOptions): Promise<capSQLiteValues>;
272
+ /**
273
+ * Add SQLIte Suffix to existing databases
274
+ * @param options: capSQLitePathOptions
275
+ * @returns Promise<void>
276
+ * @since 3.0.0-beta.5
277
+ */
278
+ addSQLiteSuffix(options: capSQLitePathOptions): Promise<void>;
279
+ /**
280
+ * Delete Old Cordova databases
281
+ * @param options: capSQLitePathOptions
282
+ * @returns Promise<void>
283
+ * @since 3.0.0-beta.5
284
+ */
285
+ deleteOldDatabases(options: capSQLitePathOptions): Promise<void>;
286
+ /**
287
+ * Moves databases to the location the plugin can read them, and adds sqlite suffix
288
+ * This resembles calling addSQLiteSuffix and deleteOldDatabases, but it is more performant as it doesn't copy but moves the files
289
+ * @param options: capSQLitePathOptions
290
+ */
291
+ moveDatabasesAndAddSuffix(options: capSQLitePathOptions): Promise<void>;
292
+ /**
293
+ * Check Connection Consistency JS <=> Native
294
+ * return true : consistency, connections are opened
295
+ * return false : no consistency, connections are closed
296
+ * @param options: capAllConnectionsOptions
297
+ * @returns Promise<capSQLiteResult>
298
+ * @since 3.0.0-beta.11
299
+ */
300
+ checkConnectionsConsistency(
301
+ options: capAllConnectionsOptions,
302
+ ): Promise<capSQLiteResult>;
303
+ /**
304
+ * get a non conformed database path
305
+ * @param options capNCDatabasePathOptions
306
+ * @return Promise<capNCDatabasePathResult>
307
+ * @since 3.3.3-1
308
+ */
309
+ getNCDatabasePath(
310
+ options: capNCDatabasePathOptions,
311
+ ): Promise<capNCDatabasePathResult>;
312
+ /**
313
+ * create a non conformed database connection
314
+ * @param options capNCConnectionOptions
315
+ * @return Promise<void>
316
+ * @since 3.3.3-1
317
+ */
318
+ createNCConnection(options: capNCConnectionOptions): Promise<void>;
319
+ /**
320
+ * close a non conformed database connection
321
+ * @param options capNCOptions
322
+ * @return Promise<void>
323
+ * @since 3.3.3-1
324
+ */
325
+ closeNCConnection(options: capNCOptions): Promise<void>;
326
+ /**
327
+ * Check if a non conformed database exists without connection
328
+ * @param options: capNCOptions
329
+ * @returns Promise<capSQLiteResult>
330
+ * @since 3.3.3-1
331
+ */
332
+ isNCDatabase(options: capNCOptions): Promise<capSQLiteResult>;
333
+ }
334
+
335
+ export interface capSetSecretOptions {
336
+ /**
337
+ * The passphrase for Encrypted Databases
338
+ */
339
+ passphrase?: string;
340
+ }
341
+ export interface capChangeSecretOptions {
342
+ /**
343
+ * The new passphrase for Encrypted Databases
344
+ */
345
+ passphrase?: string;
346
+ /**
347
+ * The old passphrase for Encrypted Databases
348
+ */
349
+ oldpassphrase?: string;
350
+ }
351
+ export interface capEchoOptions {
352
+ /**
353
+ * String to be echoed
354
+ */
355
+ value?: string;
356
+ }
357
+ export interface capConnectionOptions {
358
+ /**
359
+ * The database name
360
+ */
361
+ database?: string;
362
+ /**
363
+ * The database version
364
+ */
365
+ version?: number;
366
+ /**
367
+ * Set to true (database encryption) / false
368
+ */
369
+ encrypted?: boolean;
370
+ /**
371
+ * Set the mode for database encryption
372
+ * ["encryption", "secret", "newsecret"]
373
+ */
374
+ mode?: string;
375
+ /**
376
+ * Set to true (database in read-only mode) / false
377
+ */
378
+ readonly?: boolean;
379
+ }
380
+ export interface capAllConnectionsOptions {
381
+ /**
382
+ * the dbName of all connections
383
+ * @since 3.0.0-beta.10
384
+ */
385
+ dbNames?: string[];
386
+ /**
387
+ * the openMode ("RW" read&write, "RO" readonly) of all connections
388
+ * @since 4.1.0
389
+ */
390
+ openModes?: string[];
391
+ }
392
+ export interface capSQLiteOptions {
393
+ /**
394
+ * The database name
395
+ */
396
+ database?: string;
397
+ /**
398
+ * Set to true (database in read-only mode) / false
399
+ */
400
+ readonly?: boolean;
401
+ }
402
+ export interface capNCDatabasePathOptions {
403
+ /**
404
+ * the database path
405
+ */
406
+ path?: string;
407
+ /**
408
+ * The database name
409
+ */
410
+ database?: string;
411
+ }
412
+ export interface capNCConnectionOptions {
413
+ /**
414
+ * The database path
415
+ */
416
+ databasePath?: string;
417
+ /**
418
+ * The database version
419
+ */
420
+ version?: number;
421
+ }
422
+
423
+ export interface capNCOptions {
424
+ /**
425
+ * The database path
426
+ */
427
+ databasePath?: string;
428
+ }
429
+ export interface capSQLiteExecuteOptions {
430
+ /**
431
+ * The database name
432
+ */
433
+ database?: string;
434
+ /**
435
+ * The batch of raw SQL statements as string
436
+ */
437
+ statements?: string;
438
+ /**
439
+ * Enable / Disable transactions
440
+ * default Enable (true)
441
+ * @since 3.0.0-beta.10
442
+ */
443
+ transaction?: boolean;
444
+ /**
445
+ * ReadOnly / ReadWrite
446
+ * default ReadWrite (false)
447
+ * @since 4.1.0-7
448
+ */
449
+ readonly?: boolean;
450
+ }
451
+ export interface capSQLiteSetOptions {
452
+ /**
453
+ * The database name
454
+ */
455
+ database?: string;
456
+ /**
457
+ * The batch of raw SQL statements as Array of capSQLLiteSet
458
+ */
459
+ set?: capSQLiteSet[];
460
+ /**
461
+ * Enable / Disable transactions
462
+ * default Enable (true)
463
+ * @since 3.0.0-beta.10
464
+ */
465
+ transaction?: boolean;
466
+ /**
467
+ * ReadOnly / ReadWrite
468
+ * default ReadWrite (false)
469
+ * @since 4.1.0-7
470
+ */
471
+ readonly?: boolean;
472
+ }
473
+ export interface capSQLiteRunOptions {
474
+ /**
475
+ * The database name
476
+ */
477
+ database?: string;
478
+ /**
479
+ * A statement
480
+ */
481
+ statement?: string;
482
+ /**
483
+ * A set of values for a statement
484
+ */
485
+ values?: any[];
486
+ /**
487
+ * Enable / Disable transactions
488
+ * default Enable (true)
489
+ * @since 3.0.0-beta.10
490
+ */
491
+ transaction?: boolean;
492
+ /**
493
+ * ReadOnly / ReadWrite
494
+ * default ReadWrite (false)
495
+ * @since 4.1.0-7
496
+ */
497
+ readonly?: boolean;
498
+ }
499
+ export interface capSQLiteQueryOptions {
500
+ /**
501
+ * The database name
502
+ */
503
+ database?: string;
504
+ /**
505
+ * A statement
506
+ */
507
+ statement?: string;
508
+ /**
509
+ * A set of values for a statement
510
+ * Change to any[]
511
+ * @since 3.0.0-beta.11
512
+ */
513
+ values?: any[];
514
+ /**
515
+ * ReadOnly / ReadWrite
516
+ * default ReadWrite (false)
517
+ * @since 4.1.0-7
518
+ */
519
+ readonly?: boolean;
520
+ }
521
+ export interface capSQLiteImportOptions {
522
+ /**
523
+ * Set the JSON object to import
524
+ *
525
+ */
526
+ jsonstring?: string;
527
+ }
528
+ export interface capSQLiteExportOptions {
529
+ /**
530
+ * The database name
531
+ */
532
+ database?: string;
533
+ /**
534
+ * Set the mode to export JSON Object:
535
+ * "full" or "partial"
536
+ *
537
+ */
538
+ jsonexportmode?: string;
539
+ /**
540
+ * ReadOnly / ReadWrite
541
+ * default ReadWrite (false)
542
+ * @since 4.1.0-7
543
+ */
544
+ readonly?: boolean;
545
+ }
546
+ export interface capSQLiteFromAssetsOptions {
547
+ /**
548
+ * Set the overwrite mode for the copy from assets
549
+ * "true"/"false" default to "true"
550
+ *
551
+ */
552
+ overwrite?: boolean;
553
+ }
554
+ export interface capSQLiteHTTPOptions {
555
+ /**
556
+ * The url of the database or the zipped database(s)
557
+ */
558
+ url?: string;
559
+
560
+ /**
561
+ * Set the overwrite mode for the copy from assets
562
+ * "true"/"false" default to "true"
563
+ *
564
+ */
565
+ overwrite?: boolean;
566
+ }
567
+ export interface capSQLiteSyncDateOptions {
568
+ /**
569
+ * The database name
570
+ */
571
+ database?: string;
572
+ /**
573
+ * Set the synchronization date
574
+ * Format yyyy-MM-dd'T'HH:mm:ss.SSSZ
575
+ */
576
+ syncdate?: string;
577
+ /**
578
+ * ReadOnly / ReadWrite
579
+ * default ReadWrite (false)
580
+ * @since 4.1.0-7
581
+ */
582
+ readonly?: boolean;
583
+ }
584
+ export interface capSQLiteSet {
585
+ /**
586
+ * A statement
587
+ */
588
+ statement?: string;
589
+ /**
590
+ * the data values list as an Array
591
+ */
592
+ values?: any[];
593
+ }
594
+ export interface capSQLiteUpgradeOptions {
595
+ /**
596
+ * The database name
597
+ */
598
+ database?: string;
599
+ /**
600
+ * The upgrade options for version upgrade
601
+ * Array of length 1 to easiest the iOS plugin
602
+ */
603
+ upgrade?: capSQLiteVersionUpgrade[];
604
+ }
605
+ export interface capSQLitePathOptions {
606
+ /**
607
+ * The folder path of existing databases
608
+ * If not given folder path is "default"
609
+ */
610
+ folderPath?: string;
611
+ /**
612
+ * The database name's list to be copied and/or deleted
613
+ * since 3.2.4-1
614
+ * If not given all databases in the specify folder path
615
+ */
616
+ dbNameList?: string[];
617
+ }
618
+ export interface capSQLiteTableOptions {
619
+ /**
620
+ * The database name
621
+ */
622
+ database?: string;
623
+ /**
624
+ * The table name
625
+ */
626
+ table?: string;
627
+ /**
628
+ * ReadOnly / ReadWrite
629
+ * default ReadWrite (false)
630
+ * @since 4.1.0-7
631
+ */
632
+ readonly?: boolean;
633
+ }
634
+ export interface capEchoResult {
635
+ /**
636
+ * String returned
637
+ */
638
+ value?: string;
639
+ }
640
+ export interface capNCDatabasePathResult {
641
+ /**
642
+ * String returned
643
+ */
644
+ path?: string;
645
+ }
646
+ export interface capVersionResult {
647
+ /**
648
+ * Number returned
649
+ */
650
+ version?: number;
651
+ }
652
+ export interface capSQLiteResult {
653
+ /**
654
+ * result set to true when successful else false
655
+ */
656
+ result?: boolean;
657
+ }
658
+ export interface capSQLiteUrl {
659
+ /**
660
+ * a returned url
661
+ */
662
+ url?: string;
663
+ }
664
+ export interface capSQLiteChanges {
665
+ /**
666
+ * a returned Changes
667
+ */
668
+ changes?: Changes;
669
+ }
670
+ export interface Changes {
671
+ /**
672
+ * the number of changes from an execute or run command
673
+ */
674
+ changes?: number;
675
+ /**
676
+ * the lastId created from a run command
677
+ */
678
+ lastId?: number;
679
+ }
680
+ export interface capSQLiteValues {
681
+ /**
682
+ * the data values list as an Array
683
+ * iOS the first row is the returned ios_columns name list
684
+ */
685
+ values?: any[];
686
+ }
687
+ export interface DBSQLiteValues {
688
+ /**
689
+ * the data values list as an Array
690
+ */
691
+ values?: any[];
692
+ }
693
+ export interface capSQLiteJson {
694
+ /**
695
+ * an export JSON object
696
+ */
697
+ export?: JsonSQLite;
698
+ }
699
+ export interface capSQLiteSyncDate {
700
+ /**
701
+ * the synchronization date
702
+ */
703
+ syncDate?: number;
704
+ }
705
+
706
+ /* JSON Types */
707
+ export interface JsonSQLite {
708
+ /**
709
+ * The database name
710
+ */
711
+ database: string;
712
+ /**
713
+ * The database version
714
+ */
715
+ version: number;
716
+ /**
717
+ * Delete the database prior to import (default false)
718
+ */
719
+ overwrite?: boolean;
720
+ /**
721
+ * Set to true (database encryption) / false
722
+ */
723
+ encrypted: boolean;
724
+ /***
725
+ * Set the mode
726
+ * ["full", "partial"]
727
+ */
728
+ mode: string;
729
+ /***
730
+ * Array of Table (JsonTable)
731
+ */
732
+ tables: JsonTable[];
733
+ /***
734
+ * Array of View (JsonView)
735
+ */
736
+ views?: JsonView[];
737
+ }
738
+ export interface JsonTable {
739
+ /**
740
+ * The database name
741
+ */
742
+ name: string;
743
+ /***
744
+ * Array of Schema (JsonColumn)
745
+ */
746
+ schema?: JsonColumn[];
747
+ /***
748
+ * Array of Index (JsonIndex)
749
+ */
750
+ indexes?: JsonIndex[];
751
+ /***
752
+ * Array of Trigger (JsonTrigger)
753
+ */
754
+ triggers?: JsonTrigger[];
755
+ /***
756
+ * Array of Table data
757
+ */
758
+ values?: any[][];
759
+ }
760
+ export interface JsonColumn {
761
+ /**
762
+ * The column name
763
+ */
764
+ column?: string;
765
+ /**
766
+ * The column data (type, unique, ...)
767
+ */
768
+ value: string;
769
+ /**
770
+ * The column foreign key constraints
771
+ */
772
+ foreignkey?: string;
773
+ /**
774
+ * the column constraint
775
+ */
776
+ constraint?: string;
777
+ }
778
+ export interface JsonTrigger {
779
+ /**
780
+ * The trigger name
781
+ */
782
+ name: string;
783
+ /**
784
+ * The trigger time event fired
785
+ */
786
+ timeevent: string;
787
+
788
+ /**
789
+ * The trigger condition
790
+ */
791
+ condition?: string;
792
+
793
+ /**
794
+ * The logic of the trigger
795
+ */
796
+ logic: string;
797
+ }
798
+ export interface JsonIndex {
799
+ /**
800
+ * The index name
801
+ */
802
+ name: string;
803
+ /**
804
+ * The value of the index can have the following formats:
805
+ * email
806
+ * email ASC
807
+ * email, MobileNumber
808
+ * email ASC, MobileNumber DESC
809
+ */
810
+ value: string;
811
+ /**
812
+ * the mode (Optional)
813
+ * UNIQUE
814
+ */
815
+ mode?: string;
816
+ }
817
+ export interface JsonView {
818
+ /**
819
+ * The view name
820
+ */
821
+ name: string;
822
+ /**
823
+ * The view create statement
824
+ */
825
+ value: string;
826
+ }
827
+ export interface capBiometricListener {
828
+ /**
829
+ * Biometric ready
830
+ */
831
+ result: boolean;
832
+ message: string;
833
+ }
834
+ export interface capJsonProgressListener {
835
+ /**
836
+ * Progress message
837
+ */
838
+ progress?: string;
839
+ }
840
+ export interface capSQLiteVersionUpgrade {
841
+ toVersion: number;
842
+ statements: string[];
843
+ }
844
+
845
+ /**
846
+ * SQLiteConnection Interface
847
+ */
848
+ export interface ISQLiteConnection {
849
+ /**
850
+ * Init the web store
851
+ * @returns Promise<void>
852
+ * @since 3.2.3-1
853
+ */
854
+ initWebStore(): Promise<void>;
855
+ /**
856
+ * Save the datbase to the web store
857
+ * @param database
858
+ * @returns Promise<void>
859
+ * @since 3.2.3-1
860
+ */
861
+ saveToStore(database: string): Promise<void>;
862
+ /**
863
+ * Echo a value
864
+ * @param value
865
+ * @returns Promise<capEchoResult>
866
+ * @since 2.9.0 refactor
867
+ */
868
+ echo(value: string): Promise<capEchoResult>;
869
+ /**
870
+ * Check if a secret is stored
871
+ * @returns Promise<capSQLiteResult>
872
+ * @since 3.0.0-beta.13
873
+ */
874
+ isSecretStored(): Promise<capSQLiteResult>;
875
+ /**
876
+ * Set a passphrase in a secure store
877
+ * @param passphrase
878
+ * @returns Promise<void>
879
+ * @since 3.0.0-beta.13
880
+ */
881
+ setEncryptionSecret(passphrase: string): Promise<void>;
882
+ /**
883
+ * Change the passphrase in a secure store
884
+ * @param passphrase
885
+ * @param oldpassphrase
886
+ * @returns Promise<void>
887
+ * @since 3.0.0-beta.13
888
+ */
889
+ changeEncryptionSecret(
890
+ passphrase: string,
891
+ oldpassphrase: string,
892
+ ): Promise<void>;
893
+ /**
894
+ * Clear the passphrase in a secure store
895
+ * @returns Promise<void>
896
+ * @since 3.5.1
897
+ */
898
+ clearEncryptionSecret(): Promise<void>;
899
+ /**
900
+ * Check the passphrase stored in a secure store
901
+ * @param passphrase
902
+ * @returns Promise<capSQLiteResult>
903
+ * @since 4.6.1
904
+ */
905
+ checkEncryptionSecret(passphrase: string): Promise<capSQLiteResult>;
906
+ /**
907
+ * Add the upgrade Statement for database version upgrading
908
+ * @param database
909
+ * @param toVersion
910
+ * @param statement
911
+ * @param set
912
+ * @returns Promise<void>
913
+ * @since 2.9.0 refactor
914
+ */
915
+ addUpgradeStatement(
916
+ database: string,
917
+ toVersion: number,
918
+ statements: string[],
919
+ ): Promise<void>;
920
+ /**
921
+ * Create a connection to a database
922
+ * @param database
923
+ * @param encrypted
924
+ * @param mode
925
+ * @param version
926
+ * @param readonly
927
+ * @returns Promise<SQLiteDBConnection>
928
+ * @since 2.9.0 refactor
929
+ */
930
+ createConnection(
931
+ database: string,
932
+ encrypted: boolean,
933
+ mode: string,
934
+ version: number,
935
+ readonly: boolean,
936
+ ): Promise<SQLiteDBConnection>;
937
+ /**
938
+ * Check if a connection exists
939
+ * @param database
940
+ * @param readonly
941
+ * @returns Promise<capSQLiteResult>
942
+ * @since 3.0.0-beta.5
943
+ */
944
+ isConnection(database: string, readonly: boolean): Promise<capSQLiteResult>;
945
+ /**
946
+ * Retrieve an existing database connection
947
+ * @param database
948
+ * @param readonly
949
+ * @returns Promise<SQLiteDBConnection>
950
+ * @since 2.9.0 refactor
951
+ */
952
+ retrieveConnection(
953
+ database: string,
954
+ readonly: boolean,
955
+ ): Promise<SQLiteDBConnection>;
956
+ /**
957
+ * Retrieve all database connections
958
+ * @returns Promise<Map<string, SQLiteDBConnection>>
959
+ * @since 2.9.0 refactor
960
+ */
961
+ retrieveAllConnections(): Promise<Map<string, SQLiteDBConnection>>;
962
+ /**
963
+ * Close a database connection
964
+ * @param database
965
+ * @param readonly
966
+ * @returns Promise<void>
967
+ * @since 2.9.0 refactor
968
+ */
969
+ closeConnection(database: string, readonly: boolean): Promise<void>;
970
+ /**
971
+ * Close all database connections
972
+ * @returns Promise<void>
973
+ * @since 2.9.0 refactor
974
+ */
975
+ closeAllConnections(): Promise<void>;
976
+ /**
977
+ * Check the consistency between Js Connections
978
+ * and Native Connections
979
+ * if inconsistency all connections are removed
980
+ * @returns Promise<capSQLiteResult>
981
+ * @since 3.0.0-beta.10
982
+ */
983
+ checkConnectionsConsistency(): Promise<capSQLiteResult>;
984
+ /**
985
+ * get a non-conformed database path
986
+ * @param path
987
+ * @param database
988
+ * @returns Promise<capNCDatabasePathResult>
989
+ * @since 3.3.3-1
990
+ */
991
+ getNCDatabasePath(
992
+ path: string,
993
+ database: string,
994
+ ): Promise<capNCDatabasePathResult>;
995
+ /**
996
+ * Create a non-conformed database connection
997
+ * @param databasePath
998
+ * @param version
999
+ * @returns Promise<SQLiteDBConnection>
1000
+ * @since 3.3.3-1
1001
+ */
1002
+ createNCConnection(
1003
+ databasePath: string,
1004
+ version: number,
1005
+ ): Promise<SQLiteDBConnection>;
1006
+ /**
1007
+ * Close a non-conformed database connection
1008
+ * @param databasePath
1009
+ * @returns Promise<void>
1010
+ * @since 3.3.3-1
1011
+ */
1012
+ closeNCConnection(databasePath: string): Promise<void>;
1013
+ /**
1014
+ * Check if a non-conformed databaseconnection exists
1015
+ * @param databasePath
1016
+ * @returns Promise<capSQLiteResult>
1017
+ * @since 3.3.3-1
1018
+ */
1019
+ isNCConnection(databasePath: string): Promise<capSQLiteResult>;
1020
+ /**
1021
+ * Retrieve an existing non-conformed database connection
1022
+ * @param databasePath
1023
+ * @returns Promise<SQLiteDBConnection>
1024
+ * @since 3.3.3-1
1025
+ */
1026
+ retrieveNCConnection(databasePath: string): Promise<SQLiteDBConnection>;
1027
+
1028
+ /**
1029
+ * Import a database From a JSON
1030
+ * @param jsonstring string
1031
+ * @returns Promise<capSQLiteChanges>
1032
+ * @since 2.9.0 refactor
1033
+ */
1034
+ importFromJson(jsonstring: string): Promise<capSQLiteChanges>;
1035
+ /**
1036
+ * Check the validity of a JSON Object
1037
+ * @param jsonstring string
1038
+ * @returns Promise<capSQLiteResult>
1039
+ * @since 2.9.0 refactor
1040
+ */
1041
+ isJsonValid(jsonstring: string): Promise<capSQLiteResult>;
1042
+ /**
1043
+ * Copy databases from public/assets/databases folder to application databases folder
1044
+ * @param overwrite since 3.2.5-2
1045
+ * @returns Promise<void>
1046
+ * @since 2.9.0 refactor
1047
+ */
1048
+ copyFromAssets(overwrite?: boolean): Promise<void>;
1049
+ /**
1050
+ *
1051
+ * @param url
1052
+ * @param overwrite
1053
+ * @returns Promise<void>
1054
+ * @since 4.1.1
1055
+ */
1056
+ getFromHTTPRequest(url?: string, overwrite?: boolean): Promise<void>;
1057
+ /**
1058
+ * Check if a database exists
1059
+ * @param database
1060
+ * @returns Promise<capSQLiteResult>
1061
+ * @since 3.0.0-beta.5
1062
+ */
1063
+ isDatabase(database: string): Promise<capSQLiteResult>;
1064
+ /**
1065
+ * Check if a non conformed database exists
1066
+ * @param databasePath
1067
+ * @returns Promise<capSQLiteResult>
1068
+ * @since 3.3.3-1
1069
+ */
1070
+ isNCDatabase(databasePath: string): Promise<capSQLiteResult>;
1071
+ /**
1072
+ * Get the database list
1073
+ * @returns Promise<capSQLiteValues>
1074
+ * @since 3.0.0-beta.5
1075
+ */
1076
+ getDatabaseList(): Promise<capSQLiteValues>;
1077
+ /**
1078
+ * Get the Migratable database list
1079
+ * @param folderPath: string // only iOS & Android since 3.2.4-2
1080
+ * @returns Promise<capSQLiteValues>
1081
+ * @since 3.0.0-beta.5
1082
+ */
1083
+ getMigratableDbList(folderPath: string): Promise<capSQLiteValues>;
1084
+
1085
+ /**
1086
+ * Add SQLIte Suffix to existing databases
1087
+ * @param folderPath
1088
+ * @param dbNameList since 3.2.4-1
1089
+ * @returns Promise<void>
1090
+ * @since 3.0.0-beta.5
1091
+ */
1092
+ addSQLiteSuffix(folderPath?: string, dbNameList?: string[]): Promise<void>;
1093
+ /**
1094
+ * Delete Old Cordova databases
1095
+ * @param folderPath
1096
+ * @param dbNameList since 3.2.4-1
1097
+ * @returns Promise<void>
1098
+ * @since 3.0.0-beta.5
1099
+ */
1100
+ deleteOldDatabases(folderPath?: string, dbNameList?: string[]): Promise<void>;
1101
+ /**
1102
+ * Moves databases to the location the plugin can read them, and adds sqlite suffix
1103
+ * This resembles calling addSQLiteSuffix and deleteOldDatabases, but it is more performant as it doesn't copy but moves the files
1104
+ * @param folderPath the origin from where to move the databases
1105
+ * @param dbNameList the names of the databases to move, check out the getMigratableDbList to get a list, an empty list will result in copying all the databases with '.db' extension.
1106
+ */
1107
+ moveDatabasesAndAddSuffix(
1108
+ folderPath?: string,
1109
+ dbNameList?: string[],
1110
+ ): Promise<void>;
1111
+ }
1112
+ /**
1113
+ * SQLiteConnection Class
1114
+ */
1115
+ export class SQLiteConnection implements ISQLiteConnection {
1116
+ private _connectionDict: Map<string, SQLiteDBConnection> = new Map();
1117
+ constructor(private sqlite: any) {}
1118
+
1119
+ async initWebStore(): Promise<void> {
1120
+ try {
1121
+ await this.sqlite.initWebStore();
1122
+ return Promise.resolve();
1123
+ } catch (err) {
1124
+ return Promise.reject(err);
1125
+ }
1126
+ }
1127
+ async saveToStore(database: string): Promise<void> {
1128
+ try {
1129
+ await this.sqlite.saveToStore({ database });
1130
+ return Promise.resolve();
1131
+ } catch (err) {
1132
+ return Promise.reject(err);
1133
+ }
1134
+ }
1135
+ async echo(value: string): Promise<capEchoResult> {
1136
+ try {
1137
+ const res = await this.sqlite.echo({ value });
1138
+ return Promise.resolve(res);
1139
+ } catch (err) {
1140
+ return Promise.reject(err);
1141
+ }
1142
+ }
1143
+ async isSecretStored(): Promise<capSQLiteResult> {
1144
+ try {
1145
+ const res: capSQLiteResult = await this.sqlite.isSecretStored();
1146
+ return Promise.resolve(res);
1147
+ } catch (err) {
1148
+ return Promise.reject(err);
1149
+ }
1150
+ }
1151
+
1152
+ async setEncryptionSecret(passphrase: string): Promise<void> {
1153
+ try {
1154
+ await this.sqlite.setEncryptionSecret({ passphrase: passphrase });
1155
+ return Promise.resolve();
1156
+ } catch (err) {
1157
+ return Promise.reject(err);
1158
+ }
1159
+ }
1160
+ async changeEncryptionSecret(
1161
+ passphrase: string,
1162
+ oldpassphrase: string,
1163
+ ): Promise<void> {
1164
+ try {
1165
+ await this.sqlite.changeEncryptionSecret({
1166
+ passphrase: passphrase,
1167
+ oldpassphrase: oldpassphrase,
1168
+ });
1169
+ return Promise.resolve();
1170
+ } catch (err) {
1171
+ return Promise.reject(err);
1172
+ }
1173
+ }
1174
+ async clearEncryptionSecret(): Promise<void> {
1175
+ try {
1176
+ await this.sqlite.clearEncryptionSecret();
1177
+ return Promise.resolve();
1178
+ } catch (err) {
1179
+ return Promise.reject(err);
1180
+ }
1181
+ }
1182
+ async checkEncryptionSecret(passphrase: string): Promise<capSQLiteResult> {
1183
+ try {
1184
+ const res: capSQLiteResult = await this.sqlite.checkEncryptionSecret({
1185
+ passphrase: passphrase,
1186
+ });
1187
+ return Promise.resolve(res);
1188
+ } catch (err) {
1189
+ return Promise.reject(err);
1190
+ }
1191
+ }
1192
+ async addUpgradeStatement(
1193
+ database: string,
1194
+ toVersion: number,
1195
+ statements: string[],
1196
+ ): Promise<void> {
1197
+ const upgrade: capSQLiteVersionUpgrade = {
1198
+ toVersion,
1199
+ statements,
1200
+ };
1201
+ try {
1202
+ if (database.endsWith('.db')) database = database.slice(0, -3);
1203
+ await this.sqlite.addUpgradeStatement({
1204
+ database,
1205
+ upgrade: [upgrade],
1206
+ });
1207
+ return Promise.resolve();
1208
+ } catch (err) {
1209
+ return Promise.reject(err);
1210
+ }
1211
+ }
1212
+ async createConnection(
1213
+ database: string,
1214
+ encrypted: boolean,
1215
+ mode: string,
1216
+ version: number,
1217
+ readonly: boolean,
1218
+ ): Promise<SQLiteDBConnection> {
1219
+ try {
1220
+ if (database.endsWith('.db')) database = database.slice(0, -3);
1221
+ await this.sqlite.createConnection({
1222
+ database,
1223
+ encrypted,
1224
+ mode,
1225
+ version,
1226
+ readonly,
1227
+ });
1228
+ const conn = new SQLiteDBConnection(database, readonly, this.sqlite);
1229
+ const connName = readonly ? `RO_${database}` : `RW_${database}`;
1230
+ this._connectionDict.set(connName, conn);
1231
+ return Promise.resolve(conn);
1232
+ } catch (err) {
1233
+ return Promise.reject(err);
1234
+ }
1235
+ }
1236
+ async closeConnection(database: string, readonly: boolean): Promise<void> {
1237
+ try {
1238
+ if (database.endsWith('.db')) database = database.slice(0, -3);
1239
+ await this.sqlite.closeConnection({ database, readonly });
1240
+ const connName = readonly ? `RO_${database}` : `RW_${database}`;
1241
+ this._connectionDict.delete(connName);
1242
+ return Promise.resolve();
1243
+ } catch (err) {
1244
+ return Promise.reject(err);
1245
+ }
1246
+ }
1247
+ async isConnection(
1248
+ database: string,
1249
+ readonly: boolean,
1250
+ ): Promise<capSQLiteResult> {
1251
+ const res: capSQLiteResult = {} as capSQLiteResult;
1252
+ if (database.endsWith('.db')) database = database.slice(0, -3);
1253
+ const connName = readonly ? `RO_${database}` : `RW_${database}`;
1254
+ res.result = this._connectionDict.has(connName);
1255
+ return Promise.resolve(res);
1256
+ }
1257
+ async retrieveConnection(
1258
+ database: string,
1259
+ readonly: boolean,
1260
+ ): Promise<SQLiteDBConnection> {
1261
+ if (database.endsWith('.db')) database = database.slice(0, -3);
1262
+ const connName = readonly ? `RO_${database}` : `RW_${database}`;
1263
+ if (this._connectionDict.has(connName)) {
1264
+ const conn = this._connectionDict.get(connName);
1265
+ if (typeof conn != 'undefined') return Promise.resolve(conn);
1266
+ else {
1267
+ return Promise.reject(`Connection ${database} is undefined`);
1268
+ }
1269
+ } else {
1270
+ return Promise.reject(`Connection ${database} does not exist`);
1271
+ }
1272
+ }
1273
+ async getNCDatabasePath(
1274
+ path: string,
1275
+ database: string,
1276
+ ): Promise<capNCDatabasePathResult> {
1277
+ try {
1278
+ const databasePath: capNCDatabasePathResult =
1279
+ await this.sqlite.getNCDatabasePath({
1280
+ path,
1281
+ database,
1282
+ });
1283
+ return Promise.resolve(databasePath);
1284
+ } catch (err) {
1285
+ return Promise.reject(err);
1286
+ }
1287
+ }
1288
+ async createNCConnection(
1289
+ databasePath: string,
1290
+ version: number,
1291
+ ): Promise<SQLiteDBConnection> {
1292
+ try {
1293
+ await this.sqlite.createNCConnection({
1294
+ databasePath,
1295
+ version,
1296
+ });
1297
+ const conn = new SQLiteDBConnection(databasePath, true, this.sqlite);
1298
+ const connName = `RO_${databasePath})`;
1299
+ this._connectionDict.set(connName, conn);
1300
+ return Promise.resolve(conn);
1301
+ } catch (err) {
1302
+ return Promise.reject(err);
1303
+ }
1304
+ }
1305
+ async closeNCConnection(databasePath: string): Promise<void> {
1306
+ try {
1307
+ await this.sqlite.closeNCConnection({ databasePath });
1308
+ const connName = `RO_${databasePath})`;
1309
+ this._connectionDict.delete(connName);
1310
+ return Promise.resolve();
1311
+ } catch (err) {
1312
+ return Promise.reject(err);
1313
+ }
1314
+ }
1315
+ async isNCConnection(databasePath: string): Promise<capSQLiteResult> {
1316
+ const res: capSQLiteResult = {} as capSQLiteResult;
1317
+ const connName = `RO_${databasePath})`;
1318
+ res.result = this._connectionDict.has(connName);
1319
+ return Promise.resolve(res);
1320
+ }
1321
+ async retrieveNCConnection(
1322
+ databasePath: string,
1323
+ ): Promise<SQLiteDBConnection> {
1324
+ if (this._connectionDict.has(databasePath)) {
1325
+ const connName = `RO_${databasePath})`;
1326
+ const conn = this._connectionDict.get(connName);
1327
+ if (typeof conn != 'undefined') return Promise.resolve(conn);
1328
+ else {
1329
+ return Promise.reject(`Connection ${databasePath} is undefined`);
1330
+ }
1331
+ } else {
1332
+ return Promise.reject(`Connection ${databasePath} does not exist`);
1333
+ }
1334
+ }
1335
+ async isNCDatabase(databasePath: string): Promise<capSQLiteResult> {
1336
+ try {
1337
+ const res = await this.sqlite.isNCDatabase({ databasePath });
1338
+ return Promise.resolve(res);
1339
+ } catch (err) {
1340
+ return Promise.reject(err);
1341
+ }
1342
+ }
1343
+
1344
+ async retrieveAllConnections(): Promise<Map<string, SQLiteDBConnection>> {
1345
+ return this._connectionDict;
1346
+ }
1347
+ async closeAllConnections(): Promise<void> {
1348
+ const delDict: Map<string, SQLiteDBConnection | null> = new Map();
1349
+ try {
1350
+ for (const key of this._connectionDict.keys()) {
1351
+ const database = key.substring(3);
1352
+ const readonly = key.substring(0, 3) === 'RO_' ? true : false;
1353
+ await this.sqlite.closeConnection({ database, readonly });
1354
+ delDict.set(key, null);
1355
+ }
1356
+
1357
+ for (const key of delDict.keys()) {
1358
+ this._connectionDict.delete(key);
1359
+ }
1360
+ return Promise.resolve();
1361
+ } catch (err) {
1362
+ return Promise.reject(err);
1363
+ }
1364
+ }
1365
+ async checkConnectionsConsistency(): Promise<capSQLiteResult> {
1366
+ try {
1367
+ const keys = [...this._connectionDict.keys()];
1368
+ const openModes = [];
1369
+ const dbNames = [];
1370
+ for (const key of keys) {
1371
+ openModes.push(key.substring(0, 2));
1372
+ dbNames.push(key.substring(3));
1373
+ }
1374
+ const res: capSQLiteResult =
1375
+ await this.sqlite.checkConnectionsConsistency({
1376
+ dbNames: dbNames,
1377
+ openModes: openModes,
1378
+ });
1379
+ if (!res.result) this._connectionDict = new Map();
1380
+ return Promise.resolve(res);
1381
+ } catch (err) {
1382
+ this._connectionDict = new Map();
1383
+ return Promise.reject(err);
1384
+ }
1385
+ }
1386
+ async importFromJson(jsonstring: string): Promise<capSQLiteChanges> {
1387
+ try {
1388
+ const ret = await this.sqlite.importFromJson({ jsonstring: jsonstring });
1389
+ return Promise.resolve(ret);
1390
+ } catch (err) {
1391
+ return Promise.reject(err);
1392
+ }
1393
+ }
1394
+ async isJsonValid(jsonstring: string): Promise<capSQLiteResult> {
1395
+ try {
1396
+ const ret = await this.sqlite.isJsonValid({ jsonstring: jsonstring });
1397
+ return Promise.resolve(ret);
1398
+ } catch (err) {
1399
+ return Promise.reject(err);
1400
+ }
1401
+ }
1402
+ async copyFromAssets(overwrite?: boolean): Promise<void> {
1403
+ const mOverwrite: boolean = overwrite != null ? overwrite : true;
1404
+
1405
+ try {
1406
+ await this.sqlite.copyFromAssets({ overwrite: mOverwrite });
1407
+ return Promise.resolve();
1408
+ } catch (err) {
1409
+ return Promise.reject(err);
1410
+ }
1411
+ }
1412
+ async getFromHTTPRequest(url: string, overwrite?: boolean): Promise<void> {
1413
+ const mOverwrite: boolean = overwrite != null ? overwrite : true;
1414
+ try {
1415
+ await this.sqlite.getFromHTTPRequest({ url, overwrite: mOverwrite });
1416
+ return Promise.resolve();
1417
+ } catch (err) {
1418
+ return Promise.reject(err);
1419
+ }
1420
+ }
1421
+ async isDatabase(database: string): Promise<capSQLiteResult> {
1422
+ if (database.endsWith('.db')) database = database.slice(0, -3);
1423
+ try {
1424
+ const res = await this.sqlite.isDatabase({ database: database });
1425
+ return Promise.resolve(res);
1426
+ } catch (err) {
1427
+ return Promise.reject(err);
1428
+ }
1429
+ }
1430
+ async getDatabaseList(): Promise<capSQLiteValues> {
1431
+ try {
1432
+ const res = await this.sqlite.getDatabaseList();
1433
+ return Promise.resolve(res);
1434
+ } catch (err) {
1435
+ return Promise.reject(err);
1436
+ }
1437
+ }
1438
+ async getMigratableDbList(folderPath: string): Promise<capSQLiteValues> {
1439
+ if (!folderPath || folderPath.length === 0) {
1440
+ return Promise.reject('You must provide a folder path');
1441
+ }
1442
+ try {
1443
+ const res = await this.sqlite.getMigratableDbList({
1444
+ folderPath: folderPath,
1445
+ });
1446
+ return Promise.resolve(res);
1447
+ } catch (err) {
1448
+ return Promise.reject(err);
1449
+ }
1450
+ }
1451
+ async addSQLiteSuffix(
1452
+ folderPath?: string,
1453
+ dbNameList?: string[],
1454
+ ): Promise<void> {
1455
+ const path: string = folderPath ? folderPath : 'default';
1456
+ const dbList: string[] = dbNameList ? dbNameList : [];
1457
+ try {
1458
+ const res = await this.sqlite.addSQLiteSuffix({
1459
+ folderPath: path,
1460
+ dbNameList: dbList,
1461
+ });
1462
+ return Promise.resolve(res);
1463
+ } catch (err) {
1464
+ return Promise.reject(err);
1465
+ }
1466
+ }
1467
+ async deleteOldDatabases(
1468
+ folderPath?: string,
1469
+ dbNameList?: string[],
1470
+ ): Promise<void> {
1471
+ const path: string = folderPath ? folderPath : 'default';
1472
+ const dbList: string[] = dbNameList ? dbNameList : [];
1473
+ try {
1474
+ const res = await this.sqlite.deleteOldDatabases({
1475
+ folderPath: path,
1476
+ dbNameList: dbList,
1477
+ });
1478
+ return Promise.resolve(res);
1479
+ } catch (err) {
1480
+ return Promise.reject(err);
1481
+ }
1482
+ }
1483
+
1484
+ async moveDatabasesAndAddSuffix(
1485
+ folderPath?: string,
1486
+ dbNameList?: string[],
1487
+ ): Promise<void> {
1488
+ const path: string = folderPath ? folderPath : 'default';
1489
+ const dbList: string[] = dbNameList ? dbNameList : [];
1490
+ return this.sqlite.moveDatabasesAndAddSuffix({
1491
+ folderPath: path,
1492
+ dbNameList: dbList,
1493
+ });
1494
+ }
1495
+ }
1496
+
1497
+ /**
1498
+ * SQLiteDBConnection Interface
1499
+ */
1500
+ export interface ISQLiteDBConnection {
1501
+ /**
1502
+ * Get SQLite DB Connection DB name
1503
+ * @returns string
1504
+ * @since 2.9.0 refactor
1505
+ */
1506
+ getConnectionDBName(): string;
1507
+
1508
+ /**
1509
+ * Get SQLite DB Connection read-only mode
1510
+ * @returns boolean
1511
+ * @since 4.1.0
1512
+ */
1513
+ getConnectionReadOnly(): boolean;
1514
+
1515
+ /**
1516
+ * Open a SQLite DB Connection
1517
+ * @returns Promise<void>
1518
+ * @since 2.9.0 refactor
1519
+ */
1520
+ open(): Promise<void>;
1521
+ /**
1522
+ * Close a SQLite DB Connection
1523
+ * @returns Promise<void>
1524
+ * @since 2.9.0 refactor
1525
+ */
1526
+ close(): Promise<void>;
1527
+ /**
1528
+ * Get Database Url
1529
+ * @returns Promise<capSQLiteUrl>
1530
+ * @since 3.3.3-4
1531
+ */
1532
+ getUrl(): Promise<capSQLiteUrl>;
1533
+ /**
1534
+ * Get the a SQLite DB Version
1535
+ * @returns Promise<capVersionResult>
1536
+ * @since 3.2.0
1537
+ */
1538
+ getVersion(): Promise<capVersionResult>;
1539
+ /**
1540
+ * Execute SQLite DB Connection Statements
1541
+ * @param statements
1542
+ * @returns Promise<capSQLiteChanges>
1543
+ * @since 2.9.0 refactor
1544
+ */
1545
+ execute(statements: string, transaction?: boolean): Promise<capSQLiteChanges>;
1546
+ /**
1547
+ * Execute SQLite DB Connection Query
1548
+ * @param statement
1549
+ * @param values (optional)
1550
+ * @returns Promise<Promise<DBSQLiteValues>
1551
+ * @since 2.9.0 refactor
1552
+ */
1553
+ query(statement: string, values?: any[]): Promise<DBSQLiteValues>;
1554
+ /**
1555
+ * Execute SQLite DB Connection Raw Statement
1556
+ * @param statement
1557
+ * @param values (optional)
1558
+ * @returns Promise<capSQLiteChanges>
1559
+ * @since 2.9.0 refactor
1560
+ */
1561
+ run(
1562
+ statement: string,
1563
+ values?: any[],
1564
+ transaction?: boolean,
1565
+ ): Promise<capSQLiteChanges>;
1566
+ /**
1567
+ * Execute SQLite DB Connection Set
1568
+ * @param set
1569
+ * @returns Promise<capSQLiteChanges>
1570
+ * @since 2.9.0 refactor
1571
+ */
1572
+ executeSet(
1573
+ set: capSQLiteSet[],
1574
+ transaction?: boolean,
1575
+ ): Promise<capSQLiteChanges>;
1576
+ /**
1577
+ * Check if a SQLite DB Connection exists
1578
+ * @returns Promise<capSQLiteResult>
1579
+ * @since 2.9.0 refactor
1580
+ */
1581
+ isExists(): Promise<capSQLiteResult>;
1582
+ /**
1583
+ * Check if a SQLite database is opened
1584
+ * @returns Promise<capSQLiteResult>
1585
+ * @since 3.0.0-beta.5
1586
+ */
1587
+ isDBOpen(): Promise<capSQLiteResult>;
1588
+ /**
1589
+ * Check if a table exists
1590
+ * @returns Promise<capSQLiteResult>
1591
+ * @since 3.0.0-beta.5
1592
+ */
1593
+ isTable(table: string): Promise<capSQLiteResult>;
1594
+ /**
1595
+ * Get database's table list
1596
+ * @since 3.4.2-3
1597
+ */
1598
+ getTableList(): Promise<DBSQLiteValues>;
1599
+ /**
1600
+ * Delete a SQLite DB Connection
1601
+ * @returns Promise<void>
1602
+ * @since 2.9.0 refactor
1603
+ */
1604
+ delete(): Promise<void>;
1605
+ /**
1606
+ * Create a synchronization table
1607
+ * @returns Promise<capSQLiteChanges>
1608
+ * @since 2.9.0 refactor
1609
+ */
1610
+ createSyncTable(): Promise<capSQLiteChanges>;
1611
+ /**
1612
+ * Set the synchronization date
1613
+ * @param syncdate
1614
+ * @returns Promise<void>
1615
+ * @since 2.9.0 refactor
1616
+ */
1617
+ setSyncDate(syncdate: string): Promise<void>;
1618
+ /**
1619
+ * Get the synchronization date
1620
+ * @returns Promise<capSQLiteSyncDate>
1621
+ * @since 2.9.0 refactor
1622
+ */
1623
+ getSyncDate(): Promise<string>;
1624
+ /**
1625
+ * Export the given database to a JSON Object
1626
+ * @param mode
1627
+ * @returns Promise<capSQLiteJson>
1628
+ * @since 2.9.0 refactor
1629
+ */
1630
+ exportToJson(mode: string): Promise<capSQLiteJson>;
1631
+ /**
1632
+ * Remove rows with sql_deleted = 1 after an export
1633
+ * @returns Promise<void>
1634
+ * @since 3.4.3-2
1635
+ */
1636
+ deleteExportedRows(): Promise<void>;
1637
+
1638
+ /**
1639
+ *
1640
+ * @param txn
1641
+ * @returns Promise<void>
1642
+ * @since 3.4.0
1643
+ */
1644
+ executeTransaction(
1645
+ txn: { statement: string; values?: any[] }[],
1646
+ ): Promise<void>;
1647
+ }
1648
+ /**
1649
+ * SQLiteDBConnection Class
1650
+ */
1651
+ export class SQLiteDBConnection implements ISQLiteDBConnection {
1652
+ constructor(
1653
+ private dbName: string,
1654
+ private readonly: boolean,
1655
+ private sqlite: any,
1656
+ ) {}
1657
+
1658
+ getConnectionDBName(): string {
1659
+ return this.dbName;
1660
+ }
1661
+ getConnectionReadOnly(): boolean {
1662
+ return this.readonly;
1663
+ }
1664
+
1665
+ async open(): Promise<void> {
1666
+ try {
1667
+ await this.sqlite.open({
1668
+ database: this.dbName,
1669
+ readonly: this.readonly,
1670
+ });
1671
+ return Promise.resolve();
1672
+ } catch (err) {
1673
+ return Promise.reject(err);
1674
+ }
1675
+ }
1676
+ async close(): Promise<void> {
1677
+ try {
1678
+ await this.sqlite.close({
1679
+ database: this.dbName,
1680
+ readonly: this.readonly,
1681
+ });
1682
+ return Promise.resolve();
1683
+ } catch (err) {
1684
+ return Promise.reject(err);
1685
+ }
1686
+ }
1687
+ async getUrl(): Promise<capSQLiteUrl> {
1688
+ try {
1689
+ const res: capSQLiteUrl = await this.sqlite.getUrl({
1690
+ database: this.dbName,
1691
+ readonly: this.readonly,
1692
+ });
1693
+ return Promise.resolve(res);
1694
+ } catch (err) {
1695
+ return Promise.reject(err);
1696
+ }
1697
+ }
1698
+ async getVersion(): Promise<capVersionResult> {
1699
+ try {
1700
+ const version: capVersionResult = await this.sqlite.getVersion({
1701
+ database: this.dbName,
1702
+ readonly: this.readonly,
1703
+ });
1704
+ return Promise.resolve(version);
1705
+ } catch (err) {
1706
+ return Promise.reject(err);
1707
+ }
1708
+ }
1709
+ async getTableList(): Promise<DBSQLiteValues> {
1710
+ try {
1711
+ const res: any = await this.sqlite.getTableList({
1712
+ database: this.dbName,
1713
+ readonly: this.readonly,
1714
+ });
1715
+ return Promise.resolve(res);
1716
+ } catch (err) {
1717
+ return Promise.reject(err);
1718
+ }
1719
+ }
1720
+ async execute(
1721
+ statements: string,
1722
+ transaction = true,
1723
+ ): Promise<capSQLiteChanges> {
1724
+ try {
1725
+ if (!this.readonly) {
1726
+ const res: any = await this.sqlite.execute({
1727
+ database: this.dbName,
1728
+ statements: statements,
1729
+ transaction: transaction,
1730
+ readonly: false,
1731
+ });
1732
+ return Promise.resolve(res);
1733
+ } else {
1734
+ return Promise.reject('not allowed in read-only mode');
1735
+ }
1736
+ } catch (err) {
1737
+ return Promise.reject(err);
1738
+ }
1739
+ }
1740
+ async query(statement: string, values?: any[]): Promise<DBSQLiteValues> {
1741
+ let res: any;
1742
+ try {
1743
+ if (values && values.length > 0) {
1744
+ res = await this.sqlite.query({
1745
+ database: this.dbName,
1746
+ statement: statement,
1747
+ values: values,
1748
+ readonly: this.readonly,
1749
+ });
1750
+ } else {
1751
+ res = await this.sqlite.query({
1752
+ database: this.dbName,
1753
+ statement: statement,
1754
+ values: [],
1755
+ readonly: this.readonly,
1756
+ });
1757
+ }
1758
+ if (res && typeof res.values[0] === 'object') {
1759
+ if (Object.keys(res.values[0]).includes('ios_columns')) {
1760
+ const columnList: string[] = res.values[0]['ios_columns'];
1761
+ const iosRes: any[] = [];
1762
+ for (let i = 1; i < res.values.length; i++) {
1763
+ const rowJson: any = res.values[i];
1764
+ const resRowJson: any = {};
1765
+ for (const item of columnList) {
1766
+ resRowJson[item] = rowJson[item];
1767
+ }
1768
+ iosRes.push(resRowJson);
1769
+ }
1770
+ res = {};
1771
+ res['values'] = iosRes;
1772
+ }
1773
+ }
1774
+ return Promise.resolve(res);
1775
+ } catch (err) {
1776
+ return Promise.reject(err);
1777
+ }
1778
+ }
1779
+ async run(
1780
+ statement: string,
1781
+ values?: any[],
1782
+ transaction = true,
1783
+ ): Promise<capSQLiteChanges> {
1784
+ let res: any;
1785
+ try {
1786
+ if (!this.readonly) {
1787
+ if (values && values.length > 0) {
1788
+ res = await this.sqlite.run({
1789
+ database: this.dbName,
1790
+ statement: statement,
1791
+ values: values,
1792
+ transaction: transaction,
1793
+ readonly: false,
1794
+ });
1795
+ // }
1796
+ } else {
1797
+ res = await this.sqlite.run({
1798
+ database: this.dbName,
1799
+ statement: statement,
1800
+ values: [],
1801
+ transaction: transaction,
1802
+ readonly: false,
1803
+ });
1804
+ }
1805
+ return Promise.resolve(res);
1806
+ } else {
1807
+ return Promise.reject('not allowed in read-only mode');
1808
+ }
1809
+ } catch (err) {
1810
+ return Promise.reject(err);
1811
+ }
1812
+ }
1813
+ async executeSet(
1814
+ set: capSQLiteSet[],
1815
+ transaction = true,
1816
+ ): Promise<capSQLiteChanges> {
1817
+ try {
1818
+ if (!this.readonly) {
1819
+ const res: any = await this.sqlite.executeSet({
1820
+ database: this.dbName,
1821
+ set: set,
1822
+ transaction: transaction,
1823
+ readonly: false,
1824
+ });
1825
+ // }
1826
+ return Promise.resolve(res);
1827
+ } else {
1828
+ return Promise.reject('not allowed in read-only mode');
1829
+ }
1830
+ } catch (err) {
1831
+ return Promise.reject(err);
1832
+ }
1833
+ }
1834
+ async isExists(): Promise<capSQLiteResult> {
1835
+ try {
1836
+ const res: any = await this.sqlite.isDBExists({
1837
+ database: this.dbName,
1838
+ readonly: this.readonly,
1839
+ });
1840
+ return Promise.resolve(res);
1841
+ } catch (err) {
1842
+ return Promise.reject(err);
1843
+ }
1844
+ }
1845
+ async isTable(table: string): Promise<capSQLiteResult> {
1846
+ try {
1847
+ const res: capSQLiteResult = await this.sqlite.isTableExists({
1848
+ database: this.dbName,
1849
+ table: table,
1850
+ readonly: this.readonly,
1851
+ });
1852
+ return Promise.resolve(res);
1853
+ } catch (err) {
1854
+ return Promise.reject(err);
1855
+ }
1856
+ }
1857
+ async isDBOpen(): Promise<capSQLiteResult> {
1858
+ try {
1859
+ const res: capSQLiteResult = await this.sqlite.isDBOpen({
1860
+ database: this.dbName,
1861
+ readonly: this.readonly,
1862
+ });
1863
+ return Promise.resolve(res);
1864
+ } catch (err) {
1865
+ return Promise.reject(err);
1866
+ }
1867
+ }
1868
+ async delete(): Promise<void> {
1869
+ try {
1870
+ if (!this.readonly) {
1871
+ await this.sqlite.deleteDatabase({
1872
+ database: this.dbName,
1873
+ readonly: false,
1874
+ });
1875
+ return Promise.resolve();
1876
+ } else {
1877
+ return Promise.reject('not allowed in read-only mode');
1878
+ }
1879
+ } catch (err) {
1880
+ return Promise.reject(err);
1881
+ }
1882
+ }
1883
+ async createSyncTable(): Promise<capSQLiteChanges> {
1884
+ try {
1885
+ if (!this.readonly) {
1886
+ const res: any = await this.sqlite.createSyncTable({
1887
+ database: this.dbName,
1888
+ readonly: false,
1889
+ });
1890
+ return Promise.resolve(res);
1891
+ } else {
1892
+ return Promise.reject('not allowed in read-only mode');
1893
+ }
1894
+ } catch (err) {
1895
+ return Promise.reject(err);
1896
+ }
1897
+ }
1898
+ async setSyncDate(syncdate: string): Promise<void> {
1899
+ try {
1900
+ if (!this.readonly) {
1901
+ await this.sqlite.setSyncDate({
1902
+ database: this.dbName,
1903
+ syncdate: syncdate,
1904
+ readonly: false,
1905
+ });
1906
+ return Promise.resolve();
1907
+ } else {
1908
+ return Promise.reject('not allowed in read-only mode');
1909
+ }
1910
+ } catch (err) {
1911
+ return Promise.reject(err);
1912
+ }
1913
+ }
1914
+ async getSyncDate(): Promise<string> {
1915
+ try {
1916
+ const res: any = await this.sqlite.getSyncDate({
1917
+ database: this.dbName,
1918
+ readonly: this.readonly,
1919
+ });
1920
+ let retDate = '';
1921
+ if (res.syncDate > 0)
1922
+ retDate = new Date(res.syncDate * 1000).toISOString();
1923
+ return Promise.resolve(retDate);
1924
+ } catch (err) {
1925
+ return Promise.reject(err);
1926
+ }
1927
+ }
1928
+ async exportToJson(mode: string): Promise<capSQLiteJson> {
1929
+ try {
1930
+ const res: any = await this.sqlite.exportToJson({
1931
+ database: this.dbName,
1932
+ jsonexportmode: mode,
1933
+ readonly: this.readonly,
1934
+ });
1935
+ return Promise.resolve(res);
1936
+ } catch (err) {
1937
+ return Promise.reject(err);
1938
+ }
1939
+ }
1940
+ async deleteExportedRows(): Promise<void> {
1941
+ try {
1942
+ if (!this.readonly) {
1943
+ await this.sqlite.deleteExportedRows({
1944
+ database: this.dbName,
1945
+ readonly: false,
1946
+ });
1947
+ return Promise.resolve();
1948
+ } else {
1949
+ return Promise.reject('not allowed in read-only mode');
1950
+ }
1951
+ } catch (err) {
1952
+ return Promise.reject(err);
1953
+ }
1954
+ }
1955
+
1956
+ async executeTransaction(
1957
+ txn: { statement: string; values?: any[] }[],
1958
+ ): Promise<void> {
1959
+ try {
1960
+ if (!this.readonly) {
1961
+ const ret = await this.sqlite.execute({
1962
+ database: this.dbName,
1963
+ statements: 'BEGIN TRANSACTION;',
1964
+ transaction: false,
1965
+ });
1966
+ if (ret.changes.changes < 0) {
1967
+ return Promise.reject('Error in BEGIN TRANSACTION');
1968
+ }
1969
+ for (const task of txn) {
1970
+ if (task.values && task.values.length > 0) {
1971
+ const ret = await this.sqlite.run({
1972
+ database: this.dbName,
1973
+ statement: task.statement,
1974
+ values: task.values,
1975
+ transaction: false,
1976
+ readonly: false,
1977
+ });
1978
+ if (ret.changes.lastId === -1) {
1979
+ await this.execute('ROLLBACK;', false);
1980
+ return Promise.reject('Error in transaction run ');
1981
+ }
1982
+ } else {
1983
+ const ret = await this.sqlite.execute({
1984
+ database: this.dbName,
1985
+ statements: task.statement,
1986
+ transaction: false,
1987
+ readonly: false,
1988
+ });
1989
+ if (ret.changes.changes < 0) {
1990
+ await this.sqlite.execute({
1991
+ database: this.dbName,
1992
+ statements: 'ROLLBACK;',
1993
+ transaction: false,
1994
+ readonly: false,
1995
+ });
1996
+ return Promise.reject('Error in transaction execute ');
1997
+ }
1998
+ }
1999
+ }
2000
+ await this.sqlite.execute({
2001
+ database: this.dbName,
2002
+ statements: 'COMMIT;',
2003
+ transaction: false,
2004
+ readonly: false,
2005
+ });
2006
+ return Promise.resolve();
2007
+ } else {
2008
+ return Promise.reject('not allowed in read-only mode');
2009
+ }
2010
+ } catch (err: any) {
2011
+ await this.sqlite.execute({
2012
+ database: this.dbName,
2013
+ statements: 'ROLLBACK;',
2014
+ transaction: false,
2015
+ readonly: false,
2016
+ });
2017
+ return Promise.reject(err);
2018
+ }
2019
+ }
2020
+ }