@capacitor-community/sqlite 4.0.0-0 → 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.
@@ -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) {
@@ -16,7 +16,6 @@ extension String {
16
16
  searchStartIndex = self.index(self.startIndex, offsetBy: fIdx)
17
17
  }
18
18
  }
19
-
20
19
 
21
20
  while searchStartIndex < self.endIndex,
22
21
  let range = self.range(of: string, options: .caseInsensitive, range: searchStartIndex..<self.endIndex),
@@ -149,7 +149,7 @@ class UtilsFile {
149
149
  dbPathURL = try UtilsFile.getApplicationURL().absoluteURL
150
150
  } else if first[0] == "Library" {
151
151
  dbPathURL = try UtilsFile.getLibraryURL().absoluteURL
152
- } else if first[0].caseInsensitiveCompare("cache") == .orderedSame {
152
+ } else if first[0].caseInsensitiveCompare("cache") == .orderedSame {
153
153
  dbPathURL = try UtilsFile.getCacheURL().absoluteURL
154
154
  } else if first[0] == "Documents" || first[0] == "default" {
155
155
  dbPathURL = databaseURL
@@ -241,7 +241,7 @@ class UtilsFile {
241
241
  throw UtilsFileError.getApplicationPathFailed
242
242
  }
243
243
  }
244
-
244
+
245
245
  // MARK: - getCacheURL
246
246
 
247
247
  class func getCacheURL() 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": "4.0.0-0",
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",