@capacitor-community/sqlite 3.3.3-1 → 3.3.3-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.
- package/CHANGELOG.md +17 -0
- package/README.md +20 -2
- package/ios/Plugin/CapacitorSQLite.swift +37 -11
- package/ios/Plugin/CapacitorSQLitePlugin.swift +133 -72
- package/ios/Plugin/Database.swift +23 -11
- package/ios/Plugin/SqliteConfig.swift +10 -0
- package/ios/Plugin/Utils/UtilsEncryption.swift +10 -7
- package/ios/Plugin/Utils/UtilsFile.swift +195 -33
- package/ios/Plugin/Utils/UtilsMigrate.swift +11 -44
- package/ios/Plugin/Utils/UtilsNCDatabase.swift +2 -2
- package/ios/Plugin/Utils/UtilsSQLCipher.swift +29 -24
- package/ios/Plugin/Utils/UtilsSecret.swift +22 -8
- package/ios/Plugin/Utils/UtilsUpgrade.swift +6 -2
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
|
+
## 3.3.3-2 (2022-01-03)
|
|
2
|
+
|
|
3
|
+
### Added Features
|
|
4
|
+
|
|
5
|
+
- iOS Support for databases that are not visible to iTunes and are not backed up by iCloud issue#207
|
|
6
|
+
|
|
7
|
+
### Bug Fixes
|
|
8
|
+
|
|
9
|
+
- fix README.md
|
|
10
|
+
- fix API.md
|
|
11
|
+
|
|
1
12
|
## 3.3.3-1 (2021-12-18)
|
|
2
13
|
|
|
14
|
+
### Chore
|
|
15
|
+
|
|
16
|
+
- Update to @capacitor/core 3.3.3
|
|
17
|
+
- Update to @capacitor/ios 3.3.3
|
|
18
|
+
- Update to @capacitor/android 3.3.3
|
|
19
|
+
|
|
3
20
|
### Added Features
|
|
4
21
|
|
|
5
22
|
- Open in Read-Only Mode databases without SQLite suffix
|
package/README.md
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
<a href="https://www.npmjs.com/package/@capacitor-community/sqlite"><img src="https://img.shields.io/npm/dw/@capacitor-community/sqlite?style=flat-square" /></a>
|
|
17
17
|
<a href="https://www.npmjs.com/package/@capacitor-community/sqlite"><img src="https://img.shields.io/npm/v/@capacitor-community/sqlite?style=flat-square" /></a>
|
|
18
18
|
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
|
|
19
|
-
<a href="#contributors-"><img src="https://img.shields.io/badge/all%20contributors-
|
|
19
|
+
<a href="#contributors-"><img src="https://img.shields.io/badge/all%20contributors-10-orange?style=flat-square" /></a>
|
|
20
20
|
<!-- ALL-CONTRIBUTORS-BADGE:END -->
|
|
21
21
|
</p>
|
|
22
22
|
|
|
@@ -28,6 +28,23 @@
|
|
|
28
28
|
|
|
29
29
|
## CAPACITOR 3 (Master)
|
|
30
30
|
|
|
31
|
+
🚨 Since release 3.3.3-2 ->> 🚨
|
|
32
|
+
|
|
33
|
+
- iOS only
|
|
34
|
+
Support for a database location not visible to iTunes and backed up to iCloud.
|
|
35
|
+
For this you must add to the `const config: CapacitorConfig` of the `capacitor.config.ts` file of your application the following:
|
|
36
|
+
```ts
|
|
37
|
+
plugins: {
|
|
38
|
+
CapacitorSQLite: {
|
|
39
|
+
"iosDatabaseLocation": "Library/CapacitorDatabase"
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
```
|
|
43
|
+
Pre-existing databases from the `Documents` folder will be moved to the new folder `Library/CapacitorDatabase` and your application will work as before.
|
|
44
|
+
If you do not modify the `capacitor.config.ts` file of your application the databases will still reside in the `Documents` folder
|
|
45
|
+
|
|
46
|
+
🚨 Since release 3.3.3-2 <<- 🚨
|
|
47
|
+
|
|
31
48
|
🚨 Since release 3.2.5-2 ->> 🚨
|
|
32
49
|
|
|
33
50
|
- support zip file in copyFromAssets method
|
|
@@ -308,7 +325,8 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
|
|
|
308
325
|
<td align="center"><a href="https://github.com/digaus"><img src="https://avatars.githubusercontent.com/u/15358538?v=4" width="100px;" alt=""/><br /><sub><b>Dirk Gausmann</b></sub></a><br /><a href="https://github.com/capacitor-community/sqlite/commits?author=jepiqueau" title="Code">💻</a></td>
|
|
309
326
|
<td align="center"><a href="https://github.com/IT-MikeS"><img src="https://avatars.githubusercontent.com/u/20338451?v=4" width="100px;" alt=""/><br /><sub><b>Mike Summerfeldt</b></sub></a><br /><a href="https://github.com/capacitor-community/sqlite/commits?author=jepiqueau" title="Code">💻</a></td>
|
|
310
327
|
<td align="center"><a href="https://github.com/peakcool"><img src="https://avatars.githubusercontent.com/u/14804014?v=4" width="100px;" alt=""/><br /><sub><b>Peakcool</b></sub></a><br /><a href="https://github.com/capacitor-community/sqlite/commits?author=jepiqueau" title="Code">💻</a></td>
|
|
311
|
-
<td align="center"><a href="https://github.com/gion-andri"><img src="https://avatars.githubusercontent.com/u/540998?v=4" width="100px;" alt=""/><br /><sub><b>Gion-Andri Cantieni</b></sub></a><br /><a href="https://github.com/capacitor-community/sqlite/commits?author=jepiqueau" title="Documentation"
|
|
328
|
+
<td align="center"><a href="https://github.com/gion-andri"><img src="https://avatars.githubusercontent.com/u/540998?v=4" width="100px;" alt=""/><br /><sub><b>Gion-Andri Cantieni</b></sub></a><br /><a href="https://github.com/capacitor-community/sqlite/commits?author=jepiqueau" title="Documentation">📖</a></td>
|
|
329
|
+
<td align="center"><a href="https://github.com/robingenz"><img src="https://avatars.githubusercontent.com/u/13857929?v=4" width="100px;" alt=""/><br /><sub><b>Robin Genz</b></sub></a><br /><a href="https://github.com/capacitor-community/sqlite/commits?author=jepiqueau" title="Documentation">📖</a></td>
|
|
312
330
|
</tr>
|
|
313
331
|
</table>
|
|
314
332
|
|
|
@@ -5,7 +5,19 @@ enum CapacitorSQLiteError: Error {
|
|
|
5
5
|
// swiftlint:disable file_length
|
|
6
6
|
// swiftlint:disable type_body_length
|
|
7
7
|
@objc public class CapacitorSQLite: NSObject {
|
|
8
|
+
private var config: SqliteConfig
|
|
8
9
|
private var dbDict: [String: Database] = [:]
|
|
10
|
+
private var databaseLocation: String
|
|
11
|
+
|
|
12
|
+
init(config: SqliteConfig) {
|
|
13
|
+
self.config = config
|
|
14
|
+
if let isLocation = config.iosDatabaseLocation {
|
|
15
|
+
self.databaseLocation = isLocation
|
|
16
|
+
} else {
|
|
17
|
+
self.databaseLocation = "Documents"
|
|
18
|
+
}
|
|
19
|
+
super.init()
|
|
20
|
+
}
|
|
9
21
|
|
|
10
22
|
// MARK: - Echo
|
|
11
23
|
|
|
@@ -31,7 +43,9 @@ enum CapacitorSQLiteError: Error {
|
|
|
31
43
|
// close all connections
|
|
32
44
|
try closeAllConnections()
|
|
33
45
|
// set encryption secret
|
|
34
|
-
try UtilsSecret
|
|
46
|
+
try UtilsSecret
|
|
47
|
+
.setEncryptionSecret(passphrase: passphrase,
|
|
48
|
+
databaseLocation: databaseLocation)
|
|
35
49
|
return
|
|
36
50
|
} catch UtilsSecretError.setEncryptionSecret(let message) {
|
|
37
51
|
throw CapacitorSQLiteError.failed(message: message)
|
|
@@ -48,7 +62,10 @@ enum CapacitorSQLiteError: Error {
|
|
|
48
62
|
// close all connections
|
|
49
63
|
try closeAllConnections()
|
|
50
64
|
// set encryption secret
|
|
51
|
-
try UtilsSecret
|
|
65
|
+
try UtilsSecret
|
|
66
|
+
.changeEncryptionSecret(passphrase: passphrase,
|
|
67
|
+
oldPassphrase: oldPassphrase,
|
|
68
|
+
databaseLocation: databaseLocation)
|
|
52
69
|
return
|
|
53
70
|
} catch UtilsSecretError.changeEncryptionSecret(let message) {
|
|
54
71
|
throw CapacitorSQLiteError.failed(message: message)
|
|
@@ -91,6 +108,7 @@ enum CapacitorSQLiteError: Error {
|
|
|
91
108
|
throw CapacitorSQLiteError.failed(message: "database \(databasePath) does not exist")
|
|
92
109
|
}
|
|
93
110
|
let mDb: Database = try Database(
|
|
111
|
+
databaseLocation: databaseLocation,
|
|
94
112
|
databaseName: databasePath,
|
|
95
113
|
encrypted: false, mode: "no-encryption", version: version,
|
|
96
114
|
vUpgDict: [:])
|
|
@@ -136,6 +154,7 @@ enum CapacitorSQLiteError: Error {
|
|
|
136
154
|
|
|
137
155
|
do {
|
|
138
156
|
let mDb: Database = try Database(
|
|
157
|
+
databaseLocation: databaseLocation,
|
|
139
158
|
databaseName: "\(mDbName)SQLite.db",
|
|
140
159
|
encrypted: encrypted, mode: mode, version: version,
|
|
141
160
|
vUpgDict: vUpgDict)
|
|
@@ -261,7 +280,8 @@ enum CapacitorSQLiteError: Error {
|
|
|
261
280
|
@objc public func isDatabase(_ dbName: String) throws -> NSNumber {
|
|
262
281
|
let mDbName = CapacitorSQLite.getDatabaseName(dbName: dbName)
|
|
263
282
|
let isFileExists: Bool = UtilsFile
|
|
264
|
-
.isFileExist(
|
|
283
|
+
.isFileExist(databaseLocation: databaseLocation,
|
|
284
|
+
fileName: mDbName + "SQLite.db")
|
|
265
285
|
if isFileExists {
|
|
266
286
|
return 1
|
|
267
287
|
} else {
|
|
@@ -459,7 +479,8 @@ enum CapacitorSQLiteError: Error {
|
|
|
459
479
|
throw CapacitorSQLiteError.failed(message: msg)
|
|
460
480
|
}
|
|
461
481
|
let res: Bool = UtilsFile
|
|
462
|
-
.isFileExist(
|
|
482
|
+
.isFileExist(databaseLocation: databaseLocation,
|
|
483
|
+
fileName: "\(mDbName)SQLite.db")
|
|
463
484
|
if res {
|
|
464
485
|
return 1
|
|
465
486
|
} else {
|
|
@@ -496,8 +517,7 @@ enum CapacitorSQLiteError: Error {
|
|
|
496
517
|
if !mDb.isDBOpen() {
|
|
497
518
|
try mDb.open()
|
|
498
519
|
}
|
|
499
|
-
let res: Bool = try mDb.deleteDB(
|
|
500
|
-
databaseName: "\(mDbName)SQLite.db")
|
|
520
|
+
let res: Bool = try mDb.deleteDB(databaseName: "\(mDbName)SQLite.db")
|
|
501
521
|
if res {
|
|
502
522
|
return
|
|
503
523
|
} else {
|
|
@@ -558,6 +578,7 @@ enum CapacitorSQLiteError: Error {
|
|
|
558
578
|
// open the database
|
|
559
579
|
do {
|
|
560
580
|
mDb = try Database(
|
|
581
|
+
databaseLocation: databaseLocation,
|
|
561
582
|
databaseName: dbName, encrypted: encrypted,
|
|
562
583
|
mode: inMode, version: version, vUpgDict: [:])
|
|
563
584
|
try mDb.open()
|
|
@@ -760,7 +781,7 @@ enum CapacitorSQLiteError: Error {
|
|
|
760
781
|
let aPath: String = assetsDbPath.path
|
|
761
782
|
let bRes: Bool = UtilsFile.isDirExist(dirPath: aPath)
|
|
762
783
|
if bRes {
|
|
763
|
-
// get the database files
|
|
784
|
+
// get the database files from assets
|
|
764
785
|
let dbList: [String] = try UtilsFile
|
|
765
786
|
.getFileList(path: aPath, ext: ".db")
|
|
766
787
|
// loop through the database files
|
|
@@ -772,7 +793,8 @@ enum CapacitorSQLiteError: Error {
|
|
|
772
793
|
// for each copy the file to the Application
|
|
773
794
|
// database folder
|
|
774
795
|
_ = try UtilsFile
|
|
775
|
-
.copyFromAssetToDatabase(
|
|
796
|
+
.copyFromAssetToDatabase(databaseLocation: databaseLocation,
|
|
797
|
+
fromDb: mDb,
|
|
776
798
|
toDb: toDb, overwrite: overwrite)
|
|
777
799
|
}
|
|
778
800
|
// get the zip files
|
|
@@ -783,7 +805,8 @@ enum CapacitorSQLiteError: Error {
|
|
|
783
805
|
// for each zip uncompress the file to the Application
|
|
784
806
|
// database folder
|
|
785
807
|
_ = try UtilsFile
|
|
786
|
-
.unzipFromAssetToDatabase(
|
|
808
|
+
.unzipFromAssetToDatabase(databaseLocation: databaseLocation,
|
|
809
|
+
zip: zip, overwrite: overwrite)
|
|
787
810
|
}
|
|
788
811
|
return
|
|
789
812
|
} else {
|
|
@@ -840,7 +863,9 @@ enum CapacitorSQLiteError: Error {
|
|
|
840
863
|
@objc func addSQLiteSuffix(_ folderPath: String, dbList: [String]) throws {
|
|
841
864
|
|
|
842
865
|
do {
|
|
843
|
-
try UtilsMigrate.addSQLiteSuffix(
|
|
866
|
+
try UtilsMigrate.addSQLiteSuffix(databaseLocation: databaseLocation,
|
|
867
|
+
folderPath: folderPath,
|
|
868
|
+
dbList: dbList)
|
|
844
869
|
return
|
|
845
870
|
} catch UtilsMigrateError.addSQLiteSuffix(let message) {
|
|
846
871
|
var msg: String = "addSQLiteSuffix:"
|
|
@@ -858,7 +883,8 @@ enum CapacitorSQLiteError: Error {
|
|
|
858
883
|
|
|
859
884
|
@objc func deleteOldDatabases(_ folderPath: String, dbList: [String]) throws {
|
|
860
885
|
do {
|
|
861
|
-
try UtilsMigrate
|
|
886
|
+
try UtilsMigrate
|
|
887
|
+
.deleteOldDatabases(folderPath: folderPath, dbList: dbList)
|
|
862
888
|
return
|
|
863
889
|
} catch UtilsMigrateError.deleteOldDatabases(let message) {
|
|
864
890
|
var msg: String = "deleteOldDatabases:"
|