@capacitor-community/sqlite 3.5.2 → 4.0.0-1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CapacitorCommunitySqlite.podspec +1 -1
- package/README.md +21 -1
- package/android/build.gradle +14 -11
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/CapacitorSQLite.java +15 -0
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/CapacitorSQLitePlugin.java +34 -0
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/Database.java +1 -1
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/UtilsMigrate.java +50 -3
- package/dist/esm/definitions.d.ts +14 -0
- package/dist/esm/definitions.js +8 -0
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/web.d.ts +1 -0
- package/dist/esm/web.js +4 -0
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +12 -0
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +12 -0
- package/dist/plugin.js.map +1 -1
- package/electron/dist/plugin.js +10 -3
- package/electron/dist/plugin.js.map +1 -1
- package/ios/Plugin/CapacitorSQLite.swift +26 -0
- package/ios/Plugin/CapacitorSQLitePlugin.m +1 -0
- package/ios/Plugin/CapacitorSQLitePlugin.swift +29 -0
- package/ios/Plugin/Extensions/String.swift +0 -1
- package/ios/Plugin/Utils/UtilsFile.swift +16 -0
- package/ios/Plugin/Utils/UtilsMigrate.swift +72 -0
- package/package.json +8 -8
|
@@ -1341,6 +1341,32 @@ enum CapacitorSQLiteError: Error {
|
|
|
1341
1341
|
throw CapacitorSQLiteError.failed(message: initMessage)
|
|
1342
1342
|
}
|
|
1343
1343
|
}
|
|
1344
|
+
|
|
1345
|
+
// MARK: - moveDatabasesAndAddSuffix
|
|
1346
|
+
|
|
1347
|
+
@objc func moveDatabasesAndAddSuffix(_ folderPath: String, dbList: [String]) throws {
|
|
1348
|
+
if isInit {
|
|
1349
|
+
do {
|
|
1350
|
+
try UtilsMigrate
|
|
1351
|
+
.moveDatabasesAndAddSuffix(databaseLocation: databaseLocation,
|
|
1352
|
+
folderPath: folderPath,
|
|
1353
|
+
dbList: dbList)
|
|
1354
|
+
return
|
|
1355
|
+
} catch UtilsMigrateError.moveDatabasesAndAddSuffix(let message) {
|
|
1356
|
+
var msg: String = "moveDatabasesAndAddSuffix:"
|
|
1357
|
+
msg.append(" \(message)")
|
|
1358
|
+
throw CapacitorSQLiteError.failed(message: msg)
|
|
1359
|
+
|
|
1360
|
+
} catch let error {
|
|
1361
|
+
var msg: String = "moveDatabasesAndAddSuffix:"
|
|
1362
|
+
msg.append(" \(error)")
|
|
1363
|
+
throw CapacitorSQLiteError.failed(message: msg)
|
|
1364
|
+
}
|
|
1365
|
+
} else {
|
|
1366
|
+
throw CapacitorSQLiteError.failed(message: initMessage)
|
|
1367
|
+
}
|
|
1368
|
+
}
|
|
1369
|
+
|
|
1344
1370
|
class func getDatabaseName(dbName: String) -> String {
|
|
1345
1371
|
var retName: String = dbName
|
|
1346
1372
|
if !retName.contains("/") {
|
|
@@ -38,6 +38,7 @@ CAP_PLUGIN(CapacitorSQLitePlugin, "CapacitorSQLite",
|
|
|
38
38
|
CAP_PLUGIN_METHOD(getMigratableDbList, CAPPluginReturnPromise);
|
|
39
39
|
CAP_PLUGIN_METHOD(addSQLiteSuffix, CAPPluginReturnPromise);
|
|
40
40
|
CAP_PLUGIN_METHOD(deleteOldDatabases, CAPPluginReturnPromise);
|
|
41
|
+
CAP_PLUGIN_METHOD(moveDatabasesAndAddSuffix, CAPPluginReturnPromise);
|
|
41
42
|
CAP_PLUGIN_METHOD(checkConnectionsConsistency, CAPPluginReturnPromise);
|
|
42
43
|
CAP_PLUGIN_METHOD(isSecretStored, CAPPluginReturnPromise);
|
|
43
44
|
CAP_PLUGIN_METHOD(setEncryptionSecret, CAPPluginReturnPromise);
|
|
@@ -549,6 +549,35 @@ public class CapacitorSQLitePlugin: CAPPlugin {
|
|
|
549
549
|
}
|
|
550
550
|
}
|
|
551
551
|
|
|
552
|
+
// MARK: - moveDatabasesAndAddSuffix
|
|
553
|
+
|
|
554
|
+
@objc func moveDatabasesAndAddSuffix(_ call: CAPPluginCall) {
|
|
555
|
+
let folderPath: String = call.getString("folderPath") ?? "default"
|
|
556
|
+
let dbJsList: JSArray = call.getArray("dbNameList") ?? []
|
|
557
|
+
var dbList: [String] = []
|
|
558
|
+
if dbJsList.count > 0 {
|
|
559
|
+
for dbName in dbJsList {
|
|
560
|
+
if let name = dbName as? String {
|
|
561
|
+
dbList.append(name)
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
do {
|
|
566
|
+
try implementation?.moveDatabasesAndAddSuffix(folderPath, dbList: dbList)
|
|
567
|
+
retHandler.rResult(call: call)
|
|
568
|
+
return
|
|
569
|
+
} catch CapacitorSQLiteError.failed(let message) {
|
|
570
|
+
let msg = "moveDatabasesAndAddSuffix: \(message)"
|
|
571
|
+
retHandler.rResult(call: call, message: msg)
|
|
572
|
+
return
|
|
573
|
+
} catch let error {
|
|
574
|
+
retHandler.rResult(
|
|
575
|
+
call: call,
|
|
576
|
+
message: "moveDatabasesAndAddSuffix: \(error)")
|
|
577
|
+
return
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
|
|
552
581
|
// MARK: - Execute
|
|
553
582
|
|
|
554
583
|
@objc func execute(_ call: CAPPluginCall) {
|
|
@@ -20,6 +20,7 @@ enum UtilsFileError: Error {
|
|
|
20
20
|
case getDatabasesURLFailed
|
|
21
21
|
case getApplicationPathFailed
|
|
22
22
|
case getApplicationURLFailed
|
|
23
|
+
case getCacheURLFailed
|
|
23
24
|
case getLibraryPathFailed
|
|
24
25
|
case getLibraryURLFailed
|
|
25
26
|
case getFileListFailed
|
|
@@ -148,6 +149,8 @@ class UtilsFile {
|
|
|
148
149
|
dbPathURL = try UtilsFile.getApplicationURL().absoluteURL
|
|
149
150
|
} else if first[0] == "Library" {
|
|
150
151
|
dbPathURL = try UtilsFile.getLibraryURL().absoluteURL
|
|
152
|
+
} else if first[0].caseInsensitiveCompare("cache") == .orderedSame {
|
|
153
|
+
dbPathURL = try UtilsFile.getCacheURL().absoluteURL
|
|
151
154
|
} else if first[0] == "Documents" || first[0] == "default" {
|
|
152
155
|
dbPathURL = databaseURL
|
|
153
156
|
} else {
|
|
@@ -239,6 +242,19 @@ class UtilsFile {
|
|
|
239
242
|
}
|
|
240
243
|
}
|
|
241
244
|
|
|
245
|
+
// MARK: - getCacheURL
|
|
246
|
+
|
|
247
|
+
class func getCacheURL() throws -> URL {
|
|
248
|
+
if let path: String = NSSearchPathForDirectoriesInDomains(
|
|
249
|
+
.cachesDirectory, .userDomainMask, true
|
|
250
|
+
).first {
|
|
251
|
+
return NSURL(fileURLWithPath: path) as URL
|
|
252
|
+
} else {
|
|
253
|
+
print("Error: getCacheURL did not find the cache folder")
|
|
254
|
+
throw UtilsFileError.getCacheURLFailed
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
242
258
|
// MARK: - getLibraryURL
|
|
243
259
|
|
|
244
260
|
class func getLibraryURL() throws -> URL {
|
|
@@ -9,6 +9,7 @@ enum UtilsMigrateError: Error {
|
|
|
9
9
|
case addSQLiteSuffix(message: String)
|
|
10
10
|
case getMigratableList(message: String)
|
|
11
11
|
case deleteOldDatabases(message: String)
|
|
12
|
+
case moveDatabasesAndAddSuffix(message: String)
|
|
12
13
|
}
|
|
13
14
|
|
|
14
15
|
class UtilsMigrate {
|
|
@@ -192,4 +193,75 @@ class UtilsMigrate {
|
|
|
192
193
|
// swiftlint:enable cyclomatic_complexity
|
|
193
194
|
// swiftlint:enable function_body_length
|
|
194
195
|
|
|
196
|
+
// MARK: - moveDatabasesAndAddSuffix
|
|
197
|
+
|
|
198
|
+
// swiftlint:disable function_body_length
|
|
199
|
+
// swiftlint:disable cyclomatic_complexity
|
|
200
|
+
class func moveDatabasesAndAddSuffix(databaseLocation: String, folderPath: String,
|
|
201
|
+
dbList: [String]) throws {
|
|
202
|
+
var fromFile: String = ""
|
|
203
|
+
var toFile: String = ""
|
|
204
|
+
do {
|
|
205
|
+
let databaseURL: URL = try UtilsFile
|
|
206
|
+
.getFolderURL(folderPath: databaseLocation)
|
|
207
|
+
let dbPathURL: URL = try UtilsFile
|
|
208
|
+
.getFolderURL(folderPath: folderPath)
|
|
209
|
+
var isDir = ObjCBool(true)
|
|
210
|
+
if FileManager.default.fileExists(atPath: dbPathURL.relativePath,
|
|
211
|
+
isDirectory: &isDir) &&
|
|
212
|
+
isDir.boolValue {
|
|
213
|
+
var mDbList: [String]
|
|
214
|
+
if dbList.count > 0 {
|
|
215
|
+
mDbList = try UtilsFile
|
|
216
|
+
.getFileList(path: dbPathURL.relativePath, ext: nil)
|
|
217
|
+
} else {
|
|
218
|
+
mDbList = try UtilsFile
|
|
219
|
+
.getFileList(path: dbPathURL.relativePath, ext: "db")
|
|
220
|
+
}
|
|
221
|
+
for file: String in mDbList {
|
|
222
|
+
if !file.contains("SQLite.db") {
|
|
223
|
+
fromFile = file
|
|
224
|
+
toFile = ""
|
|
225
|
+
if dbList.count > 0 {
|
|
226
|
+
if dbList.contains(fromFile) {
|
|
227
|
+
if String(file.suffix(3)) == ".db" {
|
|
228
|
+
toFile = file
|
|
229
|
+
.replacingOccurrences(of: ".db", with: "SQLite.db")
|
|
230
|
+
} else {
|
|
231
|
+
toFile = file + "SQLite.db"
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
} else {
|
|
235
|
+
toFile = file
|
|
236
|
+
.replacingOccurrences(of: ".db", with: "SQLite.db")
|
|
237
|
+
}
|
|
238
|
+
if !toFile.isEmpty {
|
|
239
|
+
let uFrom: URL = dbPathURL.appendingPathComponent(fromFile)
|
|
240
|
+
let uTo: URL = databaseURL.appendingPathComponent(toFile)
|
|
241
|
+
try UtilsFile.moveFile(pathName: uFrom.path, toPathName: uTo.path, overwrite: true)
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
return
|
|
246
|
+
} else {
|
|
247
|
+
var msg: String = "moveDatabasesAndAddSuffix command failed :"
|
|
248
|
+
msg.append(" Folder '\(dbPathURL.absoluteString)' not found")
|
|
249
|
+
throw UtilsMigrateError.moveDatabasesAndAddSuffix(message: msg)
|
|
250
|
+
}
|
|
251
|
+
} catch UtilsFileError.getDatabasesURLFailed {
|
|
252
|
+
throw UtilsMigrateError
|
|
253
|
+
.moveDatabasesAndAddSuffix(message: "getDatabasesURLFailed")
|
|
254
|
+
} catch UtilsFileError.getFolderURLFailed(let message) {
|
|
255
|
+
throw UtilsMigrateError.moveDatabasesAndAddSuffix(message: message)
|
|
256
|
+
} catch UtilsFileError.getFileListFailed {
|
|
257
|
+
throw UtilsMigrateError.moveDatabasesAndAddSuffix(message: "getFileListFailed")
|
|
258
|
+
} catch let error {
|
|
259
|
+
var msg: String = "moveDatabasesAndAddSuffix command failed :"
|
|
260
|
+
msg.append(" \(error.localizedDescription)")
|
|
261
|
+
throw UtilsMigrateError.moveDatabasesAndAddSuffix(message: msg)
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
// swiftlint:enable cyclomatic_complexity
|
|
265
|
+
// swiftlint:enable function_body_length
|
|
266
|
+
|
|
195
267
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@capacitor-community/sqlite",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0-1",
|
|
4
4
|
"description": "Community plugin for native & electron SQLite databases",
|
|
5
5
|
"main": "dist/plugin.cjs.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -55,10 +55,10 @@
|
|
|
55
55
|
"prepublishOnly": "npm run build && npm run build-electron && npm run docgen"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
|
-
"@capacitor/android": "^
|
|
59
|
-
"@capacitor/core": "^
|
|
58
|
+
"@capacitor/android": "^4.0.0",
|
|
59
|
+
"@capacitor/core": "^4.0.0",
|
|
60
60
|
"@capacitor/docgen": "^0.0.17",
|
|
61
|
-
"@capacitor/ios": "^
|
|
61
|
+
"@capacitor/ios": "^4.0.0",
|
|
62
62
|
"@ionic/eslint-config": "^0.3.0",
|
|
63
63
|
"@ionic/prettier-config": "^1.0.1",
|
|
64
64
|
"@ionic/swiftlint-config": "^1.1.2",
|
|
@@ -66,15 +66,15 @@
|
|
|
66
66
|
"@rollup/plugin-node-resolve": "^13.0.4",
|
|
67
67
|
"electron": "^15.5.5",
|
|
68
68
|
"eslint": "^7.11.0",
|
|
69
|
-
"prettier": "~2.
|
|
70
|
-
"prettier-plugin-java": "~1.0.
|
|
69
|
+
"prettier": "~2.3.0",
|
|
70
|
+
"prettier-plugin-java": "~1.0.2",
|
|
71
71
|
"rimraf": "^3.0.2",
|
|
72
72
|
"rollup": "^2.32.0",
|
|
73
73
|
"swiftlint": "^1.0.1",
|
|
74
|
-
"typescript": "~4.
|
|
74
|
+
"typescript": "~4.1.5"
|
|
75
75
|
},
|
|
76
76
|
"peerDependencies": {
|
|
77
|
-
"@capacitor/core": "^
|
|
77
|
+
"@capacitor/core": "^4.0.0"
|
|
78
78
|
},
|
|
79
79
|
"prettier": "@ionic/prettier-config",
|
|
80
80
|
"swiftlint": "@ionic/swiftlint-config",
|