@capacitor-community/sqlite 3.3.3-4 → 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.
@@ -84,7 +84,7 @@ class Database {
84
84
  // MARK: - getUrl
85
85
 
86
86
  func getUrl () -> String {
87
- return path
87
+ return "file://\(path)"
88
88
  }
89
89
 
90
90
  // MARK: - Open
@@ -29,24 +29,17 @@ enum UtilsFileError: Error {
29
29
  case getFolderURLFailed(message: String)
30
30
  case createDirFailed(message: String)
31
31
  case moveAllDBSQLiteFailed(message: String)
32
+ case createDatabaseLocationFailed(message: String)
32
33
  }
33
34
  // swiftlint:disable file_length
34
35
  // swiftlint:disable type_body_length
35
36
  class UtilsFile {
36
37
 
37
- // MARK: - IsFileExist
38
-
39
- class func isDirExist(dirPath: String) -> Bool {
40
- var isDir: ObjCBool = true
41
- let fileManager = FileManager.default
42
- let exists = fileManager.fileExists(atPath: dirPath, isDirectory: &isDir)
43
- return exists && isDir.boolValue
44
- }
45
-
46
- class func createDirCopyDB(url: URL) throws {
38
+ class func createDatabaseLocation(location: String) throws {
47
39
  do {
48
- var dirUrl = url
49
- let dirPath: String = url.path
40
+ var dirUrl: URL = try UtilsFile
41
+ .getFolderURL(folderPath: location)
42
+ let dirPath: String = dirUrl.path
50
43
  if !UtilsFile.isDirExist(dirPath: dirPath) {
51
44
  // create the directory
52
45
  try FileManager.default
@@ -54,20 +47,31 @@ class UtilsFile {
54
47
  // exclude the directory from iCloud Backup
55
48
  try UtilsFile.setExcludeFromiCloudBackup(&dirUrl,
56
49
  isExcluded: true)
57
- // move all SQLite database from Documents folder
58
- // to this new directory
59
- try UtilsFile.moveAllDBSQLite(dirUrl: dirUrl)
50
+ // move all existing dbs from "Documents" to location folder
51
+ if location.prefix(9) != "Documents" &&
52
+ location.prefix(7) != "default" {
53
+
54
+ try UtilsFile.moveAllDBSQLite(dirUrl: dirUrl)
55
+ }
60
56
  }
61
57
  } catch UtilsFileError.getFolderURLFailed(let message) {
62
- throw UtilsFileError.createDirFailed(message: message)
58
+ throw UtilsFileError.createDatabaseLocationFailed(message: message)
63
59
  } catch UtilsFileError.moveAllDBSQLiteFailed(let message) {
64
- throw UtilsFileError.createDirFailed(message: message)
60
+ throw UtilsFileError.createDatabaseLocationFailed(message: message)
65
61
  } catch let error {
66
- var msg: String = "createDir command failed :"
62
+ var msg: String = "CreateDatabaseLocation command failed :"
67
63
  msg.append(" \(error.localizedDescription)")
68
- throw UtilsFileError.createDirFailed(message: msg)
64
+ throw UtilsFileError.createDatabaseLocationFailed(message: msg)
69
65
  }
66
+ }
70
67
 
68
+ // MARK: - IsFileExist
69
+
70
+ class func isDirExist(dirPath: String) -> Bool {
71
+ var isDir: ObjCBool = true
72
+ let fileManager = FileManager.default
73
+ let exists = fileManager.fileExists(atPath: dirPath, isDirectory: &isDir)
74
+ return exists && isDir.boolValue
71
75
  }
72
76
 
73
77
  // MARK: - moveAllDBSQLite
@@ -175,11 +179,6 @@ class UtilsFile {
175
179
  do {
176
180
  let url: URL = try UtilsFile
177
181
  .getFolderURL(folderPath: databaseLocation)
178
- if databaseLocation.prefix(9) != "Documents" &&
179
- databaseLocation.prefix(7) != "default" {
180
- // create the directories if they do not exists
181
- try UtilsFile.createDirCopyDB(url: url)
182
- }
183
182
  let dbPath: String = url
184
183
  .appendingPathComponent("\(fileName)").path
185
184
  return dbPath
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capacitor-community/sqlite",
3
- "version": "3.3.3-4",
3
+ "version": "3.3.3-5",
4
4
  "description": "Community plugin for native & electron SQLite databases",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",