@capacitor-community/sqlite 3.4.1-1 → 3.4.1-4
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 +24 -1
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/CapacitorSQLite.java +14 -6
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/Database.java +24 -11
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/ImportExportJson/ExportToJson.java +5 -0
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/ImportExportJson/ImportFromJson.java +24 -15
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/ImportExportJson/UtilsJson.java +23 -0
- package/electron/dist/plugin.js +265 -198
- package/electron/dist/plugin.js.map +1 -1
- package/electron/rollup.config.js +18 -2
- package/ios/Plugin/BiometricIDAuthentication.swift +3 -0
- package/ios/Plugin/CapacitorSQLite.swift +4 -0
- package/ios/Plugin/CapacitorSQLitePlugin.swift +2 -0
- package/ios/Plugin/Database.swift +32 -9
- package/ios/Plugin/ImportExportJson/ExportToJson.swift +8 -0
- package/ios/Plugin/ImportExportJson/ImportFromJson.swift +20 -14
- package/ios/Plugin/Utils/UtilsJson.swift +28 -0
- package/package.json +4 -1
package/electron/dist/plugin.js
CHANGED
|
@@ -7,6 +7,7 @@ var require$$0$1 = require('path');
|
|
|
7
7
|
var require$$1 = require('fs');
|
|
8
8
|
var require$$2 = require('os');
|
|
9
9
|
var require$$3 = require('jszip');
|
|
10
|
+
var require$$4 = require('electron');
|
|
10
11
|
|
|
11
12
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
12
13
|
|
|
@@ -15,6 +16,7 @@ var require$$0__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$0$1);
|
|
|
15
16
|
var require$$1__default = /*#__PURE__*/_interopDefaultLegacy(require$$1);
|
|
16
17
|
var require$$2__default = /*#__PURE__*/_interopDefaultLegacy(require$$2);
|
|
17
18
|
var require$$3__default = /*#__PURE__*/_interopDefaultLegacy(require$$3);
|
|
19
|
+
var require$$4__default = /*#__PURE__*/_interopDefaultLegacy(require$$4);
|
|
18
20
|
|
|
19
21
|
var src = {};
|
|
20
22
|
|
|
@@ -435,12 +437,187 @@ utilsSQLite.UtilsSQLite = UtilsSQLite;
|
|
|
435
437
|
|
|
436
438
|
var utilsJson = {};
|
|
437
439
|
|
|
440
|
+
var utilsDrop = {};
|
|
441
|
+
|
|
442
|
+
Object.defineProperty(utilsDrop, "__esModule", { value: true });
|
|
443
|
+
utilsDrop.UtilsDrop = void 0;
|
|
444
|
+
const utilsSQLite_1$5 = utilsSQLite;
|
|
445
|
+
class UtilsDrop {
|
|
446
|
+
constructor() {
|
|
447
|
+
this._uSQLite = new utilsSQLite_1$5.UtilsSQLite();
|
|
448
|
+
}
|
|
449
|
+
/**
|
|
450
|
+
* GetTablesNames
|
|
451
|
+
* @param mDb
|
|
452
|
+
*/
|
|
453
|
+
async getTablesNames(mDb) {
|
|
454
|
+
let sql = 'SELECT name FROM sqlite_master WHERE ';
|
|
455
|
+
sql += "type='table' AND name NOT LIKE 'sync_table' ";
|
|
456
|
+
sql += "AND name NOT LIKE '_temp_%' ";
|
|
457
|
+
sql += "AND name NOT LIKE 'sqlite_%' ";
|
|
458
|
+
sql += 'ORDER BY rootpage DESC;';
|
|
459
|
+
const retArr = [];
|
|
460
|
+
try {
|
|
461
|
+
const retQuery = await this._uSQLite.queryAll(mDb, sql, []);
|
|
462
|
+
for (const query of retQuery) {
|
|
463
|
+
retArr.push(query.name);
|
|
464
|
+
}
|
|
465
|
+
return Promise.resolve(retArr);
|
|
466
|
+
}
|
|
467
|
+
catch (err) {
|
|
468
|
+
return Promise.reject(`getTablesNames: ${err}`);
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
/**
|
|
472
|
+
* GetViewsNames
|
|
473
|
+
* @param mDb
|
|
474
|
+
*/
|
|
475
|
+
async getViewsNames(mDb) {
|
|
476
|
+
let sql = 'SELECT name FROM sqlite_master WHERE ';
|
|
477
|
+
sql += "type='view' AND name NOT LIKE 'sqlite_%' ";
|
|
478
|
+
sql += 'ORDER BY rootpage DESC;';
|
|
479
|
+
const retArr = [];
|
|
480
|
+
try {
|
|
481
|
+
const retQuery = await this._uSQLite.queryAll(mDb, sql, []);
|
|
482
|
+
for (const query of retQuery) {
|
|
483
|
+
retArr.push(query.name);
|
|
484
|
+
}
|
|
485
|
+
return Promise.resolve(retArr);
|
|
486
|
+
}
|
|
487
|
+
catch (err) {
|
|
488
|
+
return Promise.reject(`getViewsNames: ${err}`);
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
/**
|
|
492
|
+
* DropElements
|
|
493
|
+
* @param db
|
|
494
|
+
* @param type ["table","index","trigger"]
|
|
495
|
+
*/
|
|
496
|
+
async dropElements(db, type) {
|
|
497
|
+
let msg = '';
|
|
498
|
+
switch (type) {
|
|
499
|
+
case 'index':
|
|
500
|
+
msg = 'DropIndexes';
|
|
501
|
+
break;
|
|
502
|
+
case 'trigger':
|
|
503
|
+
msg = 'DropTriggers';
|
|
504
|
+
break;
|
|
505
|
+
case 'table':
|
|
506
|
+
msg = 'DropTables';
|
|
507
|
+
break;
|
|
508
|
+
case 'view':
|
|
509
|
+
msg = 'DropViews';
|
|
510
|
+
break;
|
|
511
|
+
default:
|
|
512
|
+
return Promise.reject(`DropElements: ${type} ` + 'not found');
|
|
513
|
+
}
|
|
514
|
+
// get the element's names
|
|
515
|
+
let stmt = 'SELECT name FROM sqlite_master WHERE ';
|
|
516
|
+
stmt += `type = '${type}' AND name NOT LIKE 'sqlite_%';`;
|
|
517
|
+
try {
|
|
518
|
+
const elements = await this._uSQLite.queryAll(db, stmt, []);
|
|
519
|
+
if (elements.length > 0) {
|
|
520
|
+
const upType = type.toUpperCase();
|
|
521
|
+
const statements = [];
|
|
522
|
+
for (const elem of elements) {
|
|
523
|
+
let stmt = `DROP ${upType} IF EXISTS `;
|
|
524
|
+
stmt += `${elem.name};`;
|
|
525
|
+
statements.push(stmt);
|
|
526
|
+
}
|
|
527
|
+
for (const stmt of statements) {
|
|
528
|
+
const lastId = await this._uSQLite.prepareRun(db, stmt, []);
|
|
529
|
+
if (lastId < 0) {
|
|
530
|
+
return Promise.reject(`${msg}: lastId < 0`);
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
return Promise.resolve();
|
|
535
|
+
}
|
|
536
|
+
catch (err) {
|
|
537
|
+
return Promise.reject(`${msg}: ${err}`);
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
/**
|
|
541
|
+
* DropAll
|
|
542
|
+
* Drop all database's elements
|
|
543
|
+
* @param db
|
|
544
|
+
*/
|
|
545
|
+
async dropAll(db) {
|
|
546
|
+
try {
|
|
547
|
+
// drop tables
|
|
548
|
+
await this.dropElements(db, 'table');
|
|
549
|
+
// drop indexes
|
|
550
|
+
await this.dropElements(db, 'index');
|
|
551
|
+
// drop triggers
|
|
552
|
+
await this.dropElements(db, 'trigger');
|
|
553
|
+
// drop views
|
|
554
|
+
await this.dropElements(db, 'view');
|
|
555
|
+
// vacuum the database
|
|
556
|
+
await this._uSQLite.prepareRun(db, 'VACUUM;', []);
|
|
557
|
+
return Promise.resolve();
|
|
558
|
+
}
|
|
559
|
+
catch (err) {
|
|
560
|
+
return Promise.reject(`DropAll: ${err}`);
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
/**
|
|
564
|
+
* DropTempTables
|
|
565
|
+
* @param db
|
|
566
|
+
* @param alterTables
|
|
567
|
+
*/
|
|
568
|
+
async dropTempTables(db, alterTables) {
|
|
569
|
+
const tempTables = Object.keys(alterTables);
|
|
570
|
+
const statements = [];
|
|
571
|
+
for (const tTable of tempTables) {
|
|
572
|
+
let stmt = 'DROP TABLE IF EXISTS ';
|
|
573
|
+
stmt += `_temp_${tTable};`;
|
|
574
|
+
statements.push(stmt);
|
|
575
|
+
}
|
|
576
|
+
try {
|
|
577
|
+
const changes = await this._uSQLite.execute(db, statements.join('\n'));
|
|
578
|
+
if (changes < 0) {
|
|
579
|
+
return Promise.reject('DropTempTables: changes < 0');
|
|
580
|
+
}
|
|
581
|
+
return Promise.resolve();
|
|
582
|
+
}
|
|
583
|
+
catch (err) {
|
|
584
|
+
return Promise.reject(`DropTempTables: ${err}`);
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
utilsDrop.UtilsDrop = UtilsDrop;
|
|
589
|
+
|
|
438
590
|
Object.defineProperty(utilsJson, "__esModule", { value: true });
|
|
439
591
|
utilsJson.UtilsJson = void 0;
|
|
440
|
-
const
|
|
592
|
+
const utilsDrop_1$2 = utilsDrop;
|
|
593
|
+
const utilsSQLite_1$4 = utilsSQLite;
|
|
441
594
|
class UtilsJson {
|
|
442
595
|
constructor() {
|
|
443
|
-
this._uSQLite = new utilsSQLite_1$
|
|
596
|
+
this._uSQLite = new utilsSQLite_1$4.UtilsSQLite();
|
|
597
|
+
this._uDrop = new utilsDrop_1$2.UtilsDrop();
|
|
598
|
+
}
|
|
599
|
+
/**
|
|
600
|
+
* isLastModified
|
|
601
|
+
* @param db
|
|
602
|
+
* @param isOpen
|
|
603
|
+
*/
|
|
604
|
+
async isLastModified(db, isOpen) {
|
|
605
|
+
if (!isOpen) {
|
|
606
|
+
return Promise.reject('isLastModified: database not opened');
|
|
607
|
+
}
|
|
608
|
+
try {
|
|
609
|
+
const tableList = await this._uDrop.getTablesNames(db);
|
|
610
|
+
for (const table of tableList) {
|
|
611
|
+
const tableNamesTypes = await this.getTableColumnNamesTypes(db, table);
|
|
612
|
+
const tableColumnNames = tableNamesTypes.names;
|
|
613
|
+
if (tableColumnNames.includes('last_modified')) {
|
|
614
|
+
return Promise.resolve(true);
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
catch (err) {
|
|
619
|
+
return Promise.reject(`isLastModified: ${err}`);
|
|
620
|
+
}
|
|
444
621
|
}
|
|
445
622
|
/**
|
|
446
623
|
* IsTableExists
|
|
@@ -554,6 +731,7 @@ class UtilsJson {
|
|
|
554
731
|
*/
|
|
555
732
|
async createSchemaStatement(jsonData) {
|
|
556
733
|
const statements = [];
|
|
734
|
+
let isLastModified = false;
|
|
557
735
|
// Prepare the statement to execute
|
|
558
736
|
try {
|
|
559
737
|
for (const jTable of jsonData.tables) {
|
|
@@ -564,6 +742,9 @@ class UtilsJson {
|
|
|
564
742
|
if (j === jTable.schema.length - 1) {
|
|
565
743
|
if (jTable.schema[j].column) {
|
|
566
744
|
statements.push(`${jTable.schema[j].column} ${jTable.schema[j].value}`);
|
|
745
|
+
if (jTable.schema[j].column === 'last_modified') {
|
|
746
|
+
isLastModified = true;
|
|
747
|
+
}
|
|
567
748
|
}
|
|
568
749
|
else if (jTable.schema[j].foreignkey) {
|
|
569
750
|
statements.push(`FOREIGN KEY (${jTable.schema[j].foreignkey}) ${jTable.schema[j].value}`);
|
|
@@ -575,6 +756,9 @@ class UtilsJson {
|
|
|
575
756
|
else {
|
|
576
757
|
if (jTable.schema[j].column) {
|
|
577
758
|
statements.push(`${jTable.schema[j].column} ${jTable.schema[j].value},`);
|
|
759
|
+
if (jTable.schema[j].column === 'last_modified') {
|
|
760
|
+
isLastModified = true;
|
|
761
|
+
}
|
|
578
762
|
}
|
|
579
763
|
else if (jTable.schema[j].foreignkey) {
|
|
580
764
|
statements.push(`FOREIGN KEY (${jTable.schema[j].foreignkey}) ${jTable.schema[j].value},`);
|
|
@@ -585,17 +769,19 @@ class UtilsJson {
|
|
|
585
769
|
}
|
|
586
770
|
}
|
|
587
771
|
statements.push(');');
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
772
|
+
if (isLastModified) {
|
|
773
|
+
// create trigger last_modified associated with the table
|
|
774
|
+
let trig = 'CREATE TRIGGER IF NOT EXISTS ';
|
|
775
|
+
trig += `${jTable.name}`;
|
|
776
|
+
trig += `_trigger_last_modified `;
|
|
777
|
+
trig += `AFTER UPDATE ON ${jTable.name} `;
|
|
778
|
+
trig += 'FOR EACH ROW WHEN NEW.last_modified <= ';
|
|
779
|
+
trig += 'OLD.last_modified BEGIN UPDATE ';
|
|
780
|
+
trig += `${jTable.name} `;
|
|
781
|
+
trig += `SET last_modified = `;
|
|
782
|
+
trig += "(strftime('%s','now')) WHERE id=OLD.id; END;";
|
|
783
|
+
statements.push(trig);
|
|
784
|
+
}
|
|
599
785
|
}
|
|
600
786
|
if (jTable.indexes != null && jTable.indexes.length >= 1) {
|
|
601
787
|
for (const jIndex of jTable.indexes) {
|
|
@@ -1165,11 +1351,11 @@ utilsJson.UtilsJson = UtilsJson;
|
|
|
1165
1351
|
|
|
1166
1352
|
Object.defineProperty(exportToJson, "__esModule", { value: true });
|
|
1167
1353
|
exportToJson.ExportToJson = void 0;
|
|
1168
|
-
const utilsSQLite_1$
|
|
1354
|
+
const utilsSQLite_1$3 = utilsSQLite;
|
|
1169
1355
|
const utilsJson_1$4 = utilsJson;
|
|
1170
1356
|
class ExportToJson {
|
|
1171
1357
|
constructor() {
|
|
1172
|
-
this._uSQLite = new utilsSQLite_1$
|
|
1358
|
+
this._uSQLite = new utilsSQLite_1$3.UtilsSQLite();
|
|
1173
1359
|
this._uJson = new utilsJson_1$4.UtilsJson();
|
|
1174
1360
|
}
|
|
1175
1361
|
/**
|
|
@@ -1191,6 +1377,10 @@ class ExportToJson {
|
|
|
1191
1377
|
return Promise.reject("createExportObject: table's names failed");
|
|
1192
1378
|
}
|
|
1193
1379
|
else {
|
|
1380
|
+
const isTable = await this._uJson.isTableExists(mDB, true, 'sync_table');
|
|
1381
|
+
if (!isTable && sqlObj.mode === 'partial') {
|
|
1382
|
+
return Promise.reject('No sync_table available');
|
|
1383
|
+
}
|
|
1194
1384
|
switch (sqlObj.mode) {
|
|
1195
1385
|
case 'partial': {
|
|
1196
1386
|
tables = await this.getTablesPartial(mDB, resTables);
|
|
@@ -1807,156 +1997,6 @@ exportToJson.ExportToJson = ExportToJson;
|
|
|
1807
1997
|
|
|
1808
1998
|
var importFromJson = {};
|
|
1809
1999
|
|
|
1810
|
-
var utilsDrop = {};
|
|
1811
|
-
|
|
1812
|
-
Object.defineProperty(utilsDrop, "__esModule", { value: true });
|
|
1813
|
-
utilsDrop.UtilsDrop = void 0;
|
|
1814
|
-
const utilsSQLite_1$3 = utilsSQLite;
|
|
1815
|
-
class UtilsDrop {
|
|
1816
|
-
constructor() {
|
|
1817
|
-
this._uSQLite = new utilsSQLite_1$3.UtilsSQLite();
|
|
1818
|
-
}
|
|
1819
|
-
/**
|
|
1820
|
-
* GetTablesNames
|
|
1821
|
-
* @param mDb
|
|
1822
|
-
*/
|
|
1823
|
-
async getTablesNames(mDb) {
|
|
1824
|
-
let sql = 'SELECT name FROM sqlite_master WHERE ';
|
|
1825
|
-
sql += "type='table' AND name NOT LIKE 'sync_table' ";
|
|
1826
|
-
sql += "AND name NOT LIKE '_temp_%' ";
|
|
1827
|
-
sql += "AND name NOT LIKE 'sqlite_%' ";
|
|
1828
|
-
sql += 'ORDER BY rootpage DESC;';
|
|
1829
|
-
const retArr = [];
|
|
1830
|
-
try {
|
|
1831
|
-
const retQuery = await this._uSQLite.queryAll(mDb, sql, []);
|
|
1832
|
-
for (const query of retQuery) {
|
|
1833
|
-
retArr.push(query.name);
|
|
1834
|
-
}
|
|
1835
|
-
return Promise.resolve(retArr);
|
|
1836
|
-
}
|
|
1837
|
-
catch (err) {
|
|
1838
|
-
return Promise.reject(`getTablesNames: ${err}`);
|
|
1839
|
-
}
|
|
1840
|
-
}
|
|
1841
|
-
/**
|
|
1842
|
-
* GetViewsNames
|
|
1843
|
-
* @param mDb
|
|
1844
|
-
*/
|
|
1845
|
-
async getViewsNames(mDb) {
|
|
1846
|
-
let sql = 'SELECT name FROM sqlite_master WHERE ';
|
|
1847
|
-
sql += "type='view' AND name NOT LIKE 'sqlite_%' ";
|
|
1848
|
-
sql += 'ORDER BY rootpage DESC;';
|
|
1849
|
-
const retArr = [];
|
|
1850
|
-
try {
|
|
1851
|
-
const retQuery = await this._uSQLite.queryAll(mDb, sql, []);
|
|
1852
|
-
for (const query of retQuery) {
|
|
1853
|
-
retArr.push(query.name);
|
|
1854
|
-
}
|
|
1855
|
-
return Promise.resolve(retArr);
|
|
1856
|
-
}
|
|
1857
|
-
catch (err) {
|
|
1858
|
-
return Promise.reject(`getViewsNames: ${err}`);
|
|
1859
|
-
}
|
|
1860
|
-
}
|
|
1861
|
-
/**
|
|
1862
|
-
* DropElements
|
|
1863
|
-
* @param db
|
|
1864
|
-
* @param type ["table","index","trigger"]
|
|
1865
|
-
*/
|
|
1866
|
-
async dropElements(db, type) {
|
|
1867
|
-
let msg = '';
|
|
1868
|
-
switch (type) {
|
|
1869
|
-
case 'index':
|
|
1870
|
-
msg = 'DropIndexes';
|
|
1871
|
-
break;
|
|
1872
|
-
case 'trigger':
|
|
1873
|
-
msg = 'DropTriggers';
|
|
1874
|
-
break;
|
|
1875
|
-
case 'table':
|
|
1876
|
-
msg = 'DropTables';
|
|
1877
|
-
break;
|
|
1878
|
-
case 'view':
|
|
1879
|
-
msg = 'DropViews';
|
|
1880
|
-
break;
|
|
1881
|
-
default:
|
|
1882
|
-
return Promise.reject(`DropElements: ${type} ` + 'not found');
|
|
1883
|
-
}
|
|
1884
|
-
// get the element's names
|
|
1885
|
-
let stmt = 'SELECT name FROM sqlite_master WHERE ';
|
|
1886
|
-
stmt += `type = '${type}' AND name NOT LIKE 'sqlite_%';`;
|
|
1887
|
-
try {
|
|
1888
|
-
const elements = await this._uSQLite.queryAll(db, stmt, []);
|
|
1889
|
-
if (elements.length > 0) {
|
|
1890
|
-
const upType = type.toUpperCase();
|
|
1891
|
-
const statements = [];
|
|
1892
|
-
for (const elem of elements) {
|
|
1893
|
-
let stmt = `DROP ${upType} IF EXISTS `;
|
|
1894
|
-
stmt += `${elem.name};`;
|
|
1895
|
-
statements.push(stmt);
|
|
1896
|
-
}
|
|
1897
|
-
for (const stmt of statements) {
|
|
1898
|
-
const lastId = await this._uSQLite.prepareRun(db, stmt, []);
|
|
1899
|
-
if (lastId < 0) {
|
|
1900
|
-
return Promise.reject(`${msg}: lastId < 0`);
|
|
1901
|
-
}
|
|
1902
|
-
}
|
|
1903
|
-
}
|
|
1904
|
-
return Promise.resolve();
|
|
1905
|
-
}
|
|
1906
|
-
catch (err) {
|
|
1907
|
-
return Promise.reject(`${msg}: ${err}`);
|
|
1908
|
-
}
|
|
1909
|
-
}
|
|
1910
|
-
/**
|
|
1911
|
-
* DropAll
|
|
1912
|
-
* Drop all database's elements
|
|
1913
|
-
* @param db
|
|
1914
|
-
*/
|
|
1915
|
-
async dropAll(db) {
|
|
1916
|
-
try {
|
|
1917
|
-
// drop tables
|
|
1918
|
-
await this.dropElements(db, 'table');
|
|
1919
|
-
// drop indexes
|
|
1920
|
-
await this.dropElements(db, 'index');
|
|
1921
|
-
// drop triggers
|
|
1922
|
-
await this.dropElements(db, 'trigger');
|
|
1923
|
-
// drop views
|
|
1924
|
-
await this.dropElements(db, 'view');
|
|
1925
|
-
// vacuum the database
|
|
1926
|
-
await this._uSQLite.prepareRun(db, 'VACUUM;', []);
|
|
1927
|
-
return Promise.resolve();
|
|
1928
|
-
}
|
|
1929
|
-
catch (err) {
|
|
1930
|
-
return Promise.reject(`DropAll: ${err}`);
|
|
1931
|
-
}
|
|
1932
|
-
}
|
|
1933
|
-
/**
|
|
1934
|
-
* DropTempTables
|
|
1935
|
-
* @param db
|
|
1936
|
-
* @param alterTables
|
|
1937
|
-
*/
|
|
1938
|
-
async dropTempTables(db, alterTables) {
|
|
1939
|
-
const tempTables = Object.keys(alterTables);
|
|
1940
|
-
const statements = [];
|
|
1941
|
-
for (const tTable of tempTables) {
|
|
1942
|
-
let stmt = 'DROP TABLE IF EXISTS ';
|
|
1943
|
-
stmt += `_temp_${tTable};`;
|
|
1944
|
-
statements.push(stmt);
|
|
1945
|
-
}
|
|
1946
|
-
try {
|
|
1947
|
-
const changes = await this._uSQLite.execute(db, statements.join('\n'));
|
|
1948
|
-
if (changes < 0) {
|
|
1949
|
-
return Promise.reject('DropTempTables: changes < 0');
|
|
1950
|
-
}
|
|
1951
|
-
return Promise.resolve();
|
|
1952
|
-
}
|
|
1953
|
-
catch (err) {
|
|
1954
|
-
return Promise.reject(`DropTempTables: ${err}`);
|
|
1955
|
-
}
|
|
1956
|
-
}
|
|
1957
|
-
}
|
|
1958
|
-
utilsDrop.UtilsDrop = UtilsDrop;
|
|
1959
|
-
|
|
1960
2000
|
Object.defineProperty(importFromJson, "__esModule", { value: true });
|
|
1961
2001
|
importFromJson.ImportFromJson = void 0;
|
|
1962
2002
|
const utilsDrop_1$1 = utilsDrop;
|
|
@@ -2121,6 +2161,7 @@ class UtilsFile {
|
|
|
2121
2161
|
this.NodeFs = null;
|
|
2122
2162
|
this.JSZip = null;
|
|
2123
2163
|
this.Os = null;
|
|
2164
|
+
this.Electron = null;
|
|
2124
2165
|
this.AppName = '';
|
|
2125
2166
|
this.HomeDir = '';
|
|
2126
2167
|
this.sep = '/';
|
|
@@ -2128,15 +2169,38 @@ class UtilsFile {
|
|
|
2128
2169
|
this.NodeFs = require$$1__default['default'];
|
|
2129
2170
|
this.Os = require$$2__default['default'];
|
|
2130
2171
|
this.JSZip = require$$3__default['default'];
|
|
2172
|
+
this.Electron = require$$4__default['default'];
|
|
2131
2173
|
this.HomeDir = this.Os.homedir();
|
|
2132
2174
|
const dir = __dirname;
|
|
2133
2175
|
const idx = dir.indexOf('\\');
|
|
2134
2176
|
if (idx != -1)
|
|
2135
2177
|
this.sep = '\\';
|
|
2136
|
-
this.appPath =
|
|
2178
|
+
this.appPath = this.Electron.app.getAppPath();
|
|
2137
2179
|
const rawdata = this.NodeFs.readFileSync(this.Path.resolve(this.appPath, 'package.json'));
|
|
2138
2180
|
this.AppName = JSON.parse(rawdata).name;
|
|
2181
|
+
const pathToBuild = this.Path.join(this.appPath, 'build');
|
|
2182
|
+
if (this.NodeFs.existsSync(this.Path.join(pathToBuild, 'capacitor.config.js'))) {
|
|
2183
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
2184
|
+
this.capConfig = require(this.Path.join(pathToBuild, 'capacitor.config.js')).default;
|
|
2185
|
+
}
|
|
2186
|
+
else {
|
|
2187
|
+
this.capConfig = JSON.parse(this.NodeFs.readFileSync(this.Path.join(this.appPath, 'capacitor.config.json')).toString());
|
|
2188
|
+
}
|
|
2139
2189
|
this.osType = this.Os.type();
|
|
2190
|
+
switch (this.osType) {
|
|
2191
|
+
case 'Darwin':
|
|
2192
|
+
this.pathDB = this.capConfig.plugins.CapacitorSQLite.electronMacLocation;
|
|
2193
|
+
break;
|
|
2194
|
+
case 'Linux':
|
|
2195
|
+
this.pathDB = this.capConfig.plugins.CapacitorSQLite.electronLinuxLocation;
|
|
2196
|
+
break;
|
|
2197
|
+
case 'Windows_NT':
|
|
2198
|
+
this.pathDB = this.capConfig.plugins.CapacitorSQLite.electronWindowsLocation;
|
|
2199
|
+
break;
|
|
2200
|
+
default:
|
|
2201
|
+
console.log('other operating system');
|
|
2202
|
+
}
|
|
2203
|
+
console.log(`&&& Databases path: ${this.pathDB}`);
|
|
2140
2204
|
}
|
|
2141
2205
|
/**
|
|
2142
2206
|
* IsPathExists
|
|
@@ -2175,37 +2239,26 @@ class UtilsFile {
|
|
|
2175
2239
|
getFilePath(fileName) {
|
|
2176
2240
|
return this.Path.join(this.getDatabasesPath(), fileName);
|
|
2177
2241
|
}
|
|
2178
|
-
/**
|
|
2179
|
-
* GetCustomerPath
|
|
2180
|
-
* get the customer path
|
|
2181
|
-
*/
|
|
2182
|
-
getCustomerPath(custPath) {
|
|
2183
|
-
return this.Path.join(this.HomeDir, custPath);
|
|
2184
|
-
}
|
|
2185
|
-
/**
|
|
2186
|
-
* GetCustomerFilePath
|
|
2187
|
-
* get the customer file path
|
|
2188
|
-
*/
|
|
2189
|
-
getCustomerFilePath(custPath, file) {
|
|
2190
|
-
return this.Path.join(custPath, file);
|
|
2191
|
-
}
|
|
2192
2242
|
/**
|
|
2193
2243
|
* GetDatabasesPath
|
|
2194
2244
|
* get the database folder path
|
|
2195
2245
|
*/
|
|
2196
2246
|
getDatabasesPath() {
|
|
2197
2247
|
let retPath = '';
|
|
2248
|
+
const sep = this.Path.sep;
|
|
2198
2249
|
const dbFolder = this.pathDB;
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
retPath = '';
|
|
2250
|
+
if (dbFolder.includes(sep)) {
|
|
2251
|
+
retPath = dbFolder;
|
|
2252
|
+
if (this.Path.basename(dbFolder) !== this.AppName) {
|
|
2253
|
+
retPath = this.Path.join(dbFolder, this.AppName);
|
|
2254
|
+
}
|
|
2205
2255
|
}
|
|
2206
2256
|
else {
|
|
2207
|
-
retPath =
|
|
2257
|
+
retPath = this.Path.join(this.HomeDir, dbFolder, this.AppName);
|
|
2208
2258
|
}
|
|
2259
|
+
const retB = this._createFolderIfNotExists(retPath);
|
|
2260
|
+
if (!retB)
|
|
2261
|
+
retPath = '';
|
|
2209
2262
|
return retPath;
|
|
2210
2263
|
}
|
|
2211
2264
|
/**
|
|
@@ -3069,17 +3122,23 @@ class Database {
|
|
|
3069
3122
|
try {
|
|
3070
3123
|
const retB = await this._uJson.isTableExists(this._mDB, isOpen, 'sync_table');
|
|
3071
3124
|
if (!retB) {
|
|
3072
|
-
const
|
|
3073
|
-
|
|
3074
|
-
|
|
3075
|
-
|
|
3076
|
-
|
|
3077
|
-
|
|
3078
|
-
|
|
3079
|
-
|
|
3080
|
-
|
|
3081
|
-
|
|
3082
|
-
|
|
3125
|
+
const isLastModified = await this._uJson.isLastModified(this._mDB, isOpen);
|
|
3126
|
+
if (isLastModified) {
|
|
3127
|
+
const date = Math.round(new Date().getTime() / 1000);
|
|
3128
|
+
let stmts = `
|
|
3129
|
+
CREATE TABLE IF NOT EXISTS sync_table (
|
|
3130
|
+
id INTEGER PRIMARY KEY NOT NULL,
|
|
3131
|
+
sync_date INTEGER
|
|
3132
|
+
);`;
|
|
3133
|
+
stmts += `INSERT INTO sync_table (sync_date) VALUES (
|
|
3134
|
+
"${date}");`;
|
|
3135
|
+
changes = await this._uSQLite.execute(this._mDB, stmts);
|
|
3136
|
+
if (changes < 0) {
|
|
3137
|
+
return Promise.reject(`CreateSyncTable: failed changes < 0`);
|
|
3138
|
+
}
|
|
3139
|
+
}
|
|
3140
|
+
else {
|
|
3141
|
+
return Promise.reject('No last_modified column in tables');
|
|
3083
3142
|
}
|
|
3084
3143
|
}
|
|
3085
3144
|
return Promise.resolve(changes);
|
|
@@ -3101,6 +3160,10 @@ class Database {
|
|
|
3101
3160
|
return { result: false, message: msg };
|
|
3102
3161
|
}
|
|
3103
3162
|
try {
|
|
3163
|
+
const isTable = await this._uJson.isTableExists(this._mDB, this._isDBOpen, 'sync_table');
|
|
3164
|
+
if (!isTable) {
|
|
3165
|
+
return Promise.reject('No sync_table available');
|
|
3166
|
+
}
|
|
3104
3167
|
const sDate = Math.round(new Date(syncDate).getTime() / 1000);
|
|
3105
3168
|
let stmt = `UPDATE sync_table SET sync_date = `;
|
|
3106
3169
|
stmt += `${sDate} WHERE id = 1;`;
|
|
@@ -3128,6 +3191,10 @@ class Database {
|
|
|
3128
3191
|
return { syncDate: 0, message: msg };
|
|
3129
3192
|
}
|
|
3130
3193
|
try {
|
|
3194
|
+
const isTable = await this._uJson.isTableExists(this._mDB, this._isDBOpen, 'sync_table');
|
|
3195
|
+
if (!isTable) {
|
|
3196
|
+
return Promise.reject('No sync_table available');
|
|
3197
|
+
}
|
|
3131
3198
|
const syncDate = await this._eTJson.getSyncDate(this._mDB);
|
|
3132
3199
|
if (syncDate > 0) {
|
|
3133
3200
|
return { syncDate: syncDate };
|