@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
|
+
import Capacitor
|
|
3
|
+
|
|
4
|
+
// swiftlint:disable file_length
|
|
5
|
+
// swiftlint:disable type_body_length
|
|
6
|
+
@objc(CapacitorDataStorageSqlitePlugin)
|
|
7
|
+
public class CapacitorDataStorageSqlitePlugin: CAPPlugin {
|
|
8
|
+
private let implementation = CapacitorDataStorageSqlite()
|
|
9
|
+
private let retHandler: ReturnHandler = ReturnHandler()
|
|
10
|
+
|
|
11
|
+
// MARK: - Echo
|
|
12
|
+
|
|
13
|
+
@objc func echo(_ call: CAPPluginCall) {
|
|
14
|
+
let value = call.getString("value") ?? ""
|
|
15
|
+
call.resolve([
|
|
16
|
+
"value": implementation.echo(value)
|
|
17
|
+
])
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// MARK: - OpenStore
|
|
21
|
+
|
|
22
|
+
@objc func openStore(_ call: CAPPluginCall) {
|
|
23
|
+
let dbName = call.options["database"] as? String ?? "storage"
|
|
24
|
+
let tableName = call.options["table"] as? String ?? "storage_table"
|
|
25
|
+
let encrypted = call.options["encrypted"] as? Bool ?? false
|
|
26
|
+
var inMode: String = ""
|
|
27
|
+
if encrypted {
|
|
28
|
+
inMode = call.options["mode"] as? String ?? "no-encryption"
|
|
29
|
+
|
|
30
|
+
if inMode != "no-encryption" && inMode != "encryption"
|
|
31
|
+
&& inMode != "secret" && inMode != "newsecret" && inMode != "wrongsecret" {
|
|
32
|
+
retHandler.rResult(
|
|
33
|
+
call: call,
|
|
34
|
+
message: "OpenStore: Error inMode must be in ['encryption','secret','newsecret'])")
|
|
35
|
+
return
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
} else {
|
|
39
|
+
inMode = "no-encryption"
|
|
40
|
+
}
|
|
41
|
+
do {
|
|
42
|
+
try implementation
|
|
43
|
+
.openStore(dbName,
|
|
44
|
+
tableName: tableName,
|
|
45
|
+
encrypted: encrypted, inMode: inMode)
|
|
46
|
+
retHandler.rResult(call: call)
|
|
47
|
+
return
|
|
48
|
+
} catch CapacitorDataStorageSqliteError
|
|
49
|
+
.failed(let message) {
|
|
50
|
+
let msg = "openStore: \(message)"
|
|
51
|
+
retHandler.rResult(call: call, message: msg)
|
|
52
|
+
return
|
|
53
|
+
} catch let error {
|
|
54
|
+
let msg = "openStore: \(error.localizedDescription)"
|
|
55
|
+
retHandler.rResult(call: call, message: msg)
|
|
56
|
+
return
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// MARK: - closeStore
|
|
61
|
+
|
|
62
|
+
@objc func closeStore(_ call: CAPPluginCall) {
|
|
63
|
+
|
|
64
|
+
guard let database = call.options["database"] as? String
|
|
65
|
+
else {
|
|
66
|
+
retHandler.rResult(
|
|
67
|
+
call: call, ret: false,
|
|
68
|
+
message: "closeStore: Must provide a database")
|
|
69
|
+
return
|
|
70
|
+
}
|
|
71
|
+
do {
|
|
72
|
+
try implementation.closeStore(database)
|
|
73
|
+
retHandler.rResult(call: call)
|
|
74
|
+
return
|
|
75
|
+
} catch CapacitorDataStorageSqliteError.failed(let message) {
|
|
76
|
+
let msg = "closeStore: \(message)"
|
|
77
|
+
retHandler.rResult(call: call, ret: false, message: msg)
|
|
78
|
+
return
|
|
79
|
+
} catch let error {
|
|
80
|
+
let msg = "closeStore: \(error.localizedDescription)"
|
|
81
|
+
retHandler.rResult(call: call, ret: false, message: msg)
|
|
82
|
+
return
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// MARK: - isStoreOpen
|
|
87
|
+
|
|
88
|
+
@objc func isStoreOpen(_ call: CAPPluginCall) {
|
|
89
|
+
guard let database = call.options["database"] as? String
|
|
90
|
+
else {
|
|
91
|
+
retHandler.rResult(
|
|
92
|
+
call: call, ret: false,
|
|
93
|
+
message: "isStoreOpen: Must provide a database")
|
|
94
|
+
return
|
|
95
|
+
}
|
|
96
|
+
do {
|
|
97
|
+
let res = try implementation.isStoreOpen(database)
|
|
98
|
+
let ret = res == 1 ? true : false
|
|
99
|
+
retHandler.rResult(call: call, ret: ret)
|
|
100
|
+
return
|
|
101
|
+
} catch CapacitorDataStorageSqliteError
|
|
102
|
+
.failed(let message) {
|
|
103
|
+
let msg = "isStoreOpen: \(message)"
|
|
104
|
+
retHandler.rResult(call: call, ret: false, message: msg)
|
|
105
|
+
return
|
|
106
|
+
} catch let error {
|
|
107
|
+
let msg = "isStoreOpen: \(error.localizedDescription)"
|
|
108
|
+
retHandler.rResult(call: call, ret: false, message: msg)
|
|
109
|
+
return
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// MARK: - isStoreExists
|
|
114
|
+
|
|
115
|
+
@objc func isStoreExists(_ call: CAPPluginCall) {
|
|
116
|
+
guard let database = call.options["database"] as? String
|
|
117
|
+
else {
|
|
118
|
+
retHandler.rResult(
|
|
119
|
+
call: call, ret: false,
|
|
120
|
+
message: "isStoreExists: Must provide a database")
|
|
121
|
+
return
|
|
122
|
+
}
|
|
123
|
+
do {
|
|
124
|
+
let res = try implementation.isStoreExists(database)
|
|
125
|
+
let ret = res == 1 ? true : false
|
|
126
|
+
retHandler.rResult(call: call, ret: ret)
|
|
127
|
+
return
|
|
128
|
+
} catch CapacitorDataStorageSqliteError
|
|
129
|
+
.failed(let message) {
|
|
130
|
+
let msg = "isStoreExists: \(message)"
|
|
131
|
+
retHandler.rResult(call: call, ret: false, message: msg)
|
|
132
|
+
return
|
|
133
|
+
} catch let error {
|
|
134
|
+
let msg = "isStoreExists: \(error.localizedDescription)"
|
|
135
|
+
retHandler.rResult(call: call, ret: false, message: msg)
|
|
136
|
+
return
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// MARK: - SetTable
|
|
141
|
+
|
|
142
|
+
@objc func setTable(_ call: CAPPluginCall) {
|
|
143
|
+
guard let tableName = call.options["table"] as? String
|
|
144
|
+
else {
|
|
145
|
+
retHandler.rResult(
|
|
146
|
+
call: call,
|
|
147
|
+
message: "setTable: Must provide a table name")
|
|
148
|
+
return
|
|
149
|
+
}
|
|
150
|
+
do {
|
|
151
|
+
try implementation.setTable(tableName)
|
|
152
|
+
retHandler.rResult(call: call)
|
|
153
|
+
return
|
|
154
|
+
} catch CapacitorDataStorageSqliteError
|
|
155
|
+
.failed(let message) {
|
|
156
|
+
let msg = "setTable: \(message)"
|
|
157
|
+
retHandler.rResult(call: call, message: msg)
|
|
158
|
+
return
|
|
159
|
+
} catch let error {
|
|
160
|
+
let msg = "setTable: \(error.localizedDescription)"
|
|
161
|
+
retHandler.rResult(call: call, message: msg)
|
|
162
|
+
return
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// MARK: - Set
|
|
167
|
+
|
|
168
|
+
@objc func set(_ call: CAPPluginCall) {
|
|
169
|
+
var data: Data = Data()
|
|
170
|
+
guard let key = call.options["key"] as? String else {
|
|
171
|
+
retHandler.rResult(
|
|
172
|
+
call: call,
|
|
173
|
+
message: "set: Must provide a key")
|
|
174
|
+
return
|
|
175
|
+
}
|
|
176
|
+
data.name = key
|
|
177
|
+
guard let value = call.options["value"] as? String
|
|
178
|
+
else {
|
|
179
|
+
retHandler.rResult(
|
|
180
|
+
call: call,
|
|
181
|
+
message: "set: Must provide a value")
|
|
182
|
+
return
|
|
183
|
+
}
|
|
184
|
+
data.value = value
|
|
185
|
+
do {
|
|
186
|
+
try implementation.set(data)
|
|
187
|
+
retHandler.rResult(call: call)
|
|
188
|
+
return
|
|
189
|
+
} catch CapacitorDataStorageSqliteError
|
|
190
|
+
.failed(let message) {
|
|
191
|
+
let msg = "set: \(message)"
|
|
192
|
+
retHandler.rResult(call: call, message: msg)
|
|
193
|
+
return
|
|
194
|
+
} catch let error {
|
|
195
|
+
let msg = "set: \(error.localizedDescription)"
|
|
196
|
+
retHandler.rResult(call: call, message: msg)
|
|
197
|
+
return
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// MARK: - Get
|
|
203
|
+
|
|
204
|
+
@objc func get(_ call: CAPPluginCall) {
|
|
205
|
+
guard let key = call.options["key"] as? String else {
|
|
206
|
+
retHandler.rValue(
|
|
207
|
+
call: call, ret: "",
|
|
208
|
+
message: "get: Must provide a key")
|
|
209
|
+
return
|
|
210
|
+
}
|
|
211
|
+
do {
|
|
212
|
+
let ret = try implementation.get(key)
|
|
213
|
+
retHandler.rValue(call: call, ret: ret)
|
|
214
|
+
return
|
|
215
|
+
} catch CapacitorDataStorageSqliteError
|
|
216
|
+
.failed(let message) {
|
|
217
|
+
let msg = "get: \(message)"
|
|
218
|
+
retHandler.rValue(call: call, ret: "", message: msg)
|
|
219
|
+
return
|
|
220
|
+
} catch let error {
|
|
221
|
+
let msg = "get: \(error.localizedDescription)"
|
|
222
|
+
retHandler.rValue(call: call, ret: "", message: msg)
|
|
223
|
+
return
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// MARK: - Remove
|
|
229
|
+
|
|
230
|
+
@objc func remove(_ call: CAPPluginCall) {
|
|
231
|
+
guard let key = call.options["key"] as? String else {
|
|
232
|
+
retHandler.rResult(
|
|
233
|
+
call: call,
|
|
234
|
+
message: "remove: Must provide a key")
|
|
235
|
+
return
|
|
236
|
+
}
|
|
237
|
+
do {
|
|
238
|
+
try implementation.remove(key)
|
|
239
|
+
retHandler.rResult(call: call)
|
|
240
|
+
return
|
|
241
|
+
} catch CapacitorDataStorageSqliteError
|
|
242
|
+
.failed(let message) {
|
|
243
|
+
let msg = "remove: \(message)"
|
|
244
|
+
retHandler.rResult(call: call, message: msg)
|
|
245
|
+
return
|
|
246
|
+
} catch let error {
|
|
247
|
+
let msg = "remove: \(error.localizedDescription)"
|
|
248
|
+
retHandler.rResult(call: call, message: msg)
|
|
249
|
+
return
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
// MARK: - Clear
|
|
255
|
+
|
|
256
|
+
@objc func clear(_ call: CAPPluginCall) {
|
|
257
|
+
|
|
258
|
+
do {
|
|
259
|
+
try implementation.clear()
|
|
260
|
+
retHandler.rResult(call: call)
|
|
261
|
+
return
|
|
262
|
+
} catch CapacitorDataStorageSqliteError
|
|
263
|
+
.failed(let message) {
|
|
264
|
+
let msg = "clear: \(message)"
|
|
265
|
+
retHandler.rResult(call: call, message: msg)
|
|
266
|
+
return
|
|
267
|
+
} catch let error {
|
|
268
|
+
let msg = "clear: \(error.localizedDescription)"
|
|
269
|
+
retHandler.rResult(call: call, message: msg)
|
|
270
|
+
return
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
// MARK: - IsKey
|
|
275
|
+
|
|
276
|
+
@objc func iskey(_ call: CAPPluginCall) {
|
|
277
|
+
guard let key = call.options["key"] as? String else {
|
|
278
|
+
retHandler.rResult(
|
|
279
|
+
call: call, ret: false,
|
|
280
|
+
message: "remove: Must provide a key")
|
|
281
|
+
return
|
|
282
|
+
}
|
|
283
|
+
do {
|
|
284
|
+
let res = try implementation.iskey(key)
|
|
285
|
+
let ret = res == 1 ? true : false
|
|
286
|
+
retHandler.rResult(call: call, ret: ret)
|
|
287
|
+
return
|
|
288
|
+
} catch CapacitorDataStorageSqliteError
|
|
289
|
+
.failed(let message) {
|
|
290
|
+
let msg = "iskey: \(message)"
|
|
291
|
+
retHandler.rResult(call: call, ret: false, message: msg)
|
|
292
|
+
return
|
|
293
|
+
} catch let error {
|
|
294
|
+
let msg = "iskey: \(error.localizedDescription)"
|
|
295
|
+
retHandler.rResult(call: call, ret: false, message: msg)
|
|
296
|
+
return
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
// MARK: - Keys
|
|
302
|
+
|
|
303
|
+
@objc func keys(_ call: CAPPluginCall) {
|
|
304
|
+
do {
|
|
305
|
+
let ret = try implementation.keys()
|
|
306
|
+
retHandler.rDict(call: call, ret: ["keys": ret])
|
|
307
|
+
} catch CapacitorDataStorageSqliteError
|
|
308
|
+
.failed(let message) {
|
|
309
|
+
let msg = "keys: \(message)"
|
|
310
|
+
retHandler.rDict(call: call, ret: ["keys": []], message: msg)
|
|
311
|
+
return
|
|
312
|
+
} catch let error {
|
|
313
|
+
let msg = "keys: \(error.localizedDescription)"
|
|
314
|
+
retHandler.rDict(call: call, ret: ["keys": []], message: msg)
|
|
315
|
+
return
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
// MARK: - Values
|
|
320
|
+
|
|
321
|
+
@objc func values(_ call: CAPPluginCall) {
|
|
322
|
+
do {
|
|
323
|
+
let ret = try implementation.values()
|
|
324
|
+
retHandler.rDict(call: call, ret: ["values": ret])
|
|
325
|
+
} catch CapacitorDataStorageSqliteError
|
|
326
|
+
.failed(let message) {
|
|
327
|
+
let msg = "values: \(message)"
|
|
328
|
+
retHandler.rDict(call: call, ret: ["values": []], message: msg)
|
|
329
|
+
return
|
|
330
|
+
} catch let error {
|
|
331
|
+
let msg = "values: \(error.localizedDescription)"
|
|
332
|
+
retHandler.rDict(call: call, ret: ["values": []], message: msg)
|
|
333
|
+
return
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
// MARK: - FilterValues
|
|
338
|
+
|
|
339
|
+
@objc func filtervalues(_ call: CAPPluginCall) {
|
|
340
|
+
guard let filter = call.options["filter"] as? String else {
|
|
341
|
+
retHandler.rDict(
|
|
342
|
+
call: call, ret: ["values": []],
|
|
343
|
+
message: "remove: Must provide a filter")
|
|
344
|
+
return
|
|
345
|
+
}
|
|
346
|
+
do {
|
|
347
|
+
let ret = try implementation.filtervalues(filter: filter)
|
|
348
|
+
retHandler.rDict(call: call, ret: ["values": ret])
|
|
349
|
+
} catch CapacitorDataStorageSqliteError
|
|
350
|
+
.failed(let message) {
|
|
351
|
+
let msg = "values: \(message)"
|
|
352
|
+
retHandler.rDict(call: call, ret: ["values": []], message: msg)
|
|
353
|
+
return
|
|
354
|
+
} catch let error {
|
|
355
|
+
let msg = "values: \(error.localizedDescription)"
|
|
356
|
+
retHandler.rDict(call: call, ret: ["values": []], message: msg)
|
|
357
|
+
return
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
// MARK: - KeyValues
|
|
362
|
+
|
|
363
|
+
@objc func keysvalues(_ call: CAPPluginCall) {
|
|
364
|
+
do {
|
|
365
|
+
let ret = try implementation.keysvalues()
|
|
366
|
+
retHandler.rDict(call: call, ret: ["keysvalues": ret])
|
|
367
|
+
} catch CapacitorDataStorageSqliteError
|
|
368
|
+
.failed(let message) {
|
|
369
|
+
let msg = "keysvalues: \(message)"
|
|
370
|
+
retHandler.rDict(call: call, ret: ["keysvalues": []],
|
|
371
|
+
message: msg)
|
|
372
|
+
return
|
|
373
|
+
} catch let error {
|
|
374
|
+
let msg = "keysvalues: \(error.localizedDescription)"
|
|
375
|
+
retHandler.rDict(call: call, ret: ["keysvalues": []],
|
|
376
|
+
message: msg)
|
|
377
|
+
return
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
// MARK: - DeleteStore
|
|
383
|
+
|
|
384
|
+
@objc func deleteStore(_ call: CAPPluginCall) {
|
|
385
|
+
let storeName = call.options["database"] as? String ?? "storage"
|
|
386
|
+
do {
|
|
387
|
+
try implementation.deleteStore(storeName: storeName)
|
|
388
|
+
retHandler.rResult(call: call)
|
|
389
|
+
return
|
|
390
|
+
} catch CapacitorDataStorageSqliteError
|
|
391
|
+
.failed(let message) {
|
|
392
|
+
let msg = "set: \(message)"
|
|
393
|
+
retHandler.rResult(call: call, message: msg)
|
|
394
|
+
return
|
|
395
|
+
} catch let error {
|
|
396
|
+
let msg = "set: \(error.localizedDescription)"
|
|
397
|
+
retHandler.rResult(call: call, message: msg)
|
|
398
|
+
return
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
// MARK: - isTable
|
|
403
|
+
|
|
404
|
+
@objc func isTable(_ call: CAPPluginCall) {
|
|
405
|
+
guard let table = call.options["table"] as? String else {
|
|
406
|
+
retHandler.rResult(
|
|
407
|
+
call: call, ret: false,
|
|
408
|
+
message: "remove: Must provide a table")
|
|
409
|
+
return
|
|
410
|
+
}
|
|
411
|
+
do {
|
|
412
|
+
let res = try implementation.isTable(table)
|
|
413
|
+
let ret = res == 1 ? true : false
|
|
414
|
+
retHandler.rResult(call: call, ret: ret)
|
|
415
|
+
return
|
|
416
|
+
} catch CapacitorDataStorageSqliteError
|
|
417
|
+
.failed(let message) {
|
|
418
|
+
let msg = "istable: \(message)"
|
|
419
|
+
retHandler.rResult(call: call, ret: false, message: msg)
|
|
420
|
+
return
|
|
421
|
+
} catch let error {
|
|
422
|
+
let msg = "istable: \(error.localizedDescription)"
|
|
423
|
+
retHandler.rResult(call: call, ret: false, message: msg)
|
|
424
|
+
return
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
// MARK: - tables
|
|
429
|
+
|
|
430
|
+
@objc func tables(_ call: CAPPluginCall) {
|
|
431
|
+
do {
|
|
432
|
+
let ret = try implementation.tables()
|
|
433
|
+
retHandler.rDict(call: call, ret: ["tables": ret])
|
|
434
|
+
} catch CapacitorDataStorageSqliteError
|
|
435
|
+
.failed(let message) {
|
|
436
|
+
let msg = "tables: \(message)"
|
|
437
|
+
retHandler.rDict(call: call, ret: ["tables": []], message: msg)
|
|
438
|
+
return
|
|
439
|
+
} catch let error {
|
|
440
|
+
let msg = "tables: \(error.localizedDescription)"
|
|
441
|
+
retHandler.rDict(call: call, ret: ["tables": []], message: msg)
|
|
442
|
+
return
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
// MARK: - deleteTable
|
|
447
|
+
|
|
448
|
+
@objc func deleteTable(_ call: CAPPluginCall) {
|
|
449
|
+
guard let table = call.options["table"] as? String else {
|
|
450
|
+
retHandler.rResult(
|
|
451
|
+
call: call, ret: false,
|
|
452
|
+
message: "remove: Must provide a table")
|
|
453
|
+
return
|
|
454
|
+
}
|
|
455
|
+
do {
|
|
456
|
+
try implementation.deleteTable(table)
|
|
457
|
+
retHandler.rResult(call: call)
|
|
458
|
+
return
|
|
459
|
+
} catch CapacitorDataStorageSqliteError
|
|
460
|
+
.failed(let message) {
|
|
461
|
+
let msg = "clear: \(message)"
|
|
462
|
+
retHandler.rResult(call: call, message: msg)
|
|
463
|
+
return
|
|
464
|
+
} catch let error {
|
|
465
|
+
let msg = "clear: \(error.localizedDescription)"
|
|
466
|
+
retHandler.rResult(call: call, message: msg)
|
|
467
|
+
return
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
// MARK: - IsJsonValid
|
|
472
|
+
|
|
473
|
+
@objc func isJsonValid(_ call: CAPPluginCall) {
|
|
474
|
+
let parsingData: String = call.getString("jsonstring") ?? ""
|
|
475
|
+
if parsingData.count == 0 {
|
|
476
|
+
var msg: String = "IsJsonValid: "
|
|
477
|
+
msg.append("Must provide a Stringify Json Object")
|
|
478
|
+
retHandler.rResult(call: call, message: msg)
|
|
479
|
+
return
|
|
480
|
+
}
|
|
481
|
+
do {
|
|
482
|
+
try implementation.isJsonValid(parsingData)
|
|
483
|
+
retHandler.rResult(call: call, ret: true)
|
|
484
|
+
return
|
|
485
|
+
} catch CapacitorDataStorageSqliteError.failed(let message) {
|
|
486
|
+
let msg = "isJsonValid: \(message)"
|
|
487
|
+
retHandler.rResult(call: call, message: msg)
|
|
488
|
+
return
|
|
489
|
+
} catch let error {
|
|
490
|
+
let msg = "isJsonValid: \(error.localizedDescription)"
|
|
491
|
+
retHandler.rResult(call: call, message: msg)
|
|
492
|
+
return
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
// MARK: - ImportFromJson
|
|
497
|
+
|
|
498
|
+
@objc func importFromJson(_ call: CAPPluginCall) {
|
|
499
|
+
let parsingData: String = call.getString("jsonstring") ?? ""
|
|
500
|
+
if parsingData.count == 0 {
|
|
501
|
+
retHandler.rChanges(call: call, ret: ["changes": -1],
|
|
502
|
+
message: "ImportFromJson: " +
|
|
503
|
+
"Must provide a Stringify Json Object")
|
|
504
|
+
return
|
|
505
|
+
}
|
|
506
|
+
do {
|
|
507
|
+
let res: [String: Int] = try implementation.importFromJson(parsingData)
|
|
508
|
+
retHandler.rChanges(call: call, ret: res)
|
|
509
|
+
return
|
|
510
|
+
} catch CapacitorDataStorageSqliteError.failed(let message) {
|
|
511
|
+
retHandler.rChanges(
|
|
512
|
+
call: call, ret: ["changes": -1],
|
|
513
|
+
message: "importFromJson: \(message)")
|
|
514
|
+
return
|
|
515
|
+
} catch let error {
|
|
516
|
+
let msg = "importFromJson: " +
|
|
517
|
+
"\(error.localizedDescription)"
|
|
518
|
+
retHandler.rChanges(
|
|
519
|
+
call: call, ret: ["changes": -1],
|
|
520
|
+
message: msg)
|
|
521
|
+
return
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
// MARK: - ExportToJson
|
|
527
|
+
|
|
528
|
+
@objc func exportToJson(_ call: CAPPluginCall) {
|
|
529
|
+
|
|
530
|
+
do {
|
|
531
|
+
let res: [String: Any] = try implementation.exportToJson()
|
|
532
|
+
retHandler.rJsonStore(call: call, ret: res)
|
|
533
|
+
return
|
|
534
|
+
} catch CapacitorDataStorageSqliteError.failed(let message) {
|
|
535
|
+
let msg = "exportToJson: \(message)"
|
|
536
|
+
retHandler.rJsonStore(call: call, ret: [:],
|
|
537
|
+
message: msg)
|
|
538
|
+
return
|
|
539
|
+
} catch let error {
|
|
540
|
+
let msg = "exportToJson: \(error.localizedDescription)"
|
|
541
|
+
retHandler.rJsonStore(call: call, ret: [:],
|
|
542
|
+
message: msg)
|
|
543
|
+
return
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
}
|
|
549
|
+
// swiftlint:enable type_body_length
|
|
550
|
+
// swiftlint:enable file_length
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Data.swift
|
|
3
|
+
// Plugin
|
|
4
|
+
//
|
|
5
|
+
// Created by Quéau Jean Pierre on 08/04/2021.
|
|
6
|
+
// Copyright © 2021 Max Lynch. All rights reserved.
|
|
7
|
+
//
|
|
8
|
+
|
|
9
|
+
import Foundation
|
|
10
|
+
// swiftlint:disable identifier_name
|
|
11
|
+
struct Data {
|
|
12
|
+
var id: Int64?
|
|
13
|
+
var name: String?
|
|
14
|
+
var value: String?
|
|
15
|
+
}
|
|
16
|
+
// swiftlint:enable identifier_name
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Global.swift
|
|
3
|
+
// Plugin
|
|
4
|
+
//
|
|
5
|
+
// Created by Quéau Jean Pierre on 08/04/2021.
|
|
6
|
+
// Copyright © 2021 Max Lynch. All rights reserved.
|
|
7
|
+
//
|
|
8
|
+
|
|
9
|
+
import Foundation
|
|
10
|
+
struct Global {
|
|
11
|
+
var secret: String = "test secret"
|
|
12
|
+
var newsecret: String = "test new secret"
|
|
13
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
//
|
|
2
|
+
// JsonStore.swift
|
|
3
|
+
// Plugin
|
|
4
|
+
//
|
|
5
|
+
// Created by Quéau Jean Pierre on 05/09/2021.
|
|
6
|
+
// Copyright © 2021 Max Lynch. All rights reserved.
|
|
7
|
+
//
|
|
8
|
+
|
|
9
|
+
import Foundation
|
|
10
|
+
public struct JsonStore: Codable {
|
|
11
|
+
let database: String
|
|
12
|
+
let encrypted: Bool
|
|
13
|
+
let tables: [JsonTable]
|
|
14
|
+
|
|
15
|
+
public func show() {
|
|
16
|
+
print("databaseName: \(database) ")
|
|
17
|
+
print("encrypted: \(encrypted) ")
|
|
18
|
+
print("Number of Tables: \(tables.count) ")
|
|
19
|
+
for table in tables {
|
|
20
|
+
table.show()
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
public struct JsonTable: Codable {
|
|
26
|
+
let name: String
|
|
27
|
+
let values: [JsonValue]
|
|
28
|
+
|
|
29
|
+
public func show() {
|
|
30
|
+
print("name: \(name) ")
|
|
31
|
+
if values.count > 0 {
|
|
32
|
+
print("Number of Values: \(values.count) ")
|
|
33
|
+
for val in values {
|
|
34
|
+
val.show()
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
public struct JsonValue: Codable {
|
|
41
|
+
let key: String
|
|
42
|
+
let value: String
|
|
43
|
+
|
|
44
|
+
public func show() {
|
|
45
|
+
print("key: \(key) value: \(value)")
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
3
|
+
<plist version="1.0">
|
|
4
|
+
<dict>
|
|
5
|
+
<key>CFBundleDevelopmentRegion</key>
|
|
6
|
+
<string>$(DEVELOPMENT_LANGUAGE)</string>
|
|
7
|
+
<key>CFBundleExecutable</key>
|
|
8
|
+
<string>$(EXECUTABLE_NAME)</string>
|
|
9
|
+
<key>CFBundleIdentifier</key>
|
|
10
|
+
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
|
|
11
|
+
<key>CFBundleInfoDictionaryVersion</key>
|
|
12
|
+
<string>6.0</string>
|
|
13
|
+
<key>CFBundleName</key>
|
|
14
|
+
<string>$(PRODUCT_NAME)</string>
|
|
15
|
+
<key>CFBundlePackageType</key>
|
|
16
|
+
<string>FMWK</string>
|
|
17
|
+
<key>CFBundleShortVersionString</key>
|
|
18
|
+
<string>1.0</string>
|
|
19
|
+
<key>CFBundleVersion</key>
|
|
20
|
+
<string>$(CURRENT_PROJECT_VERSION)</string>
|
|
21
|
+
<key>NSPrincipalClass</key>
|
|
22
|
+
<string></string>
|
|
23
|
+
</dict>
|
|
24
|
+
</plist>
|