@capgo/capacitor-data-storage-sqlite 6.0.0
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/CapacitorDataStorageSqlite.podspec +18 -0
- package/LICENSE +21 -0
- package/android/build.gradle +63 -0
- package/android/src/main/AndroidManifest.xml +3 -0
- package/android/src/main/java/com/jeep/plugin/capacitor/capacitordatastoragesqlite/CapacitorDataStorageSqlite.java +387 -0
- package/android/src/main/java/com/jeep/plugin/capacitor/capacitordatastoragesqlite/CapacitorDataStorageSqlitePlugin.java +447 -0
- package/android/src/main/java/com/jeep/plugin/capacitor/capacitordatastoragesqlite/RetHandler.java +117 -0
- package/android/src/main/java/com/jeep/plugin/capacitor/capacitordatastoragesqlite/cdssUtils/Data.java +8 -0
- package/android/src/main/java/com/jeep/plugin/capacitor/capacitordatastoragesqlite/cdssUtils/Global.java +7 -0
- package/android/src/main/java/com/jeep/plugin/capacitor/capacitordatastoragesqlite/cdssUtils/ImportExportJson/JsonStore.java +131 -0
- package/android/src/main/java/com/jeep/plugin/capacitor/capacitordatastoragesqlite/cdssUtils/ImportExportJson/JsonTable.java +110 -0
- package/android/src/main/java/com/jeep/plugin/capacitor/capacitordatastoragesqlite/cdssUtils/ImportExportJson/JsonValue.java +89 -0
- package/android/src/main/java/com/jeep/plugin/capacitor/capacitordatastoragesqlite/cdssUtils/StorageDatabaseHelper.java +691 -0
- package/android/src/main/java/com/jeep/plugin/capacitor/capacitordatastoragesqlite/cdssUtils/UtilsSQLCipher.java +162 -0
- package/android/src/main/res/.gitkeep +0 -0
- package/dist/docs.json +995 -0
- package/dist/esm/definitions.d.ts +296 -0
- package/dist/esm/definitions.js +2 -0
- package/dist/esm/definitions.js.map +1 -0
- package/dist/esm/index.d.ts +4 -0
- package/dist/esm/index.js +9 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/web-utils/Data.d.ts +5 -0
- package/dist/esm/web-utils/Data.js +3 -0
- package/dist/esm/web-utils/Data.js.map +1 -0
- package/dist/esm/web-utils/StorageDatabaseHelper.d.ts +23 -0
- package/dist/esm/web-utils/StorageDatabaseHelper.js +247 -0
- package/dist/esm/web-utils/StorageDatabaseHelper.js.map +1 -0
- package/dist/esm/web-utils/json-utils.d.ts +15 -0
- package/dist/esm/web-utils/json-utils.js +76 -0
- package/dist/esm/web-utils/json-utils.js.map +1 -0
- package/dist/esm/web.d.ts +27 -0
- package/dist/esm/web.js +295 -0
- package/dist/esm/web.js.map +1 -0
- package/dist/plugin.cjs.js +633 -0
- package/dist/plugin.cjs.js.map +1 -0
- package/dist/plugin.js +635 -0
- package/dist/plugin.js.map +1 -0
- package/electron/dist/plugin.js +1044 -0
- package/electron/dist/plugin.js.map +1 -0
- package/electron/rollup.config.mjs +17 -0
- package/electron/tsconfig.json +19 -0
- package/ios/Plugin/CapacitorDataStorageSqlite.swift +550 -0
- package/ios/Plugin/CapacitorDataStorageSqlitePlugin.h +10 -0
- package/ios/Plugin/CapacitorDataStorageSqlitePlugin.m +29 -0
- package/ios/Plugin/CapacitorDataStorageSqlitePlugin.swift +550 -0
- package/ios/Plugin/Data.swift +16 -0
- package/ios/Plugin/Global.swift +13 -0
- package/ios/Plugin/ImportExportJson/JsonStore.swift +47 -0
- package/ios/Plugin/Info.plist +24 -0
- package/ios/Plugin/ReturnHandler.swift +85 -0
- package/ios/Plugin/StorageDatabaseHelper.swift +603 -0
- package/ios/Plugin/Utils/Blob.swift +41 -0
- package/ios/Plugin/Utils/UtilsBinding.swift +73 -0
- package/ios/Plugin/Utils/UtilsEncryption.swift +79 -0
- package/ios/Plugin/Utils/UtilsFile.swift +244 -0
- package/ios/Plugin/Utils/UtilsSQLCipher.swift +605 -0
- package/package.json +96 -0
- package/readme.md +203 -0
|
@@ -0,0 +1,550 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
|
|
3
|
+
enum CapacitorDataStorageSqliteError: Error {
|
|
4
|
+
case failed(message: String)
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
// swiftlint:disable file_length
|
|
8
|
+
// swiftlint:disable type_body_length
|
|
9
|
+
@objc public class CapacitorDataStorageSqlite: NSObject {
|
|
10
|
+
var mDb: StorageDatabaseHelper?
|
|
11
|
+
|
|
12
|
+
// MARK: - Echo
|
|
13
|
+
|
|
14
|
+
@objc public func echo(_ value: String) -> String {
|
|
15
|
+
return value
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// MARK: - OpenStore
|
|
19
|
+
|
|
20
|
+
@objc func openStore(_ dbName: String, tableName: String,
|
|
21
|
+
encrypted: Bool, inMode: String
|
|
22
|
+
) throws {
|
|
23
|
+
do {
|
|
24
|
+
mDb = try StorageDatabaseHelper(
|
|
25
|
+
databaseName: "\(dbName)SQLite.db",
|
|
26
|
+
tableName: tableName,
|
|
27
|
+
encrypted: encrypted, mode: inMode)
|
|
28
|
+
} catch StorageHelperError.initFailed(let message) {
|
|
29
|
+
throw CapacitorDataStorageSqliteError
|
|
30
|
+
.failed(message: message)
|
|
31
|
+
} catch let error {
|
|
32
|
+
throw CapacitorDataStorageSqliteError
|
|
33
|
+
.failed(message: error.localizedDescription)
|
|
34
|
+
}
|
|
35
|
+
if !(mDb?.isOpen ?? true) {
|
|
36
|
+
throw CapacitorDataStorageSqliteError
|
|
37
|
+
.failed(message: "store not opened")
|
|
38
|
+
} else {
|
|
39
|
+
return
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// MARK: - closeStore
|
|
44
|
+
|
|
45
|
+
@objc func closeStore(_ name: String) throws {
|
|
46
|
+
if mDb != nil && ((mDb?.isOpen) != nil) &&
|
|
47
|
+
mDb?.dbName == "\(name)SQLite.db" {
|
|
48
|
+
do {
|
|
49
|
+
try mDb?.close()
|
|
50
|
+
return
|
|
51
|
+
} catch StorageHelperError.close(let message) {
|
|
52
|
+
throw CapacitorDataStorageSqliteError
|
|
53
|
+
.failed(message: message)
|
|
54
|
+
} catch let error {
|
|
55
|
+
let msg = error.localizedDescription
|
|
56
|
+
throw CapacitorDataStorageSqliteError
|
|
57
|
+
.failed(message: msg)
|
|
58
|
+
}
|
|
59
|
+
} else {
|
|
60
|
+
let message = "No database connection"
|
|
61
|
+
throw CapacitorDataStorageSqliteError
|
|
62
|
+
.failed(message: message)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// MARK: - isStoreExists
|
|
68
|
+
|
|
69
|
+
@objc func isStoreExists(_ name: String) throws -> NSNumber {
|
|
70
|
+
|
|
71
|
+
let result: Bool = UtilsFile
|
|
72
|
+
.isFileExist(fileName: "\(name)SQLite.db")
|
|
73
|
+
if result {
|
|
74
|
+
return 1
|
|
75
|
+
} else {
|
|
76
|
+
return 0
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// MARK: - isStoreOpen
|
|
81
|
+
|
|
82
|
+
@objc func isStoreOpen(_ name: String) throws -> NSNumber {
|
|
83
|
+
if mDb != nil {
|
|
84
|
+
if mDb?.dbName == "\(name)SQLite.db" && ((mDb?.isOpen) != nil) {
|
|
85
|
+
return 1
|
|
86
|
+
} else {
|
|
87
|
+
return 0
|
|
88
|
+
}
|
|
89
|
+
} else {
|
|
90
|
+
let message = "No database connection"
|
|
91
|
+
throw CapacitorDataStorageSqliteError
|
|
92
|
+
.failed(message: message)
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// MARK: - setTable
|
|
97
|
+
|
|
98
|
+
@objc func setTable(_ tableName: String) throws {
|
|
99
|
+
|
|
100
|
+
if mDb != nil {
|
|
101
|
+
do {
|
|
102
|
+
try mDb?.setTable(tblName: tableName)
|
|
103
|
+
return
|
|
104
|
+
} catch StorageHelperError.setTable(let message) {
|
|
105
|
+
throw CapacitorDataStorageSqliteError
|
|
106
|
+
.failed(message: message)
|
|
107
|
+
} catch let error {
|
|
108
|
+
throw CapacitorDataStorageSqliteError
|
|
109
|
+
.failed(message: error.localizedDescription)
|
|
110
|
+
}
|
|
111
|
+
} else {
|
|
112
|
+
let message = "Must open a store first"
|
|
113
|
+
throw CapacitorDataStorageSqliteError
|
|
114
|
+
.failed(message: message)
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// MARK: - set
|
|
119
|
+
|
|
120
|
+
@objc func set(_ data: Any) throws {
|
|
121
|
+
if mDb != nil {
|
|
122
|
+
if let mData = data as? Data {
|
|
123
|
+
do {
|
|
124
|
+
try mDb?.set(data: mData)
|
|
125
|
+
} catch StorageHelperError.setkey(let message) {
|
|
126
|
+
throw CapacitorDataStorageSqliteError
|
|
127
|
+
.failed(message: message)
|
|
128
|
+
} catch let error {
|
|
129
|
+
let msg = error.localizedDescription
|
|
130
|
+
throw CapacitorDataStorageSqliteError
|
|
131
|
+
.failed(message: msg)
|
|
132
|
+
}
|
|
133
|
+
} else {
|
|
134
|
+
let message = "data is not of type Data"
|
|
135
|
+
throw CapacitorDataStorageSqliteError
|
|
136
|
+
.failed(message: message)
|
|
137
|
+
}
|
|
138
|
+
} else {
|
|
139
|
+
let message = "No database connection"
|
|
140
|
+
throw CapacitorDataStorageSqliteError
|
|
141
|
+
.failed(message: message)
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// MARK: - get
|
|
146
|
+
|
|
147
|
+
@objc func get(_ name: String) throws -> String {
|
|
148
|
+
|
|
149
|
+
if mDb != nil {
|
|
150
|
+
do {
|
|
151
|
+
if let data: Data = try mDb?.get(name: name) {
|
|
152
|
+
if let value = data.value {
|
|
153
|
+
return value
|
|
154
|
+
} else {
|
|
155
|
+
return ""
|
|
156
|
+
}
|
|
157
|
+
} else {
|
|
158
|
+
let message = "No Data returned"
|
|
159
|
+
throw CapacitorDataStorageSqliteError
|
|
160
|
+
.failed(message: message)
|
|
161
|
+
}
|
|
162
|
+
} catch CapacitorDataStorageSqliteError.failed(let message) {
|
|
163
|
+
throw CapacitorDataStorageSqliteError
|
|
164
|
+
.failed(message: message)
|
|
165
|
+
} catch StorageHelperError.getkey(let message) {
|
|
166
|
+
throw CapacitorDataStorageSqliteError
|
|
167
|
+
.failed(message: message)
|
|
168
|
+
} catch let error {
|
|
169
|
+
let msg = error.localizedDescription
|
|
170
|
+
throw CapacitorDataStorageSqliteError
|
|
171
|
+
.failed(message: msg)
|
|
172
|
+
}
|
|
173
|
+
} else {
|
|
174
|
+
let message = "No database connection"
|
|
175
|
+
throw CapacitorDataStorageSqliteError
|
|
176
|
+
.failed(message: message)
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// MARK: - remove
|
|
181
|
+
|
|
182
|
+
@objc func remove(_ name: String) throws {
|
|
183
|
+
if mDb != nil {
|
|
184
|
+
do {
|
|
185
|
+
try mDb?.remove(name: name)
|
|
186
|
+
return
|
|
187
|
+
} catch StorageHelperError.remove(let message) {
|
|
188
|
+
throw CapacitorDataStorageSqliteError
|
|
189
|
+
.failed(message: message)
|
|
190
|
+
} catch let error {
|
|
191
|
+
let msg = error.localizedDescription
|
|
192
|
+
throw CapacitorDataStorageSqliteError
|
|
193
|
+
.failed(message: msg)
|
|
194
|
+
}
|
|
195
|
+
} else {
|
|
196
|
+
let message = "No database connection"
|
|
197
|
+
throw CapacitorDataStorageSqliteError
|
|
198
|
+
.failed(message: message)
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// MARK: - clear
|
|
204
|
+
|
|
205
|
+
@objc func clear() throws {
|
|
206
|
+
if mDb != nil {
|
|
207
|
+
do {
|
|
208
|
+
try mDb?.clear()
|
|
209
|
+
return
|
|
210
|
+
} catch StorageHelperError.clear(let message) {
|
|
211
|
+
throw CapacitorDataStorageSqliteError
|
|
212
|
+
.failed(message: message)
|
|
213
|
+
} catch let error {
|
|
214
|
+
let msg = error.localizedDescription
|
|
215
|
+
throw CapacitorDataStorageSqliteError
|
|
216
|
+
.failed(message: msg)
|
|
217
|
+
}
|
|
218
|
+
} else {
|
|
219
|
+
let message = "No database connection"
|
|
220
|
+
throw CapacitorDataStorageSqliteError
|
|
221
|
+
.failed(message: message)
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
// MARK: - iskey
|
|
227
|
+
|
|
228
|
+
@objc func iskey(_ name: String) throws -> NSNumber {
|
|
229
|
+
if mDb != nil {
|
|
230
|
+
do {
|
|
231
|
+
let result: Bool = try mDb?.iskey(name: name) ?? false
|
|
232
|
+
if result {
|
|
233
|
+
return 1
|
|
234
|
+
} else {
|
|
235
|
+
return 0
|
|
236
|
+
}
|
|
237
|
+
} catch StorageHelperError.iskey(let message) {
|
|
238
|
+
throw CapacitorDataStorageSqliteError
|
|
239
|
+
.failed(message: message)
|
|
240
|
+
} catch let error {
|
|
241
|
+
let msg = error.localizedDescription
|
|
242
|
+
throw CapacitorDataStorageSqliteError
|
|
243
|
+
.failed(message: msg)
|
|
244
|
+
}
|
|
245
|
+
} else {
|
|
246
|
+
let message = "No database connection"
|
|
247
|
+
throw CapacitorDataStorageSqliteError
|
|
248
|
+
.failed(message: message)
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
// MARK: - keys
|
|
253
|
+
|
|
254
|
+
@objc func keys() throws -> [String] {
|
|
255
|
+
if mDb != nil {
|
|
256
|
+
do {
|
|
257
|
+
let result = try mDb?.keys() ?? []
|
|
258
|
+
return result
|
|
259
|
+
} catch StorageHelperError.keys(let message) {
|
|
260
|
+
throw CapacitorDataStorageSqliteError
|
|
261
|
+
.failed(message: message)
|
|
262
|
+
} catch let error {
|
|
263
|
+
let msg = error.localizedDescription
|
|
264
|
+
throw CapacitorDataStorageSqliteError
|
|
265
|
+
.failed(message: msg)
|
|
266
|
+
}
|
|
267
|
+
} else {
|
|
268
|
+
let message = "No database connection"
|
|
269
|
+
throw CapacitorDataStorageSqliteError
|
|
270
|
+
.failed(message: message)
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
// MARK: - values
|
|
275
|
+
|
|
276
|
+
@objc func values() throws -> [String] {
|
|
277
|
+
if mDb != nil {
|
|
278
|
+
do {
|
|
279
|
+
let result = try mDb?.values() ?? []
|
|
280
|
+
return result
|
|
281
|
+
} catch StorageHelperError.values(let message) {
|
|
282
|
+
throw CapacitorDataStorageSqliteError
|
|
283
|
+
.failed(message: message)
|
|
284
|
+
} catch let error {
|
|
285
|
+
let msg = error.localizedDescription
|
|
286
|
+
throw CapacitorDataStorageSqliteError
|
|
287
|
+
.failed(message: msg)
|
|
288
|
+
}
|
|
289
|
+
} else {
|
|
290
|
+
let message = "No database connection"
|
|
291
|
+
throw CapacitorDataStorageSqliteError
|
|
292
|
+
.failed(message: message)
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
// MARK: - filtervalues
|
|
297
|
+
|
|
298
|
+
@objc func filtervalues(filter: String) throws -> [String] {
|
|
299
|
+
if mDb != nil {
|
|
300
|
+
do {
|
|
301
|
+
let result = try mDb?.filtervalues(filter: filter) ?? []
|
|
302
|
+
return result
|
|
303
|
+
|
|
304
|
+
} catch StorageHelperError.filtervalues(let message) {
|
|
305
|
+
throw CapacitorDataStorageSqliteError
|
|
306
|
+
.failed(message: message)
|
|
307
|
+
} catch let error {
|
|
308
|
+
let msg = error.localizedDescription
|
|
309
|
+
throw CapacitorDataStorageSqliteError
|
|
310
|
+
.failed(message: msg)
|
|
311
|
+
}
|
|
312
|
+
} else {
|
|
313
|
+
let message = "No database connection"
|
|
314
|
+
throw CapacitorDataStorageSqliteError
|
|
315
|
+
.failed(message: message)
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
// MARK: - keysvalues
|
|
320
|
+
|
|
321
|
+
@objc func keysvalues() throws -> [[String: String]] {
|
|
322
|
+
if mDb != nil {
|
|
323
|
+
var dicArray: [[String: String]] = []
|
|
324
|
+
do {
|
|
325
|
+
let results = try mDb?.keysvalues() ?? []
|
|
326
|
+
for result in results {
|
|
327
|
+
let res = ["key": result.name ?? "",
|
|
328
|
+
"value": result.value ?? ""]
|
|
329
|
+
dicArray.append(res)
|
|
330
|
+
}
|
|
331
|
+
return dicArray
|
|
332
|
+
|
|
333
|
+
} catch StorageHelperError.keysvalues(let message) {
|
|
334
|
+
throw CapacitorDataStorageSqliteError
|
|
335
|
+
.failed(message: message)
|
|
336
|
+
} catch let error {
|
|
337
|
+
let msg = error.localizedDescription
|
|
338
|
+
throw CapacitorDataStorageSqliteError
|
|
339
|
+
.failed(message: msg)
|
|
340
|
+
}
|
|
341
|
+
} else {
|
|
342
|
+
let message = "No database connection"
|
|
343
|
+
throw CapacitorDataStorageSqliteError
|
|
344
|
+
.failed(message: message)
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
// MARK: - deleteStore
|
|
349
|
+
|
|
350
|
+
@objc func deleteStore(storeName: String) throws {
|
|
351
|
+
do {
|
|
352
|
+
try UtilsFile.deleteFile(fileName: "\(storeName)SQLite.db")
|
|
353
|
+
return
|
|
354
|
+
} catch UtilsFileError.deleteFileFailed {
|
|
355
|
+
let message = "Failed in delete file"
|
|
356
|
+
throw CapacitorDataStorageSqliteError
|
|
357
|
+
.failed(message: message)
|
|
358
|
+
} catch let error {
|
|
359
|
+
let msg = error.localizedDescription
|
|
360
|
+
throw CapacitorDataStorageSqliteError
|
|
361
|
+
.failed(message: msg)
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
// MARK: - isTable
|
|
366
|
+
|
|
367
|
+
@objc func isTable(_ name: String) throws -> NSNumber {
|
|
368
|
+
if mDb != nil {
|
|
369
|
+
do {
|
|
370
|
+
let result: Bool = try mDb?.isTable(name: name) ?? false
|
|
371
|
+
if result {
|
|
372
|
+
return 1
|
|
373
|
+
} else {
|
|
374
|
+
return 0
|
|
375
|
+
}
|
|
376
|
+
} catch StorageHelperError.isTable(let message) {
|
|
377
|
+
throw CapacitorDataStorageSqliteError
|
|
378
|
+
.failed(message: message)
|
|
379
|
+
} catch let error {
|
|
380
|
+
let msg = error.localizedDescription
|
|
381
|
+
throw CapacitorDataStorageSqliteError
|
|
382
|
+
.failed(message: msg)
|
|
383
|
+
}
|
|
384
|
+
} else {
|
|
385
|
+
let message = "No database connection"
|
|
386
|
+
throw CapacitorDataStorageSqliteError
|
|
387
|
+
.failed(message: message)
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
// MARK: - tables
|
|
392
|
+
|
|
393
|
+
@objc func tables() throws -> [String] {
|
|
394
|
+
if mDb != nil {
|
|
395
|
+
do {
|
|
396
|
+
let result = try mDb?.tables() ?? []
|
|
397
|
+
return result
|
|
398
|
+
} catch StorageHelperError.tables(let message) {
|
|
399
|
+
throw CapacitorDataStorageSqliteError
|
|
400
|
+
.failed(message: message)
|
|
401
|
+
} catch let error {
|
|
402
|
+
let msg = error.localizedDescription
|
|
403
|
+
throw CapacitorDataStorageSqliteError
|
|
404
|
+
.failed(message: msg)
|
|
405
|
+
}
|
|
406
|
+
} else {
|
|
407
|
+
let message = "No database connection"
|
|
408
|
+
throw CapacitorDataStorageSqliteError
|
|
409
|
+
.failed(message: message)
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
// MARK: - deleteTable
|
|
414
|
+
|
|
415
|
+
@objc func deleteTable(_ tableName: String) throws {
|
|
416
|
+
|
|
417
|
+
if mDb != nil {
|
|
418
|
+
do {
|
|
419
|
+
try mDb?.deleteTable(tableName: tableName)
|
|
420
|
+
return
|
|
421
|
+
} catch StorageHelperError.deleteTable(let message) {
|
|
422
|
+
throw CapacitorDataStorageSqliteError
|
|
423
|
+
.failed(message: message)
|
|
424
|
+
} catch let error {
|
|
425
|
+
throw CapacitorDataStorageSqliteError
|
|
426
|
+
.failed(message: error.localizedDescription)
|
|
427
|
+
}
|
|
428
|
+
} else {
|
|
429
|
+
let message = "Must open a store first"
|
|
430
|
+
throw CapacitorDataStorageSqliteError
|
|
431
|
+
.failed(message: message)
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
// MARK: - isJsonValid
|
|
436
|
+
|
|
437
|
+
@objc func isJsonValid(_ parsingData: String) throws {
|
|
438
|
+
|
|
439
|
+
if let data = ("["+parsingData+"]").data(using: .utf8) {
|
|
440
|
+
do {
|
|
441
|
+
_ = try JSONDecoder().decode([JsonStore].self,
|
|
442
|
+
from: data)
|
|
443
|
+
return
|
|
444
|
+
} catch let error {
|
|
445
|
+
let msg: String = "\(error.localizedDescription)"
|
|
446
|
+
throw CapacitorDataStorageSqliteError.failed(message: msg)
|
|
447
|
+
}
|
|
448
|
+
} else {
|
|
449
|
+
let msg: String = "Stringify Json Object not Valid"
|
|
450
|
+
throw CapacitorDataStorageSqliteError.failed(message: msg)
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
// MARK: - importFromJson
|
|
455
|
+
|
|
456
|
+
// swiftlint:disable function_body_length
|
|
457
|
+
@objc func importFromJson(_ parsingData: String)
|
|
458
|
+
throws -> [String: Int] {
|
|
459
|
+
var mDb: StorageDatabaseHelper
|
|
460
|
+
if let data = ("["+parsingData+"]").data(using: .utf8) {
|
|
461
|
+
// check jsonStore validity
|
|
462
|
+
var jsonStore: [JsonStore]
|
|
463
|
+
do {
|
|
464
|
+
jsonStore = try JSONDecoder()
|
|
465
|
+
.decode([JsonStore].self, from: data)
|
|
466
|
+
} catch let error {
|
|
467
|
+
var msg: String = "Stringify Json Object not Valid "
|
|
468
|
+
msg.append("\(error.localizedDescription)")
|
|
469
|
+
throw CapacitorDataStorageSqliteError.failed(message: msg)
|
|
470
|
+
}
|
|
471
|
+
var totalChanges = 0
|
|
472
|
+
let encrypted: Bool = jsonStore[0].encrypted
|
|
473
|
+
let dbName: String = jsonStore[0].database
|
|
474
|
+
let mode: String = encrypted ? "secret" : ""
|
|
475
|
+
do {
|
|
476
|
+
for table in jsonStore[0].tables {
|
|
477
|
+
// open the database
|
|
478
|
+
mDb = try StorageDatabaseHelper(
|
|
479
|
+
databaseName: "\(dbName)SQLite.db",
|
|
480
|
+
tableName: table.name,
|
|
481
|
+
encrypted: encrypted, mode: mode)
|
|
482
|
+
if !(mDb.isOpen ) {
|
|
483
|
+
throw CapacitorDataStorageSqliteError
|
|
484
|
+
.failed(message: "store not opened")
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
// import table from json table values
|
|
488
|
+
let changes: Int = try mDb
|
|
489
|
+
.importFromJson(values: table.values)
|
|
490
|
+
if changes < 1 {
|
|
491
|
+
let msg: String = "changes < 1"
|
|
492
|
+
throw CapacitorDataStorageSqliteError
|
|
493
|
+
.failed(message: msg)
|
|
494
|
+
}
|
|
495
|
+
try mDb.close()
|
|
496
|
+
totalChanges += changes
|
|
497
|
+
}
|
|
498
|
+
return ["changes": totalChanges]
|
|
499
|
+
} catch StorageHelperError.initFailed(let message) {
|
|
500
|
+
throw CapacitorDataStorageSqliteError
|
|
501
|
+
.failed(message: message)
|
|
502
|
+
} catch StorageHelperError.close(let message) {
|
|
503
|
+
throw CapacitorDataStorageSqliteError
|
|
504
|
+
.failed(message: message)
|
|
505
|
+
} catch StorageHelperError.importFromJson(let message) {
|
|
506
|
+
let msg = message
|
|
507
|
+
do {
|
|
508
|
+
try closeStore(dbName)
|
|
509
|
+
throw CapacitorDataStorageSqliteError.failed(message: msg)
|
|
510
|
+
} catch let error {
|
|
511
|
+
throw CapacitorDataStorageSqliteError
|
|
512
|
+
.failed(message: error.localizedDescription)
|
|
513
|
+
}
|
|
514
|
+
} catch let error {
|
|
515
|
+
print("\(error)")
|
|
516
|
+
throw CapacitorDataStorageSqliteError
|
|
517
|
+
.failed(message: error.localizedDescription)
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
} else {
|
|
521
|
+
let msg: String = "Stringify Json Object not Valid"
|
|
522
|
+
throw CapacitorDataStorageSqliteError.failed(message: msg)
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
// swiftlint:enable function_body_length
|
|
526
|
+
|
|
527
|
+
// MARK: - exportToJson
|
|
528
|
+
|
|
529
|
+
@objc func exportToJson()
|
|
530
|
+
throws -> [String: Any] {
|
|
531
|
+
if mDb != nil {
|
|
532
|
+
do {
|
|
533
|
+
let res: [String: Any] = try
|
|
534
|
+
mDb?.exportToJson() ?? [:]
|
|
535
|
+
return res
|
|
536
|
+
} catch StorageHelperError.exportToJson(let message) {
|
|
537
|
+
throw CapacitorDataStorageSqliteError.failed(message: message)
|
|
538
|
+
} catch let error {
|
|
539
|
+
let msg: String = "\(error.localizedDescription)"
|
|
540
|
+
throw CapacitorDataStorageSqliteError.failed(message: msg)
|
|
541
|
+
}
|
|
542
|
+
} else {
|
|
543
|
+
let message = "Must open a store first"
|
|
544
|
+
throw CapacitorDataStorageSqliteError
|
|
545
|
+
.failed(message: message)
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
// swiftlint:enable type_body_length
|
|
550
|
+
// swiftlint:enable file_length
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
#import <UIKit/UIKit.h>
|
|
2
|
+
|
|
3
|
+
//! Project version number for Plugin.
|
|
4
|
+
FOUNDATION_EXPORT double PluginVersionNumber;
|
|
5
|
+
|
|
6
|
+
//! Project version string for Plugin.
|
|
7
|
+
FOUNDATION_EXPORT const unsigned char PluginVersionString[];
|
|
8
|
+
|
|
9
|
+
// In this header, you should import all the public headers of your framework using statements like #import <Plugin/PublicHeader.h>
|
|
10
|
+
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
#import <Foundation/Foundation.h>
|
|
2
|
+
#import <Capacitor/Capacitor.h>
|
|
3
|
+
|
|
4
|
+
// Define the plugin using the CAP_PLUGIN Macro, and
|
|
5
|
+
// each method the plugin supports using the CAP_PLUGIN_METHOD macro.
|
|
6
|
+
CAP_PLUGIN(CapacitorDataStorageSqlitePlugin, "CapacitorDataStorageSqlite",
|
|
7
|
+
CAP_PLUGIN_METHOD(echo, CAPPluginReturnPromise);
|
|
8
|
+
CAP_PLUGIN_METHOD(openStore, CAPPluginReturnPromise);
|
|
9
|
+
CAP_PLUGIN_METHOD(closeStore, CAPPluginReturnPromise);
|
|
10
|
+
CAP_PLUGIN_METHOD(isStoreOpen, CAPPluginReturnPromise);
|
|
11
|
+
CAP_PLUGIN_METHOD(isStoreExists, CAPPluginReturnPromise);
|
|
12
|
+
CAP_PLUGIN_METHOD(setTable, CAPPluginReturnPromise);
|
|
13
|
+
CAP_PLUGIN_METHOD(set, CAPPluginReturnPromise);
|
|
14
|
+
CAP_PLUGIN_METHOD(get, CAPPluginReturnPromise);
|
|
15
|
+
CAP_PLUGIN_METHOD(remove, CAPPluginReturnPromise);
|
|
16
|
+
CAP_PLUGIN_METHOD(clear, CAPPluginReturnPromise);
|
|
17
|
+
CAP_PLUGIN_METHOD(keys, CAPPluginReturnPromise);
|
|
18
|
+
CAP_PLUGIN_METHOD(values, CAPPluginReturnPromise);
|
|
19
|
+
CAP_PLUGIN_METHOD(filtervalues, CAPPluginReturnPromise);
|
|
20
|
+
CAP_PLUGIN_METHOD(keysvalues, CAPPluginReturnPromise);
|
|
21
|
+
CAP_PLUGIN_METHOD(iskey, CAPPluginReturnPromise);
|
|
22
|
+
CAP_PLUGIN_METHOD(deleteStore,CAPPluginReturnPromise);
|
|
23
|
+
CAP_PLUGIN_METHOD(isTable,CAPPluginReturnPromise);
|
|
24
|
+
CAP_PLUGIN_METHOD(tables,CAPPluginReturnPromise);
|
|
25
|
+
CAP_PLUGIN_METHOD(deleteTable,CAPPluginReturnPromise);
|
|
26
|
+
CAP_PLUGIN_METHOD(isJsonValid,CAPPluginReturnPromise);
|
|
27
|
+
CAP_PLUGIN_METHOD(importFromJson,CAPPluginReturnPromise);
|
|
28
|
+
CAP_PLUGIN_METHOD(exportToJson,CAPPluginReturnPromise);
|
|
29
|
+
)
|