@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.
- package/README.md +9 -2
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/CapacitorSQLite.java +22 -0
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/CapacitorSQLitePlugin.java +25 -1
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/RetHandler.java +25 -1
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/Database.java +9 -0
- package/dist/esm/definitions.d.ts +20 -0
- package/dist/esm/definitions.js +11 -0
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/web.d.ts +2 -1
- package/dist/esm/web.js +3 -0
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +14 -0
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +14 -0
- package/dist/plugin.js.map +1 -1
- package/electron/dist/plugin.js +3 -0
- package/electron/dist/plugin.js.map +1 -1
- package/ios/Plugin/CapacitorSQLite.swift +726 -566
- package/ios/Plugin/CapacitorSQLitePlugin.m +1 -0
- package/ios/Plugin/CapacitorSQLitePlugin.swift +33 -0
- package/ios/Plugin/Database.swift +6 -0
- package/ios/Plugin/ReturnHandler.swift +12 -0
- package/ios/Plugin/Utils/UtilsFile.swift +23 -24
- package/package.json +1 -1
- package/CHANGELOG.md +0 -1230
|
@@ -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) {
|
|
@@ -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
|
-
|
|
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 =
|
|
49
|
-
|
|
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
|
|
58
|
-
|
|
59
|
-
|
|
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.
|
|
58
|
+
throw UtilsFileError.createDatabaseLocationFailed(message: message)
|
|
63
59
|
} catch UtilsFileError.moveAllDBSQLiteFailed(let message) {
|
|
64
|
-
throw UtilsFileError.
|
|
60
|
+
throw UtilsFileError.createDatabaseLocationFailed(message: message)
|
|
65
61
|
} catch let error {
|
|
66
|
-
var msg: String = "
|
|
62
|
+
var msg: String = "CreateDatabaseLocation command failed :"
|
|
67
63
|
msg.append(" \(error.localizedDescription)")
|
|
68
|
-
throw UtilsFileError.
|
|
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
|