@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,633 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var core = require('@capacitor/core');
|
|
4
|
+
var localForage = require('localforage');
|
|
5
|
+
|
|
6
|
+
const CapacitorDataStorageSqlite = core.registerPlugin("CapacitorDataStorageSqlite", {
|
|
7
|
+
web: () => Promise.resolve().then(function () { return web; }).then((m) => new m.CapacitorDataStorageSqliteWeb()),
|
|
8
|
+
electron: () => window.CapacitorCustomPlatform.plugins
|
|
9
|
+
.CapacitorDataStorageSqlite,
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
class Data {
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
//import LocalForage from 'jeep-localforage';
|
|
16
|
+
//const DATABASE: string = "storageIDB";
|
|
17
|
+
//const STORAGESTORE: string = "storage_store";
|
|
18
|
+
class StorageDatabaseHelper {
|
|
19
|
+
constructor(dbName, tableName) {
|
|
20
|
+
this._db = null;
|
|
21
|
+
const res = this.openStore(dbName, tableName);
|
|
22
|
+
if (res) {
|
|
23
|
+
this._dbName = dbName;
|
|
24
|
+
this._tableName = tableName;
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
this._dbName = "";
|
|
28
|
+
this._tableName = "";
|
|
29
|
+
throw new Error("openStore return false");
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
openStore(dbName, tableName) {
|
|
33
|
+
let ret = false;
|
|
34
|
+
const config = this.setConfig(dbName, tableName);
|
|
35
|
+
this._db = localForage.createInstance(config);
|
|
36
|
+
if (this._db != null) {
|
|
37
|
+
this._dbName = dbName;
|
|
38
|
+
ret = true;
|
|
39
|
+
}
|
|
40
|
+
return ret;
|
|
41
|
+
}
|
|
42
|
+
setConfig(dbName, tableName) {
|
|
43
|
+
const config = {
|
|
44
|
+
name: dbName,
|
|
45
|
+
storeName: tableName,
|
|
46
|
+
driver: [localForage.INDEXEDDB, localForage.WEBSQL],
|
|
47
|
+
version: 1,
|
|
48
|
+
};
|
|
49
|
+
return config;
|
|
50
|
+
}
|
|
51
|
+
async setTable(tableName) {
|
|
52
|
+
const res = this.openStore(this._dbName, tableName);
|
|
53
|
+
if (res) {
|
|
54
|
+
return Promise.resolve();
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
return Promise.reject(new Error("openStore return false"));
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
async isTable(table) {
|
|
61
|
+
if (this._db == null) {
|
|
62
|
+
return Promise.reject(`isTable: this.db is null`);
|
|
63
|
+
}
|
|
64
|
+
try {
|
|
65
|
+
let ret = false;
|
|
66
|
+
const tables = await this.tables();
|
|
67
|
+
if (tables.includes(table))
|
|
68
|
+
ret = true;
|
|
69
|
+
return Promise.resolve(ret);
|
|
70
|
+
}
|
|
71
|
+
catch (err) {
|
|
72
|
+
return Promise.reject(err);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
async tables() {
|
|
76
|
+
return new Promise((resolve, reject) => {
|
|
77
|
+
// Let us open our database
|
|
78
|
+
const DBOpenRequest = window.indexedDB.open(this._dbName);
|
|
79
|
+
// these two event handlers act on the database being opened successfully, or not
|
|
80
|
+
DBOpenRequest.onerror = () => {
|
|
81
|
+
return reject(`Error loading database ${this._dbName}`);
|
|
82
|
+
};
|
|
83
|
+
DBOpenRequest.onsuccess = () => {
|
|
84
|
+
let result = [];
|
|
85
|
+
const db = DBOpenRequest.result;
|
|
86
|
+
const retList = db.objectStoreNames;
|
|
87
|
+
const values = Object.values(retList);
|
|
88
|
+
for (const val of values) {
|
|
89
|
+
if (val.substring(0, 12) != "local-forage") {
|
|
90
|
+
result = [...result, val];
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return resolve(result);
|
|
94
|
+
};
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
async set(data) {
|
|
98
|
+
try {
|
|
99
|
+
await this._db.setItem(data.name, data.value);
|
|
100
|
+
return Promise.resolve();
|
|
101
|
+
}
|
|
102
|
+
catch (err) {
|
|
103
|
+
return Promise.reject(err);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
async get(name) {
|
|
107
|
+
try {
|
|
108
|
+
const value = await this._db.getItem(name);
|
|
109
|
+
const data = new Data();
|
|
110
|
+
data.name = name;
|
|
111
|
+
data.value = value;
|
|
112
|
+
return Promise.resolve(data);
|
|
113
|
+
}
|
|
114
|
+
catch (err) {
|
|
115
|
+
return Promise.reject(err);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
async remove(name) {
|
|
119
|
+
return this._db
|
|
120
|
+
.removeItem(name)
|
|
121
|
+
.then(() => {
|
|
122
|
+
return Promise.resolve();
|
|
123
|
+
})
|
|
124
|
+
.catch((error) => {
|
|
125
|
+
return Promise.reject(error);
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
async clear() {
|
|
129
|
+
return this._db
|
|
130
|
+
.clear()
|
|
131
|
+
.then(() => {
|
|
132
|
+
return Promise.resolve();
|
|
133
|
+
})
|
|
134
|
+
.catch((error) => {
|
|
135
|
+
return Promise.reject(error);
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
async keys() {
|
|
139
|
+
return this._db
|
|
140
|
+
.keys()
|
|
141
|
+
.then((keys) => {
|
|
142
|
+
return Promise.resolve(keys);
|
|
143
|
+
})
|
|
144
|
+
.catch((error) => {
|
|
145
|
+
return Promise.reject(error);
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
async values() {
|
|
149
|
+
const values = [];
|
|
150
|
+
return this._db
|
|
151
|
+
.iterate((value) => {
|
|
152
|
+
values.push(value);
|
|
153
|
+
})
|
|
154
|
+
.then(() => {
|
|
155
|
+
return Promise.resolve(values);
|
|
156
|
+
})
|
|
157
|
+
.catch((error) => {
|
|
158
|
+
return Promise.reject(error);
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
async keysvalues() {
|
|
162
|
+
const keysvalues = [];
|
|
163
|
+
return this._db
|
|
164
|
+
.iterate((value, key) => {
|
|
165
|
+
const data = new Data();
|
|
166
|
+
data.name = key;
|
|
167
|
+
data.value = value;
|
|
168
|
+
keysvalues.push(data);
|
|
169
|
+
})
|
|
170
|
+
.then(() => {
|
|
171
|
+
return Promise.resolve(keysvalues);
|
|
172
|
+
})
|
|
173
|
+
.catch((error) => {
|
|
174
|
+
return Promise.reject(error);
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
async iskey(name) {
|
|
178
|
+
return this.get(name)
|
|
179
|
+
.then((data) => {
|
|
180
|
+
if (data.value != null) {
|
|
181
|
+
return Promise.resolve(true);
|
|
182
|
+
}
|
|
183
|
+
else {
|
|
184
|
+
return Promise.resolve(false);
|
|
185
|
+
}
|
|
186
|
+
})
|
|
187
|
+
.catch((error) => {
|
|
188
|
+
return Promise.reject(error);
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
async importJson(values) {
|
|
192
|
+
let changes = 0;
|
|
193
|
+
for (const val of values) {
|
|
194
|
+
try {
|
|
195
|
+
const data = new Data();
|
|
196
|
+
data.name = val.key;
|
|
197
|
+
data.value = val.value;
|
|
198
|
+
await this.set(data);
|
|
199
|
+
changes += 1;
|
|
200
|
+
}
|
|
201
|
+
catch (err) {
|
|
202
|
+
return Promise.reject(err);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
return Promise.resolve(changes);
|
|
206
|
+
}
|
|
207
|
+
async exportJson() {
|
|
208
|
+
const retJson = {};
|
|
209
|
+
const prevTableName = this._tableName;
|
|
210
|
+
try {
|
|
211
|
+
retJson.database = this._dbName.slice(0, -3);
|
|
212
|
+
retJson.encrypted = false;
|
|
213
|
+
retJson.tables = [];
|
|
214
|
+
// get the table list
|
|
215
|
+
const tables = await this.tables();
|
|
216
|
+
for (const table of tables) {
|
|
217
|
+
this._tableName = table;
|
|
218
|
+
const retTable = {};
|
|
219
|
+
retTable.name = table;
|
|
220
|
+
retTable.values = [];
|
|
221
|
+
const res = this.openStore(this._dbName, this._tableName);
|
|
222
|
+
if (res) {
|
|
223
|
+
const dataTable = await this.keysvalues();
|
|
224
|
+
for (const tdata of dataTable) {
|
|
225
|
+
const retData = {};
|
|
226
|
+
if (tdata.name != null) {
|
|
227
|
+
retData.key = tdata.name;
|
|
228
|
+
retData.value = tdata.value;
|
|
229
|
+
retTable.values = [...retTable.values, retData];
|
|
230
|
+
}
|
|
231
|
+
else {
|
|
232
|
+
return Promise.reject("Data.name is undefined");
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
retJson.tables = [...retJson.tables, retTable];
|
|
236
|
+
}
|
|
237
|
+
else {
|
|
238
|
+
const msg = `Could not open ${this._dbName} ${this._tableName} `;
|
|
239
|
+
this._tableName = prevTableName;
|
|
240
|
+
return Promise.reject(msg);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
this._tableName = prevTableName;
|
|
244
|
+
const res = this.openStore(this._dbName, this._tableName);
|
|
245
|
+
if (res) {
|
|
246
|
+
return Promise.resolve(retJson);
|
|
247
|
+
}
|
|
248
|
+
else {
|
|
249
|
+
const msg = `Could not open ${this._dbName} ${this._tableName} `;
|
|
250
|
+
return Promise.reject(msg);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
catch (err) {
|
|
254
|
+
this._tableName = prevTableName;
|
|
255
|
+
return Promise.reject(err);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* IsJsonSQLite
|
|
262
|
+
* @param obj
|
|
263
|
+
*/
|
|
264
|
+
const isJsonStore = (obj) => {
|
|
265
|
+
const keyFirstLevel = ["database", "encrypted", "tables"];
|
|
266
|
+
if (obj == null ||
|
|
267
|
+
(Object.keys(obj).length === 0 && obj.constructor === Object))
|
|
268
|
+
return false;
|
|
269
|
+
for (const key of Object.keys(obj)) {
|
|
270
|
+
if (keyFirstLevel.indexOf(key) === -1)
|
|
271
|
+
return false;
|
|
272
|
+
if (key === "database" && typeof obj[key] != "string")
|
|
273
|
+
return false;
|
|
274
|
+
if (key === "encrypted" && typeof obj[key] != "boolean")
|
|
275
|
+
return false;
|
|
276
|
+
if (key === "tables" && typeof obj[key] != "object")
|
|
277
|
+
return false;
|
|
278
|
+
if (key === "tables") {
|
|
279
|
+
for (const oKey of obj[key]) {
|
|
280
|
+
const retTable = isTable(oKey);
|
|
281
|
+
if (!retTable)
|
|
282
|
+
return false;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
return true;
|
|
287
|
+
};
|
|
288
|
+
/**
|
|
289
|
+
* IsTable
|
|
290
|
+
* @param obj
|
|
291
|
+
*/
|
|
292
|
+
const isTable = (obj) => {
|
|
293
|
+
const keyTableLevel = ["name", "values"];
|
|
294
|
+
if (obj == null ||
|
|
295
|
+
(Object.keys(obj).length === 0 && obj.constructor === Object)) {
|
|
296
|
+
return false;
|
|
297
|
+
}
|
|
298
|
+
for (const key of Object.keys(obj)) {
|
|
299
|
+
if (keyTableLevel.indexOf(key) === -1)
|
|
300
|
+
return false;
|
|
301
|
+
if (key === "name" && typeof obj[key] != "string")
|
|
302
|
+
return false;
|
|
303
|
+
if (key === "values" && typeof obj[key] != "object")
|
|
304
|
+
return false;
|
|
305
|
+
if (key === "values") {
|
|
306
|
+
for (const oKey of obj[key]) {
|
|
307
|
+
const retValue = isValue(oKey);
|
|
308
|
+
if (!retValue)
|
|
309
|
+
return false;
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
return true;
|
|
314
|
+
};
|
|
315
|
+
/**
|
|
316
|
+
* IsValue
|
|
317
|
+
* @param obj
|
|
318
|
+
*/
|
|
319
|
+
const isValue = (obj) => {
|
|
320
|
+
const keyTableLevel = ["key", "value"];
|
|
321
|
+
if (obj == null ||
|
|
322
|
+
(Object.keys(obj).length === 0 && obj.constructor === Object)) {
|
|
323
|
+
return false;
|
|
324
|
+
}
|
|
325
|
+
for (const key of Object.keys(obj)) {
|
|
326
|
+
if (keyTableLevel.indexOf(key) === -1)
|
|
327
|
+
return false;
|
|
328
|
+
if (key === "key" && typeof obj[key] != "string")
|
|
329
|
+
return false;
|
|
330
|
+
if (key === "value" && typeof obj[key] != "string")
|
|
331
|
+
return false;
|
|
332
|
+
}
|
|
333
|
+
return true;
|
|
334
|
+
};
|
|
335
|
+
|
|
336
|
+
class CapacitorDataStorageSqliteWeb extends core.WebPlugin {
|
|
337
|
+
async echo(options) {
|
|
338
|
+
const ret = {};
|
|
339
|
+
ret.value = options.value ? options.value : "";
|
|
340
|
+
return ret;
|
|
341
|
+
}
|
|
342
|
+
async openStore(options) {
|
|
343
|
+
const dbName = options.database ? `${options.database}IDB` : "storageIDB";
|
|
344
|
+
const tableName = options.table ? options.table : "storage_store";
|
|
345
|
+
try {
|
|
346
|
+
this.mDb = new StorageDatabaseHelper(dbName, tableName);
|
|
347
|
+
return Promise.resolve();
|
|
348
|
+
}
|
|
349
|
+
catch (err) {
|
|
350
|
+
return Promise.reject(`OpenStore: ${err.message}`);
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
async closeStore(options) {
|
|
354
|
+
throw new Error(`Method closeStore not implemented. ${options}`);
|
|
355
|
+
}
|
|
356
|
+
async isStoreOpen(options) {
|
|
357
|
+
throw new Error(`Method isStoreOpen not implemented. ${options}`);
|
|
358
|
+
}
|
|
359
|
+
async isStoreExists(options) {
|
|
360
|
+
throw new Error(`Method isStoreExists not implemented. ${options}`);
|
|
361
|
+
}
|
|
362
|
+
async setTable(options) {
|
|
363
|
+
const tableName = options.table;
|
|
364
|
+
if (tableName == null) {
|
|
365
|
+
return Promise.reject("SetTable: Must provide a table name");
|
|
366
|
+
}
|
|
367
|
+
if (this.mDb) {
|
|
368
|
+
try {
|
|
369
|
+
await this.mDb.setTable(tableName);
|
|
370
|
+
return Promise.resolve();
|
|
371
|
+
}
|
|
372
|
+
catch (err) {
|
|
373
|
+
return Promise.reject(`SetTable: ${err.message}`);
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
else {
|
|
377
|
+
return Promise.reject("SetTable: Must open a store first");
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
async set(options) {
|
|
381
|
+
const key = options.key;
|
|
382
|
+
if (key == null || typeof key != "string") {
|
|
383
|
+
return Promise.reject("Set: Must provide key as string");
|
|
384
|
+
}
|
|
385
|
+
const value = options.value ? options.value : null;
|
|
386
|
+
if (value == null || typeof value != "string") {
|
|
387
|
+
return Promise.reject("Set: Must provide value as string");
|
|
388
|
+
}
|
|
389
|
+
const data = new Data();
|
|
390
|
+
data.name = key;
|
|
391
|
+
data.value = value;
|
|
392
|
+
try {
|
|
393
|
+
await this.mDb.set(data);
|
|
394
|
+
return Promise.resolve();
|
|
395
|
+
}
|
|
396
|
+
catch (err) {
|
|
397
|
+
return Promise.reject(`Set: ${err.message}`);
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
async get(options) {
|
|
401
|
+
const key = options.key;
|
|
402
|
+
if (key == null || typeof key != "string") {
|
|
403
|
+
return Promise.reject("Get: Must provide key as string");
|
|
404
|
+
}
|
|
405
|
+
try {
|
|
406
|
+
const data = await this.mDb.get(key);
|
|
407
|
+
if ((data === null || data === void 0 ? void 0 : data.value) != null) {
|
|
408
|
+
return Promise.resolve({ value: data.value });
|
|
409
|
+
}
|
|
410
|
+
else {
|
|
411
|
+
return Promise.resolve({ value: "" });
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
catch (err) {
|
|
415
|
+
return Promise.reject(`Get: ${err.message}`);
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
async remove(options) {
|
|
419
|
+
const key = options.key;
|
|
420
|
+
if (key == null || typeof key != "string") {
|
|
421
|
+
return Promise.reject("Remove: Must provide key as string");
|
|
422
|
+
}
|
|
423
|
+
try {
|
|
424
|
+
await this.mDb.remove(key);
|
|
425
|
+
return Promise.resolve();
|
|
426
|
+
}
|
|
427
|
+
catch (err) {
|
|
428
|
+
return Promise.reject(`Remove: ${err.message}`);
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
async clear() {
|
|
432
|
+
try {
|
|
433
|
+
await this.mDb.clear();
|
|
434
|
+
return Promise.resolve();
|
|
435
|
+
}
|
|
436
|
+
catch (err) {
|
|
437
|
+
return Promise.reject(`Clear: ${err.message}`);
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
async iskey(options) {
|
|
441
|
+
const key = options.key;
|
|
442
|
+
if (key == null || typeof key != "string") {
|
|
443
|
+
return Promise.reject("Iskey: Must provide key as string");
|
|
444
|
+
}
|
|
445
|
+
try {
|
|
446
|
+
const ret = await this.mDb.iskey(key);
|
|
447
|
+
return Promise.resolve({ result: ret });
|
|
448
|
+
}
|
|
449
|
+
catch (err) {
|
|
450
|
+
return Promise.reject(`Iskey: ${err.message}`);
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
async keys() {
|
|
454
|
+
try {
|
|
455
|
+
const ret = await this.mDb.keys();
|
|
456
|
+
return Promise.resolve({ keys: ret });
|
|
457
|
+
}
|
|
458
|
+
catch (err) {
|
|
459
|
+
return Promise.reject(`Keys: ${err.message}`);
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
async values() {
|
|
463
|
+
try {
|
|
464
|
+
const ret = await this.mDb.values();
|
|
465
|
+
return Promise.resolve({ values: ret });
|
|
466
|
+
}
|
|
467
|
+
catch (err) {
|
|
468
|
+
return Promise.reject(`Values: ${err.message}`);
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
async filtervalues(options) {
|
|
472
|
+
const filter = options.filter;
|
|
473
|
+
if (filter == null || typeof filter != "string") {
|
|
474
|
+
return Promise.reject("Filtervalues: Must provide filter as string");
|
|
475
|
+
}
|
|
476
|
+
let regFilter;
|
|
477
|
+
if (filter.startsWith("%")) {
|
|
478
|
+
regFilter = new RegExp("^" + filter.substring(1), "i");
|
|
479
|
+
}
|
|
480
|
+
else if (filter.endsWith("%")) {
|
|
481
|
+
regFilter = new RegExp(filter.slice(0, -1) + "$", "i");
|
|
482
|
+
}
|
|
483
|
+
else {
|
|
484
|
+
regFilter = new RegExp(filter, "i");
|
|
485
|
+
}
|
|
486
|
+
try {
|
|
487
|
+
const ret = [];
|
|
488
|
+
const results = await this.mDb.keysvalues();
|
|
489
|
+
for (const result of results) {
|
|
490
|
+
if (result.name != null && regFilter.test(result.name)) {
|
|
491
|
+
if (result.value != null) {
|
|
492
|
+
ret.push(result.value);
|
|
493
|
+
}
|
|
494
|
+
else {
|
|
495
|
+
return Promise.reject(`Filtervalues: result.value is null`);
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
return Promise.resolve({ values: ret });
|
|
500
|
+
}
|
|
501
|
+
catch (err) {
|
|
502
|
+
return Promise.reject(`Filtervalues: ${err.message}`);
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
async keysvalues() {
|
|
506
|
+
try {
|
|
507
|
+
const ret = [];
|
|
508
|
+
const results = await this.mDb.keysvalues();
|
|
509
|
+
for (const result of results) {
|
|
510
|
+
if (result.name != null && result.value != null) {
|
|
511
|
+
const res = { key: result.name, value: result.value };
|
|
512
|
+
ret.push(res);
|
|
513
|
+
}
|
|
514
|
+
else {
|
|
515
|
+
return Promise.reject(`Keysvalues: result.name/value are null`);
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
return Promise.resolve({ keysvalues: ret });
|
|
519
|
+
}
|
|
520
|
+
catch (err) {
|
|
521
|
+
return Promise.reject(`Keysvalues: ${err.message}`);
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
async deleteStore(options) {
|
|
525
|
+
throw new Error(`Method deleteStore not implemented. ${options}`);
|
|
526
|
+
}
|
|
527
|
+
async isTable(options) {
|
|
528
|
+
const table = options.table;
|
|
529
|
+
if (table == null) {
|
|
530
|
+
return Promise.reject("Must provide a Table Name");
|
|
531
|
+
}
|
|
532
|
+
try {
|
|
533
|
+
const ret = await this.mDb.isTable(table);
|
|
534
|
+
return Promise.resolve({ result: ret });
|
|
535
|
+
}
|
|
536
|
+
catch (err) {
|
|
537
|
+
return Promise.reject(err);
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
async tables() {
|
|
541
|
+
try {
|
|
542
|
+
const ret = await this.mDb.tables();
|
|
543
|
+
return Promise.resolve({ tables: ret });
|
|
544
|
+
}
|
|
545
|
+
catch (err) {
|
|
546
|
+
return Promise.reject(err);
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
async deleteTable(options) {
|
|
550
|
+
throw new Error(`Method deleteTable not implemented. ${options}`);
|
|
551
|
+
}
|
|
552
|
+
async importFromJson(options) {
|
|
553
|
+
const keys = Object.keys(options);
|
|
554
|
+
if (!keys.includes("jsonstring")) {
|
|
555
|
+
return Promise.reject("Must provide a json object");
|
|
556
|
+
}
|
|
557
|
+
let totalChanges = 0;
|
|
558
|
+
if (options === null || options === void 0 ? void 0 : options.jsonstring) {
|
|
559
|
+
const jsonStrObj = options.jsonstring;
|
|
560
|
+
const jsonObj = JSON.parse(jsonStrObj);
|
|
561
|
+
const isValid = isJsonStore(jsonObj);
|
|
562
|
+
if (!isValid) {
|
|
563
|
+
return Promise.reject("Must provide a valid JsonSQLite Object");
|
|
564
|
+
}
|
|
565
|
+
const vJsonObj = jsonObj;
|
|
566
|
+
const dbName = vJsonObj.database
|
|
567
|
+
? `${vJsonObj.database}IDB`
|
|
568
|
+
: "storageIDB";
|
|
569
|
+
for (const table of vJsonObj.tables) {
|
|
570
|
+
const tableName = table.name ? table.name : "storage_store";
|
|
571
|
+
try {
|
|
572
|
+
this.mDb = new StorageDatabaseHelper(dbName, tableName);
|
|
573
|
+
// Open the database
|
|
574
|
+
const bRet = this.mDb.openStore(dbName, tableName);
|
|
575
|
+
if (bRet) {
|
|
576
|
+
// Import the JsonSQLite Object
|
|
577
|
+
if (table === null || table === void 0 ? void 0 : table.values) {
|
|
578
|
+
const changes = await this.mDb.importJson(table.values);
|
|
579
|
+
totalChanges += changes;
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
else {
|
|
583
|
+
return Promise.reject(`Open store: ${dbName} : table: ${tableName} failed`);
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
catch (err) {
|
|
587
|
+
return Promise.reject(`ImportFromJson: ${err.message}`);
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
return Promise.resolve({ changes: totalChanges });
|
|
591
|
+
}
|
|
592
|
+
else {
|
|
593
|
+
return Promise.reject("Must provide a json object");
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
async isJsonValid(options) {
|
|
597
|
+
const keys = Object.keys(options);
|
|
598
|
+
if (!keys.includes("jsonstring")) {
|
|
599
|
+
return Promise.reject("Must provide a json object");
|
|
600
|
+
}
|
|
601
|
+
if (options === null || options === void 0 ? void 0 : options.jsonstring) {
|
|
602
|
+
const jsonStrObj = options.jsonstring;
|
|
603
|
+
const jsonObj = JSON.parse(jsonStrObj);
|
|
604
|
+
const isValid = isJsonStore(jsonObj);
|
|
605
|
+
if (!isValid) {
|
|
606
|
+
return Promise.reject("Stringify Json Object not Valid");
|
|
607
|
+
}
|
|
608
|
+
else {
|
|
609
|
+
return Promise.resolve({ result: true });
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
else {
|
|
613
|
+
return Promise.reject("Must provide in options a stringify Json Object");
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
async exportToJson() {
|
|
617
|
+
try {
|
|
618
|
+
const ret = await this.mDb.exportJson();
|
|
619
|
+
return Promise.resolve({ export: ret });
|
|
620
|
+
}
|
|
621
|
+
catch (err) {
|
|
622
|
+
return Promise.reject(`exportToJson: ${err}`);
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
var web = /*#__PURE__*/Object.freeze({
|
|
628
|
+
__proto__: null,
|
|
629
|
+
CapacitorDataStorageSqliteWeb: CapacitorDataStorageSqliteWeb
|
|
630
|
+
});
|
|
631
|
+
|
|
632
|
+
exports.CapacitorDataStorageSqlite = CapacitorDataStorageSqlite;
|
|
633
|
+
//# sourceMappingURL=plugin.cjs.js.map
|