@capacitor-community/sqlite 3.3.3-3 → 3.3.3

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.
@@ -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);
@@ -207,6 +207,39 @@ public class CapacitorSQLitePlugin: CAPPlugin {
207
207
  }
208
208
  }
209
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
+
210
243
  // MARK: - getVersion
211
244
 
212
245
  @objc func getVersion(_ call: CAPPluginCall) {
@@ -81,6 +81,12 @@ class Database {
81
81
  return ncDB
82
82
  }
83
83
 
84
+ // MARK: - getUrl
85
+
86
+ func getUrl () -> String {
87
+ return "file://\(path)"
88
+ }
89
+
84
90
  // MARK: - Open
85
91
 
86
92
  // swiftlint:disable cyclomatic_complexity
@@ -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
  }
@@ -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-3",
3
+ "version": "3.3.3",
4
4
  "description": "Community plugin for native & electron SQLite databases",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",