@unvired/cordova-plugin-unvired-electron-db 0.0.40 → 0.0.41
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/package.json +1 -1
- package/plugin.xml +1 -1
- package/src/browser/DbPluginProxy.js +54 -36
- package/src/electron/package.json +1 -1
package/package.json
CHANGED
package/plugin.xml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<?xml version='1.0' encoding='utf-8'?>
|
|
2
2
|
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
|
|
3
3
|
id="@unvired/cordova-plugin-unvired-electron-db"
|
|
4
|
-
version="0.0.
|
|
4
|
+
version="0.0.41"
|
|
5
5
|
xmlns:android="http://schemas.android.com/apk/res/android">
|
|
6
6
|
<name>Unvired DB</name>
|
|
7
7
|
<description>Unvired DB Native Support for Cordova</description>
|
|
@@ -18,6 +18,7 @@ module.exports.create = async function (sucessCallback, errorCallback, options)
|
|
|
18
18
|
sucessCallback(dbCreationResponse);
|
|
19
19
|
}
|
|
20
20
|
catch (err) {
|
|
21
|
+
console.error("Error creating DB:", err);
|
|
21
22
|
errorCallback(err);
|
|
22
23
|
}
|
|
23
24
|
};
|
|
@@ -53,6 +54,7 @@ module.exports.execute = async function (sucessCallback, errorCallback, options)
|
|
|
53
54
|
}
|
|
54
55
|
}
|
|
55
56
|
catch (err) {
|
|
57
|
+
console.error("Error executing query: " + query, err);
|
|
56
58
|
errorCallback(err);
|
|
57
59
|
}
|
|
58
60
|
};
|
|
@@ -65,6 +67,7 @@ module.exports.close = async function (sucessCallback, errorCallback, options) {
|
|
|
65
67
|
sucessCallback(true);
|
|
66
68
|
}
|
|
67
69
|
catch (err) {
|
|
70
|
+
console.error("Error closing DB:", err);
|
|
68
71
|
errorCallback(err);
|
|
69
72
|
}
|
|
70
73
|
};
|
|
@@ -154,56 +157,66 @@ var webDb = /** @class */ (function () {
|
|
|
154
157
|
|
|
155
158
|
webDb.initialize = async function (userId) {
|
|
156
159
|
var initSqlJs = window.initSqlJs;
|
|
157
|
-
config = {
|
|
158
|
-
locateFile: filename => "assets/js/sql-wasm.wasm"
|
|
160
|
+
var config = {
|
|
161
|
+
locateFile: filename => "assets/js/sql-wasm.wasm",
|
|
162
|
+
// INITIAL_MEMORY: 268435456 // 256MB
|
|
159
163
|
};
|
|
160
164
|
try {
|
|
161
165
|
let SQL = await initSqlJs(config);
|
|
162
166
|
if (webDb.fwDb == null) {
|
|
163
|
-
|
|
167
|
+
let data = await webDb.getDataFromIndexedDB(userId + "_fw_db", "fwData");
|
|
168
|
+
if (data) {
|
|
169
|
+
console.log("Initializing fwDb with data size: " + (data.byteLength || data.length));
|
|
170
|
+
webDb.fwDb = new SQL.Database(data);
|
|
171
|
+
} else {
|
|
172
|
+
webDb.fwDb = new SQL.Database();
|
|
173
|
+
}
|
|
164
174
|
// Set PRAGMA for framework database
|
|
165
175
|
webDb.fwDb.run("PRAGMA journal_mode = WAL;");
|
|
166
176
|
webDb.fwDb.run("PRAGMA read_uncommitted = 1;");
|
|
167
|
-
await webDb.populateWebDb(SQL, true, userId);
|
|
168
177
|
}
|
|
169
178
|
if (webDb.appDb == null) {
|
|
170
|
-
|
|
179
|
+
let data = await webDb.getDataFromIndexedDB(userId + "_app_db", "appData");
|
|
180
|
+
if (data) {
|
|
181
|
+
console.log("Initializing appDb with data size: " + (data.byteLength || data.length));
|
|
182
|
+
webDb.appDb = new SQL.Database(data);
|
|
183
|
+
} else {
|
|
184
|
+
webDb.appDb = new SQL.Database();
|
|
185
|
+
}
|
|
171
186
|
// Set PRAGMA for app database
|
|
172
187
|
webDb.appDb.run("PRAGMA journal_mode = WAL;");
|
|
173
188
|
webDb.appDb.run("PRAGMA read_uncommitted = 1;");
|
|
174
189
|
webDb.appDb.run("PRAGMA foreign_keys = ON;");
|
|
175
|
-
await webDb.populateWebDb(SQL, false, userId);
|
|
176
190
|
}
|
|
177
191
|
return "DB Created Successfully";
|
|
178
192
|
}
|
|
179
193
|
catch (err) {
|
|
194
|
+
console.error("Error initializing DB:", err);
|
|
180
195
|
throw err;
|
|
181
196
|
}
|
|
182
197
|
};
|
|
183
198
|
|
|
184
|
-
webDb.
|
|
199
|
+
webDb.getDataFromIndexedDB = function (dbName, storeName) {
|
|
185
200
|
return new Promise((resolve, reject) => {
|
|
186
201
|
var db;
|
|
187
|
-
var request =
|
|
188
|
-
var storeName = isFwDb ? "fwData" : "appData";
|
|
202
|
+
var request = window.indexedDB.open(dbName);
|
|
189
203
|
request.onupgradeneeded = function (event) {
|
|
190
204
|
db = event.target.result;
|
|
191
205
|
db.createObjectStore(storeName, { keyPath: "id" });
|
|
192
|
-
resolve();
|
|
193
206
|
};
|
|
194
207
|
request.onerror = function (event) {
|
|
195
208
|
console.log("The database failed to open: " + event);
|
|
196
|
-
resolve();
|
|
209
|
+
resolve(null);
|
|
197
210
|
};
|
|
198
211
|
request.onsuccess = function (event) {
|
|
199
212
|
db = request.result;
|
|
200
213
|
if (!db.objectStoreNames.contains(storeName)) {
|
|
201
|
-
resolve();
|
|
214
|
+
resolve(null);
|
|
202
215
|
return;
|
|
203
216
|
}
|
|
204
217
|
|
|
205
218
|
db.onversionchange = function() {
|
|
206
|
-
console.log('Unvired Plugin Proxy: Received version change event
|
|
219
|
+
console.log('Unvired Plugin Proxy: Received version change event. Closing the database connection.')
|
|
207
220
|
db.close()
|
|
208
221
|
}
|
|
209
222
|
|
|
@@ -213,19 +226,15 @@ var webDb = /** @class */ (function () {
|
|
|
213
226
|
|
|
214
227
|
dataRequest.onerror = function (event) {
|
|
215
228
|
console.log("Unable to read " + storeName + " index DB table");
|
|
216
|
-
resolve();
|
|
229
|
+
resolve(null);
|
|
217
230
|
};
|
|
218
231
|
dataRequest.onsuccess = function (event) {
|
|
219
|
-
if (dataRequest.result) {
|
|
220
|
-
|
|
221
|
-
webDb.fwDb = new SQL.Database(dataRequest.result.data);
|
|
222
|
-
} else {
|
|
223
|
-
webDb.appDb = new SQL.Database(dataRequest.result.data);
|
|
224
|
-
}
|
|
232
|
+
if (dataRequest.result && dataRequest.result.data) {
|
|
233
|
+
resolve(dataRequest.result.data);
|
|
225
234
|
} else {
|
|
226
|
-
console.log("
|
|
235
|
+
console.log("No data found in " + storeName);
|
|
236
|
+
resolve(null);
|
|
227
237
|
}
|
|
228
|
-
resolve();
|
|
229
238
|
};
|
|
230
239
|
};
|
|
231
240
|
});
|
|
@@ -294,23 +303,27 @@ var webDb = /** @class */ (function () {
|
|
|
294
303
|
if (ch === "'") {
|
|
295
304
|
// start of quoted string; find the closing quote handling escaped ''
|
|
296
305
|
let j = i + 1;
|
|
297
|
-
let inner = '';
|
|
298
306
|
let closed = false;
|
|
307
|
+
|
|
299
308
|
while (j < len) {
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
if (
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
continue;
|
|
307
|
-
} else {
|
|
308
|
-
closed = true;
|
|
309
|
-
break; // closing quote at j
|
|
309
|
+
if (query.charAt(j) !== "'") {
|
|
310
|
+
// Optimize: Skip to the next single quote
|
|
311
|
+
const nextQuote = query.indexOf("'", j);
|
|
312
|
+
if (nextQuote === -1) {
|
|
313
|
+
j = len; // Not found
|
|
314
|
+
break;
|
|
310
315
|
}
|
|
316
|
+
j = nextQuote;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
// We found a quote at index j
|
|
320
|
+
if (j + 1 < len && query.charAt(j + 1) === "'") {
|
|
321
|
+
// It is an escaped quote (''), skip both characters
|
|
322
|
+
j += 2;
|
|
311
323
|
} else {
|
|
312
|
-
|
|
313
|
-
|
|
324
|
+
// It is a closing quote
|
|
325
|
+
closed = true;
|
|
326
|
+
break;
|
|
314
327
|
}
|
|
315
328
|
}
|
|
316
329
|
|
|
@@ -319,10 +332,15 @@ var webDb = /** @class */ (function () {
|
|
|
319
332
|
return { isPrepared: false, query: query, values: [] };
|
|
320
333
|
}
|
|
321
334
|
|
|
335
|
+
// Extract content and handle escaped quotes
|
|
336
|
+
const rawContent = query.slice(i + 1, j);
|
|
337
|
+
const inner = rawContent.replace(/''/g, "'");
|
|
338
|
+
|
|
322
339
|
// Append text before this literal
|
|
323
340
|
preparedQuery += query.slice(lastIndex, i);
|
|
324
341
|
|
|
325
|
-
|
|
342
|
+
// Optimize: Check length first to avoid toUpperCase() on large strings
|
|
343
|
+
if (inner.length === 4 && inner.toUpperCase() === 'NULL') {
|
|
326
344
|
// keep quoted NULL as-is
|
|
327
345
|
preparedQuery += query.slice(i, j + 1);
|
|
328
346
|
} else {
|