@capacitor-community/sqlite 3.3.3-1 → 3.3.3-5

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.
Files changed (32) hide show
  1. package/CHANGELOG.md +40 -0
  2. package/README.md +22 -2
  3. package/android/src/main/java/com/getcapacitor/community/database/sqlite/CapacitorSQLite.java +22 -0
  4. package/android/src/main/java/com/getcapacitor/community/database/sqlite/CapacitorSQLitePlugin.java +25 -1
  5. package/android/src/main/java/com/getcapacitor/community/database/sqlite/RetHandler.java +25 -1
  6. package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/Database.java +10 -1
  7. package/dist/esm/definitions.d.ts +20 -0
  8. package/dist/esm/definitions.js +11 -0
  9. package/dist/esm/definitions.js.map +1 -1
  10. package/dist/esm/web.d.ts +2 -1
  11. package/dist/esm/web.js +3 -0
  12. package/dist/esm/web.js.map +1 -1
  13. package/dist/plugin.cjs.js +14 -0
  14. package/dist/plugin.cjs.js.map +1 -1
  15. package/dist/plugin.js +14 -0
  16. package/dist/plugin.js.map +1 -1
  17. package/electron/dist/plugin.js +3 -0
  18. package/electron/dist/plugin.js.map +1 -1
  19. package/ios/Plugin/CapacitorSQLite.swift +738 -552
  20. package/ios/Plugin/CapacitorSQLitePlugin.m +1 -0
  21. package/ios/Plugin/CapacitorSQLitePlugin.swift +166 -72
  22. package/ios/Plugin/Database.swift +29 -11
  23. package/ios/Plugin/ReturnHandler.swift +12 -0
  24. package/ios/Plugin/SqliteConfig.swift +10 -0
  25. package/ios/Plugin/Utils/UtilsEncryption.swift +10 -7
  26. package/ios/Plugin/Utils/UtilsFile.swift +194 -33
  27. package/ios/Plugin/Utils/UtilsMigrate.swift +11 -44
  28. package/ios/Plugin/Utils/UtilsNCDatabase.swift +2 -2
  29. package/ios/Plugin/Utils/UtilsSQLCipher.swift +29 -24
  30. package/ios/Plugin/Utils/UtilsSecret.swift +22 -8
  31. package/ios/Plugin/Utils/UtilsUpgrade.swift +6 -2
  32. package/package.json +1 -1
@@ -12,6 +12,7 @@ CAP_PLUGIN(CapacitorSQLitePlugin, "CapacitorSQLite",
12
12
  CAP_PLUGIN_METHOD(getNCDatabasePath, CAPPluginReturnPromise);
13
13
  CAP_PLUGIN_METHOD(open, CAPPluginReturnPromise);
14
14
  CAP_PLUGIN_METHOD(close, CAPPluginReturnPromise);
15
+ CAP_PLUGIN_METHOD(getUrl, CAPPluginReturnPromise);
15
16
  CAP_PLUGIN_METHOD(getVersion, CAPPluginReturnPromise);
16
17
  CAP_PLUGIN_METHOD(execute, CAPPluginReturnPromise);
17
18
  CAP_PLUGIN_METHOD(executeSet, CAPPluginReturnPromise);
@@ -5,7 +5,7 @@ import Capacitor
5
5
  // swiftlint:disable file_length
6
6
  // swiftlint:disable type_body_length
7
7
  public class CapacitorSQLitePlugin: CAPPlugin {
8
- private let implementation = CapacitorSQLite()
8
+ private var implementation: CapacitorSQLite?
9
9
  private let modeList: [String] = ["no-encryption", "encryption", "secret", "newsecret", "wrongsecret"]
10
10
  private let retHandler: ReturnHandler = ReturnHandler()
11
11
  private var versionUpgrades: [String: [Int: [String: Any]]] = [:]
@@ -13,6 +13,7 @@ public class CapacitorSQLitePlugin: CAPPlugin {
13
13
  var exportObserver: Any?
14
14
 
15
15
  override public func load() {
16
+ self.implementation = CapacitorSQLite(config: sqliteConfig())
16
17
  self.addObserversToNotificationCenter()
17
18
  }
18
19
  deinit {
@@ -24,16 +25,18 @@ public class CapacitorSQLitePlugin: CAPPlugin {
24
25
 
25
26
  @objc func echo(_ call: CAPPluginCall) {
26
27
  let value = call.getString("value") ?? ""
27
- call.resolve([
28
- "value": implementation.echo(value)
29
- ])
28
+ if let retValue: String = implementation?.echo(value) {
29
+ call.resolve([
30
+ "value": retValue
31
+ ])
32
+ }
30
33
  }
31
34
 
32
35
  // MARK: - IsSecretStored
33
36
 
34
37
  @objc func isSecretStored(_ call: CAPPluginCall) {
35
38
  do {
36
- let res = try implementation.isSecretStored()
39
+ let res = try implementation?.isSecretStored()
37
40
  var bRes: Bool = false
38
41
  if res == 1 {
39
42
  bRes = true
@@ -64,7 +67,7 @@ public class CapacitorSQLitePlugin: CAPPlugin {
64
67
  return
65
68
  }
66
69
  do {
67
- try implementation.setEncryptionSecret(passphrase: passphrase)
70
+ try implementation?.setEncryptionSecret(passphrase: passphrase)
68
71
  retHandler.rResult(call: call)
69
72
  return
70
73
  } catch CapacitorSQLiteError.failed(let message) {
@@ -96,7 +99,7 @@ public class CapacitorSQLitePlugin: CAPPlugin {
96
99
  return
97
100
  }
98
101
  do {
99
- try implementation.changeEncryptionSecret(passphrase: passphrase, oldPassphrase: oldPassphrase)
102
+ try implementation?.changeEncryptionSecret(passphrase: passphrase, oldPassphrase: oldPassphrase)
100
103
  retHandler.rResult(call: call)
101
104
  return
102
105
  } catch CapacitorSQLiteError.failed(let message) {
@@ -135,11 +138,11 @@ public class CapacitorSQLitePlugin: CAPPlugin {
135
138
  upgDict = cUpgDict
136
139
  }
137
140
  do {
138
- try implementation.createConnection(dbName,
139
- encrypted: encrypted,
140
- mode: inMode,
141
- version: version,
142
- vUpgDict: upgDict)
141
+ try implementation?.createConnection(dbName,
142
+ encrypted: encrypted,
143
+ mode: inMode,
144
+ version: version,
145
+ vUpgDict: upgDict)
143
146
  retHandler.rResult(call: call)
144
147
  return
145
148
  } catch CapacitorSQLiteError.failed(let message) {
@@ -164,7 +167,7 @@ public class CapacitorSQLitePlugin: CAPPlugin {
164
167
  return
165
168
  }
166
169
  do {
167
- try implementation.open(dbName)
170
+ try implementation?.open(dbName)
168
171
  retHandler.rResult(call: call)
169
172
  return
170
173
  } catch CapacitorSQLiteError.failed(let message) {
@@ -189,7 +192,7 @@ public class CapacitorSQLitePlugin: CAPPlugin {
189
192
  return
190
193
  }
191
194
  do {
192
- try implementation.close(dbName)
195
+ try implementation?.close(dbName)
193
196
  retHandler.rResult(call: call)
194
197
  return
195
198
  } catch CapacitorSQLiteError.failed(let message) {
@@ -204,6 +207,39 @@ public class CapacitorSQLitePlugin: CAPPlugin {
204
207
  }
205
208
  }
206
209
 
210
+ // MARK: - GetUrl
211
+
212
+ @objc func getUrl(_ call: CAPPluginCall) {
213
+ guard let dbName = call.options["database"] as? String else {
214
+ retHandler.rResult(
215
+ call: call,
216
+ message: "GetUrl: Must provide a database name")
217
+ return
218
+ }
219
+ do {
220
+ let res: String = try implementation?.getUrl(dbName) ?? ""
221
+ if res.count > 0 {
222
+ retHandler.rUrl(call: call, ret: res)
223
+ return
224
+ } else {
225
+ retHandler.rUrl(
226
+ call: call, ret: "",
227
+ message: "getUrl: No path returned")
228
+ return
229
+ }
230
+ } catch CapacitorSQLiteError.failed(let message) {
231
+ retHandler.rUrl(
232
+ call: call, ret: "",
233
+ message: "getUrl: \(message)")
234
+ return
235
+ } catch let error {
236
+ retHandler.rUrl(
237
+ call: call, ret: "",
238
+ message: "getUrl: \(error)")
239
+ return
240
+ }
241
+ }
242
+
207
243
  // MARK: - getVersion
208
244
 
209
245
  @objc func getVersion(_ call: CAPPluginCall) {
@@ -214,9 +250,15 @@ public class CapacitorSQLitePlugin: CAPPlugin {
214
250
  return
215
251
  }
216
252
  do {
217
- let version: NSNumber = try implementation.getVersion(dbName)
218
- retHandler.rVersion(call: call, ret: version)
219
- return
253
+ if let version: NSNumber = try implementation?
254
+ .getVersion(dbName) {
255
+ retHandler.rVersion(call: call, ret: version)
256
+ return
257
+ } else {
258
+ let msg = "GetVersion: Does not return a valid version"
259
+ retHandler.rVersion(call: call, message: msg)
260
+ return
261
+ }
220
262
  } catch CapacitorSQLiteError.failed(let message) {
221
263
  let msg = "GetVersion: \(message)"
222
264
  retHandler.rVersion(call: call, message: msg)
@@ -239,7 +281,7 @@ public class CapacitorSQLitePlugin: CAPPlugin {
239
281
  return
240
282
  }
241
283
  do {
242
- try implementation.closeConnection(dbName)
284
+ try implementation?.closeConnection(dbName)
243
285
  retHandler.rResult(call: call)
244
286
  return
245
287
  } catch CapacitorSQLiteError.failed(let message) {
@@ -266,7 +308,7 @@ public class CapacitorSQLitePlugin: CAPPlugin {
266
308
  return
267
309
  }
268
310
  do {
269
- let res = try implementation.checkConnectionsConsistency(dbNames)
311
+ let res = try implementation?.checkConnectionsConsistency(dbNames)
270
312
  var bRes: Bool = false
271
313
  if res == 1 {
272
314
  bRes = true
@@ -291,7 +333,7 @@ public class CapacitorSQLitePlugin: CAPPlugin {
291
333
  return
292
334
  }
293
335
  do {
294
- let res = try implementation.isDatabase(dbName)
336
+ let res = try implementation?.isDatabase(dbName)
295
337
  var bRes: Bool = false
296
338
  if res == 1 {
297
339
  bRes = true
@@ -326,7 +368,7 @@ public class CapacitorSQLitePlugin: CAPPlugin {
326
368
  return
327
369
  }
328
370
  do {
329
- let res = try implementation.isTableExists(dbName, tableName: tableName)
371
+ let res = try implementation?.isTableExists(dbName, tableName: tableName)
330
372
  var bRes: Bool = false
331
373
  if res == 1 {
332
374
  bRes = true
@@ -349,7 +391,7 @@ public class CapacitorSQLitePlugin: CAPPlugin {
349
391
  @objc func getDatabaseList(_ call: CAPPluginCall) {
350
392
 
351
393
  do {
352
- let res = try implementation.getDatabaseList()
394
+ let res = try implementation?.getDatabaseList() ?? []
353
395
  retHandler.rValues(call: call, ret: res)
354
396
  return
355
397
  } catch CapacitorSQLiteError.failed(let message) {
@@ -376,7 +418,8 @@ public class CapacitorSQLitePlugin: CAPPlugin {
376
418
  }
377
419
 
378
420
  do {
379
- let res = try implementation.getMigratableDbList(dbFolder)
421
+ let res = try implementation?
422
+ .getMigratableDbList(dbFolder) ?? []
380
423
  retHandler.rValues(call: call, ret: res)
381
424
  return
382
425
  } catch CapacitorSQLiteError.failed(let message) {
@@ -406,7 +449,7 @@ public class CapacitorSQLitePlugin: CAPPlugin {
406
449
  }
407
450
  }
408
451
  do {
409
- try implementation.addSQLiteSuffix(folderPath, dbList: dbList)
452
+ try implementation?.addSQLiteSuffix(folderPath, dbList: dbList)
410
453
  retHandler.rResult(call: call)
411
454
  return
412
455
  } catch CapacitorSQLiteError.failed(let message) {
@@ -435,7 +478,7 @@ public class CapacitorSQLitePlugin: CAPPlugin {
435
478
  }
436
479
  }
437
480
  do {
438
- try implementation.deleteOldDatabases(folderPath, dbList: dbList)
481
+ try implementation?.deleteOldDatabases(folderPath, dbList: dbList)
439
482
  retHandler.rResult(call: call)
440
483
  return
441
484
  } catch CapacitorSQLiteError.failed(let message) {
@@ -470,10 +513,17 @@ public class CapacitorSQLitePlugin: CAPPlugin {
470
513
  return
471
514
  }
472
515
  do {
473
- let res = try implementation.execute(dbName, statements: statements,
474
- transaction: transaction)
475
- retHandler.rChanges(call: call, ret: res)
476
- return
516
+ if let res = try implementation?
517
+ .execute(dbName, statements: statements,
518
+ transaction: transaction) {
519
+ retHandler.rChanges(call: call, ret: res)
520
+ return
521
+ } else {
522
+ retHandler.rChanges(
523
+ call: call, ret: ["changes": -1],
524
+ message: "Execute: Does not return a valid execute")
525
+ return
526
+ }
477
527
  } catch CapacitorSQLiteError.failed(let message) {
478
528
  retHandler.rChanges(
479
529
  call: call, ret: ["changes": -1],
@@ -526,10 +576,17 @@ public class CapacitorSQLitePlugin: CAPPlugin {
526
576
  }
527
577
  let transaction: Bool = call.getBool("transaction") ?? true
528
578
  do {
529
- let res = try implementation.executeSet(dbName, set: set,
530
- transaction: transaction)
531
- retHandler.rChanges(call: call, ret: res)
532
- return
579
+ if let res = try implementation?.executeSet(dbName, set: set,
580
+ transaction: transaction) {
581
+ retHandler.rChanges(call: call, ret: res)
582
+ return
583
+ } else {
584
+ retHandler.rChanges(
585
+ call: call, ret: ["changes": -1],
586
+ message: "ExecuteSet: Does not return a valid executeSet")
587
+ return
588
+
589
+ }
533
590
  } catch CapacitorSQLiteError.failed(let message) {
534
591
  retHandler.rChanges(
535
592
  call: call, ret: ["changes": -1],
@@ -547,6 +604,7 @@ public class CapacitorSQLitePlugin: CAPPlugin {
547
604
 
548
605
  // MARK: - Run
549
606
 
607
+ // swiftlint:disable function_body_length
550
608
  @objc func run(_ call: CAPPluginCall) {
551
609
  guard let dbName = call.options["database"] as? String else {
552
610
  retHandler.rChanges(
@@ -572,13 +630,19 @@ public class CapacitorSQLitePlugin: CAPPlugin {
572
630
  }
573
631
  let transaction: Bool = call.getBool("transaction") ?? true
574
632
  do {
575
- let res = try
576
- implementation.run(dbName,
577
- statement: statement,
578
- values: values,
579
- transaction: transaction)
580
- retHandler.rChanges(call: call, ret: res)
581
- return
633
+ if let res = try
634
+ implementation?.run(dbName,
635
+ statement: statement,
636
+ values: values,
637
+ transaction: transaction) {
638
+ retHandler.rChanges(call: call, ret: res)
639
+ return
640
+ } else {
641
+ retHandler.rChanges(
642
+ call: call, ret: ["changes": -1],
643
+ message: "Run: Does not return a valid run")
644
+ return
645
+ }
582
646
  } catch CapacitorSQLiteError.failed(let message) {
583
647
  retHandler.rChanges(
584
648
  call: call, ret: ["changes": -1],
@@ -592,9 +656,11 @@ public class CapacitorSQLitePlugin: CAPPlugin {
592
656
  }
593
657
 
594
658
  }
659
+ // swiftlint:enable function_body_length
595
660
 
596
661
  // MARK: - Query
597
662
 
663
+ // swiftlint:disable function_body_length
598
664
  @objc func query(_ call: CAPPluginCall) {
599
665
  guard let dbName = call.options["database"]
600
666
  as? String else {
@@ -622,12 +688,19 @@ public class CapacitorSQLitePlugin: CAPPlugin {
622
688
 
623
689
  }
624
690
  do {
625
- let res = try
626
- implementation.query(dbName,
627
- statement: statement,
628
- values: values)
629
- retHandler.rValues(call: call, ret: res)
630
- return
691
+ if let res = try
692
+ implementation?.query(dbName,
693
+ statement: statement,
694
+ values: values) {
695
+ retHandler.rValues(call: call, ret: res)
696
+ return
697
+ } else {
698
+ retHandler.rValues(
699
+ call: call, ret: [],
700
+ message: "Query: Does not return a valid query")
701
+ return
702
+
703
+ }
631
704
  } catch CapacitorSQLiteError.failed(let message) {
632
705
  retHandler.rValues(
633
706
  call: call, ret: [],
@@ -641,6 +714,7 @@ public class CapacitorSQLitePlugin: CAPPlugin {
641
714
  }
642
715
 
643
716
  }
717
+ // swiftlint:enable function_body_length
644
718
 
645
719
  // MARK: - isDBExists
646
720
 
@@ -653,7 +727,7 @@ public class CapacitorSQLitePlugin: CAPPlugin {
653
727
  return
654
728
  }
655
729
  do {
656
- let res = try implementation.isDBExists(dbName)
730
+ let res = try implementation?.isDBExists(dbName)
657
731
  var bRes: Bool = false
658
732
  if res == 1 {
659
733
  bRes = true
@@ -683,7 +757,7 @@ public class CapacitorSQLitePlugin: CAPPlugin {
683
757
  return
684
758
  }
685
759
  do {
686
- let res = try implementation.isDBOpen(dbName)
760
+ let res = try implementation?.isDBOpen(dbName)
687
761
  var bRes: Bool = false
688
762
  if res == 1 {
689
763
  bRes = true
@@ -712,7 +786,7 @@ public class CapacitorSQLitePlugin: CAPPlugin {
712
786
  return
713
787
  }
714
788
  do {
715
- try implementation.deleteDatabase(dbName)
789
+ try implementation?.deleteDatabase(dbName)
716
790
  retHandler.rResult(call: call)
717
791
  return
718
792
  } catch CapacitorSQLiteError.failed(let message) {
@@ -737,7 +811,7 @@ public class CapacitorSQLitePlugin: CAPPlugin {
737
811
  return
738
812
  }
739
813
  do {
740
- try implementation.isJsonValid(parsingData)
814
+ try implementation?.isJsonValid(parsingData)
741
815
  retHandler.rResult(call: call, ret: true)
742
816
  return
743
817
  } catch CapacitorSQLiteError.failed(let message) {
@@ -762,7 +836,8 @@ public class CapacitorSQLitePlugin: CAPPlugin {
762
836
  return
763
837
  }
764
838
  do {
765
- let res: [String: Int] = try implementation.importFromJson(parsingData)
839
+ let res: [String: Int] = try implementation?
840
+ .importFromJson(parsingData) ?? ["changes": -1]
766
841
  retHandler.rChanges(call: call, ret: res)
767
842
  return
768
843
  } catch CapacitorSQLiteError.failed(let message) {
@@ -808,8 +883,8 @@ public class CapacitorSQLitePlugin: CAPPlugin {
808
883
  }
809
884
 
810
885
  do {
811
- let res: [String: Any] = try implementation
812
- .exportToJson(dbName, expMode: expMode)
886
+ let res: [String: Any] = try implementation?
887
+ .exportToJson(dbName, expMode: expMode) ?? [:]
813
888
  retHandler.rJsonSQLite(call: call, ret: res)
814
889
  return
815
890
  } catch CapacitorSQLiteError.failed(let message) {
@@ -837,8 +912,8 @@ public class CapacitorSQLitePlugin: CAPPlugin {
837
912
  return
838
913
  }
839
914
  do {
840
- let res: NSNumber = try implementation
841
- .createSyncTable(dbName)
915
+ let res: NSNumber = try implementation?
916
+ .createSyncTable(dbName) ?? -1
842
917
  retHandler.rChanges(call: call,
843
918
  ret: ["changes": Int(truncating: res)])
844
919
  return
@@ -872,7 +947,7 @@ public class CapacitorSQLitePlugin: CAPPlugin {
872
947
  return
873
948
  }
874
949
  do {
875
- try implementation.setSyncDate( dbName, syncDate: syncDate)
950
+ try implementation?.setSyncDate( dbName, syncDate: syncDate)
876
951
  retHandler.rResult(call: call)
877
952
  return
878
953
  } catch CapacitorSQLiteError.failed(let message) {
@@ -896,7 +971,7 @@ public class CapacitorSQLitePlugin: CAPPlugin {
896
971
  return
897
972
  }
898
973
  do {
899
- let res: NSNumber = try implementation.getSyncDate( dbName)
974
+ let res: NSNumber = try implementation?.getSyncDate( dbName) ?? 0
900
975
  retHandler.rSyncDate(call: call,
901
976
  ret: Int64(truncating: res))
902
977
  return
@@ -928,12 +1003,17 @@ public class CapacitorSQLitePlugin: CAPPlugin {
928
1003
  return
929
1004
  }
930
1005
  do {
931
- let upgVersionDict: [Int: [String: Any]] = try
932
- implementation.addUpgradeStatement(dbName,
933
- upgrade: upgrade)
934
- versionUpgrades = ["\(dbName)": upgVersionDict]
935
- retHandler.rResult(call: call)
936
- return
1006
+ if let upgVersionDict: [Int: [String: Any]] = try
1007
+ implementation?.addUpgradeStatement(dbName,
1008
+ upgrade: upgrade) {
1009
+ versionUpgrades = ["\(dbName)": upgVersionDict]
1010
+ retHandler.rResult(call: call)
1011
+ return
1012
+ } else {
1013
+ let msg = "addUpgradeStatement: Error in returned upgVersionDict"
1014
+ retHandler.rResult(call: call, message: msg)
1015
+ return
1016
+ }
937
1017
  } catch CapacitorSQLiteError.failed(let message) {
938
1018
  let msg = "addUpgradeStatement: \(message)"
939
1019
  retHandler.rResult(call: call, message: msg)
@@ -952,7 +1032,7 @@ public class CapacitorSQLitePlugin: CAPPlugin {
952
1032
  let overwrite: Bool = call.getBool("overwrite") ?? true
953
1033
 
954
1034
  do {
955
- try implementation.copyFromAssets(overwrite: overwrite)
1035
+ try implementation?.copyFromAssets(overwrite: overwrite)
956
1036
  retHandler.rResult(call: call)
957
1037
  return
958
1038
  } catch CapacitorSQLiteError.failed(let message) {
@@ -981,10 +1061,16 @@ public class CapacitorSQLitePlugin: CAPPlugin {
981
1061
  }
982
1062
  do {
983
1063
 
984
- let path: String = try implementation.getNCDatabasePath(folderPath,
985
- dbName: dbName)
986
- retHandler.rPath(call: call, ret: path)
987
- return
1064
+ if let path: String = try implementation?
1065
+ .getNCDatabasePath(folderPath, dbName: dbName) {
1066
+ retHandler.rPath(call: call, ret: path)
1067
+ return
1068
+ } else {
1069
+ let msg = "getNCDatabasePath: Does not return a NC path"
1070
+ retHandler.rPath(call: call, ret: "", message: msg)
1071
+ return
1072
+
1073
+ }
988
1074
  } catch CapacitorSQLiteError.failed(let message) {
989
1075
  let msg = "getNCDatabasePath: \(message)"
990
1076
  retHandler.rPath(call: call, ret: "", message: msg)
@@ -1007,8 +1093,8 @@ public class CapacitorSQLitePlugin: CAPPlugin {
1007
1093
  }
1008
1094
  let version: Int = call.getInt("version") ?? 1
1009
1095
  do {
1010
- try implementation.createNCConnection(dbPath,
1011
- version: version)
1096
+ try implementation?.createNCConnection(dbPath,
1097
+ version: version)
1012
1098
  retHandler.rResult(call: call)
1013
1099
  return
1014
1100
  } catch CapacitorSQLiteError.failed(let message) {
@@ -1033,7 +1119,7 @@ public class CapacitorSQLitePlugin: CAPPlugin {
1033
1119
  return
1034
1120
  }
1035
1121
  do {
1036
- try implementation.closeNCConnection(dbPath)
1122
+ try implementation?.closeNCConnection(dbPath)
1037
1123
  retHandler.rResult(call: call)
1038
1124
  return
1039
1125
  } catch CapacitorSQLiteError.failed(let message) {
@@ -1058,7 +1144,7 @@ public class CapacitorSQLitePlugin: CAPPlugin {
1058
1144
  return
1059
1145
  }
1060
1146
  do {
1061
- let res = try implementation.isNCDatabase(dbPath)
1147
+ let res = try implementation?.isNCDatabase(dbPath)
1062
1148
  var bRes: Bool = false
1063
1149
  if res == 1 {
1064
1150
  bRes = true
@@ -1103,6 +1189,14 @@ public class CapacitorSQLitePlugin: CAPPlugin {
1103
1189
  return
1104
1190
  }
1105
1191
  }
1192
+ private func sqliteConfig() -> SqliteConfig {
1193
+ var config = SqliteConfig()
1194
+
1195
+ if let iosDatabaseLocation = getConfigValue("iosDatabaseLocation") as? String {
1196
+ config.iosDatabaseLocation = iosDatabaseLocation
1197
+ }
1198
+ return config
1199
+ }
1106
1200
 
1107
1201
  }
1108
1202
  // swiftlint:enable type_body_length
@@ -33,6 +33,7 @@ class Database {
33
33
  var encrypted: Bool
34
34
  var mode: String
35
35
  var vUpgDict: [Int: [String: Any]]
36
+ var databaseLocation: String
36
37
  var path: String = ""
37
38
  var mDb: OpaquePointer?
38
39
  let globalData: GlobalSQLite = GlobalSQLite()
@@ -41,15 +42,15 @@ class Database {
41
42
  var ncDB: Bool = false
42
43
 
43
44
  // MARK: - Init
44
- init(databaseName: String, encrypted: Bool,
45
+ init(databaseLocation: String, databaseName: String, encrypted: Bool,
45
46
  mode: String, version: Int,
46
47
  vUpgDict: [Int: [String: Any]] = [:]) throws {
47
- print("databaseName: \(databaseName) ")
48
48
  self.dbVersion = version
49
49
  self.encrypted = encrypted
50
50
  self.dbName = databaseName
51
51
  self.mode = mode
52
52
  self.vUpgDict = vUpgDict
53
+ self.databaseLocation = databaseLocation
53
54
  if databaseName.contains("/") &&
54
55
  databaseName.suffix(9) != "SQLite.db" {
55
56
  self.readOnly = true
@@ -58,6 +59,7 @@ class Database {
58
59
  } else {
59
60
  do {
60
61
  self.path = try UtilsFile.getFilePath(
62
+ databaseLocation: databaseLocation,
61
63
  fileName: databaseName)
62
64
  } catch UtilsFileError.getFilePathFailed {
63
65
  throw DatabaseError.filePath(
@@ -79,6 +81,12 @@ class Database {
79
81
  return ncDB
80
82
  }
81
83
 
84
+ // MARK: - getUrl
85
+
86
+ func getUrl () -> String {
87
+ return "file://\(path)"
88
+ }
89
+
82
90
  // MARK: - Open
83
91
 
84
92
  // swiftlint:disable cyclomatic_complexity
@@ -91,7 +99,8 @@ class Database {
91
99
  if mode == "encryption" {
92
100
  do {
93
101
  let ret: Bool = try UtilsEncryption
94
- .encryptDatabase(filePath: path, password: password)
102
+ .encryptDatabase(databaseLocation: databaseLocation,
103
+ filePath: path, password: password)
95
104
  if !ret {
96
105
  let msg: String = "Failed in encryption"
97
106
  throw DatabaseError.open(message: msg)
@@ -122,11 +131,15 @@ class Database {
122
131
  }
123
132
  if dbVersion > curVersion {
124
133
  if vUpgDict.count > 0 {
125
- _ = try uUpg.onUpgrade(mDB: self, upgDict: vUpgDict,
126
- dbName: dbName,
127
- currentVersion: curVersion,
128
- targetVersion: dbVersion)
129
- try UtilsSQLCipher.deleteBackupDB(databaseName: dbName)
134
+ _ = try uUpg
135
+ .onUpgrade(mDB: self, upgDict: vUpgDict,
136
+ dbName: dbName,
137
+ currentVersion: curVersion,
138
+ targetVersion: dbVersion,
139
+ databaseLocation: databaseLocation)
140
+ try UtilsSQLCipher
141
+ .deleteBackupDB(databaseLocation: databaseLocation,
142
+ databaseName: dbName)
130
143
  } else {
131
144
  try UtilsSQLCipher.setVersion(mDB: self, version: dbVersion)
132
145
  }
@@ -157,7 +170,9 @@ class Database {
157
170
  } catch UtilsUpgradeError.onUpgradeFailed(let message) {
158
171
  //restore the database
159
172
  do {
160
- try UtilsSQLCipher.restoreDB(databaseName: dbName)
173
+ try UtilsSQLCipher
174
+ .restoreDB(databaseLocation: databaseLocation,
175
+ databaseName: dbName)
161
176
  let msg: String = "Failed OnUpgrade \(message)"
162
177
  try close()
163
178
  throw DatabaseError.open(message: msg)
@@ -227,6 +242,7 @@ class Database {
227
242
  do {
228
243
  try UtilsSQLCipher.execute(mDB: self, sql: sql)
229
244
  changes = UtilsSQLCipher.dbChanges(mDB: mDb) - initChanges
245
+
230
246
  } catch UtilsSQLCipherError.execute(let message) {
231
247
  if transaction {
232
248
  do {
@@ -378,7 +394,8 @@ class Database {
378
394
 
379
395
  func deleteDB(databaseName: String) throws -> Bool {
380
396
  let isFileExists: Bool = UtilsFile
381
- .isFileExist(fileName: databaseName)
397
+ .isFileExist(databaseLocation: databaseLocation,
398
+ fileName: databaseName)
382
399
  if isFileExists && !isOpen {
383
400
  // open the database
384
401
  do {
@@ -396,7 +413,8 @@ class Database {
396
413
  // delete the database
397
414
  if isFileExists {
398
415
  do {
399
- try UtilsSQLCipher.deleteDB(databaseName: databaseName)
416
+ try UtilsSQLCipher.deleteDB(databaseLocation: databaseLocation,
417
+ databaseName: databaseName)
400
418
  } catch UtilsSQLCipherError.deleteDB(let message ) {
401
419
  throw DatabaseError.deleteDB(message: message)
402
420
  }
@@ -106,4 +106,16 @@ class ReturnHandler {
106
106
  return
107
107
  }
108
108
  }
109
+ // MARK: - rUrl
110
+
111
+ func rUrl(call: CAPPluginCall, ret: String,
112
+ message: String? = nil) {
113
+ if let intMessage = message {
114
+ call.reject(intMessage)
115
+ return
116
+ } else {
117
+ call.resolve(["url": ret])
118
+ return
119
+ }
120
+ }
109
121
  }
@@ -0,0 +1,10 @@
1
+ //
2
+ // config.swift
3
+ // CapacitorCommunitySqlite
4
+ //
5
+ // Created by Quéau Jean Pierre on 01/01/2022.
6
+ //
7
+
8
+ public struct SqliteConfig {
9
+ var iosDatabaseLocation: String?
10
+ }