@capacitor-community/sqlite 4.6.1 → 4.6.2-2

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