@capacitor-community/sqlite 3.4.2-5 → 3.4.3-2
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 +46 -4
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/CapacitorSQLite.java +41 -2
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/CapacitorSQLitePlugin.java +26 -0
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/NotificationCenter.java +1 -1
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/Database.java +220 -7
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/ImportExportJson/ExportToJson.java +102 -86
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/ImportExportJson/ImportFromJson.java +127 -38
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/ImportExportJson/UtilsJson.java +90 -0
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/UtilsUpgrade.java +8 -4
- package/dist/esm/definitions.d.ts +17 -1
- package/dist/esm/definitions.js +22 -28
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/web.d.ts +20 -11
- package/dist/esm/web.js +288 -473
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +286 -477
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +1036 -1227
- package/dist/plugin.js.map +1 -1
- package/electron/dist/plugin.js +589 -744
- package/electron/dist/plugin.js.map +1 -1
- package/ios/Plugin/CapacitorSQLite.swift +34 -1
- package/ios/Plugin/CapacitorSQLitePlugin.m +1 -0
- package/ios/Plugin/CapacitorSQLitePlugin.swift +25 -0
- package/ios/Plugin/Database.swift +29 -1
- package/ios/Plugin/Extensions/String.swift +8 -0
- package/ios/Plugin/ImportExportJson/ExportToJson.swift +190 -32
- package/ios/Plugin/ImportExportJson/ImportFromJson.swift +73 -38
- package/ios/Plugin/Utils/UtilsDrop.swift +2 -2
- package/ios/Plugin/Utils/UtilsJson.swift +68 -1
- package/ios/Plugin/Utils/UtilsSQLCipher.swift +277 -29
- package/ios/Plugin/Utils/UtilsUpgrade.swift +33 -13
- package/package.json +6 -6
package/electron/dist/plugin.js
CHANGED
|
@@ -777,7 +777,7 @@ class UtilsJson {
|
|
|
777
777
|
trig += `${jTable.name}`;
|
|
778
778
|
trig += `_trigger_last_modified `;
|
|
779
779
|
trig += `AFTER UPDATE ON ${jTable.name} `;
|
|
780
|
-
trig += 'FOR EACH ROW WHEN NEW.last_modified
|
|
780
|
+
trig += 'FOR EACH ROW WHEN NEW.last_modified < ';
|
|
781
781
|
trig += 'OLD.last_modified BEGIN UPDATE ';
|
|
782
782
|
trig += `${jTable.name} `;
|
|
783
783
|
trig += `SET last_modified = `;
|
|
@@ -859,6 +859,7 @@ class UtilsJson {
|
|
|
859
859
|
*/
|
|
860
860
|
const retisIdExists = await this.isIdExists(mDB, table.name, tableColumnNames[0], table.values[j][0]);
|
|
861
861
|
let stmt;
|
|
862
|
+
let isRun = true;
|
|
862
863
|
if (mode === 'full' || (mode === 'partial' && !retisIdExists)) {
|
|
863
864
|
// Insert
|
|
864
865
|
const nameString = tableColumnNames.join();
|
|
@@ -880,10 +881,16 @@ class UtilsJson {
|
|
|
880
881
|
else {
|
|
881
882
|
stmt += `${tableColumnNames[0]} = ${table.values[j][0]};`;
|
|
882
883
|
}
|
|
884
|
+
isRun = await this.checkUpdate(mDB, table.values[j], table.name, tableColumnNames);
|
|
883
885
|
}
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
886
|
+
if (isRun) {
|
|
887
|
+
lastId = await this._uSQLite.prepareRun(mDB, stmt, table.values[j]);
|
|
888
|
+
if (lastId < 0) {
|
|
889
|
+
return Promise.reject('CreateDataTable: lastId < 0');
|
|
890
|
+
}
|
|
891
|
+
}
|
|
892
|
+
else {
|
|
893
|
+
lastId = 0;
|
|
887
894
|
}
|
|
888
895
|
}
|
|
889
896
|
return Promise.resolve(lastId);
|
|
@@ -892,6 +899,84 @@ class UtilsJson {
|
|
|
892
899
|
return Promise.reject(`CreateDataTable: ${err}`);
|
|
893
900
|
}
|
|
894
901
|
}
|
|
902
|
+
/**
|
|
903
|
+
*
|
|
904
|
+
* @param db
|
|
905
|
+
* @param values
|
|
906
|
+
* @param tbName
|
|
907
|
+
* @param tColNames
|
|
908
|
+
* @returns
|
|
909
|
+
*/
|
|
910
|
+
async checkUpdate(db, values, tbName, tColNames) {
|
|
911
|
+
try {
|
|
912
|
+
let query = `SELECT * FROM ${tbName} WHERE `;
|
|
913
|
+
if (typeof values[0] == 'string') {
|
|
914
|
+
query += `${tColNames[0]} = '${values[0]}';`;
|
|
915
|
+
}
|
|
916
|
+
else {
|
|
917
|
+
query += `${tColNames[0]} = ${values[0]};`;
|
|
918
|
+
}
|
|
919
|
+
const resQuery = await this.getValues(db, query, tbName);
|
|
920
|
+
let resValues = [];
|
|
921
|
+
if (resQuery.length > 0) {
|
|
922
|
+
resValues = resQuery[0];
|
|
923
|
+
}
|
|
924
|
+
if (values.length > 0 &&
|
|
925
|
+
resValues.length > 0 &&
|
|
926
|
+
values.length === resValues.length) {
|
|
927
|
+
for (let i = 0; i < values.length; i++) {
|
|
928
|
+
if (values[i] !== resValues[i]) {
|
|
929
|
+
return Promise.resolve(true);
|
|
930
|
+
}
|
|
931
|
+
}
|
|
932
|
+
return Promise.resolve(false);
|
|
933
|
+
}
|
|
934
|
+
else {
|
|
935
|
+
const msg = 'Both arrays not the same length';
|
|
936
|
+
return Promise.reject(new Error(`CheckUpdate: ${msg}`));
|
|
937
|
+
}
|
|
938
|
+
}
|
|
939
|
+
catch (err) {
|
|
940
|
+
return Promise.reject(new Error(`CheckUpdate: ${err.message}`));
|
|
941
|
+
}
|
|
942
|
+
}
|
|
943
|
+
/**
|
|
944
|
+
* GetValues
|
|
945
|
+
* @param mDb
|
|
946
|
+
* @param query
|
|
947
|
+
* @param tableName
|
|
948
|
+
*/
|
|
949
|
+
async getValues(mDb, query, tableName) {
|
|
950
|
+
const values = [];
|
|
951
|
+
try {
|
|
952
|
+
// get table column names and types
|
|
953
|
+
const tableNamesTypes = await this.getTableColumnNamesTypes(mDb, tableName);
|
|
954
|
+
let rowNames = [];
|
|
955
|
+
if (Object.keys(tableNamesTypes).includes('names')) {
|
|
956
|
+
rowNames = tableNamesTypes.names;
|
|
957
|
+
}
|
|
958
|
+
else {
|
|
959
|
+
return Promise.reject(`GetValues: Table ${tableName} no names`);
|
|
960
|
+
}
|
|
961
|
+
const retValues = await this._uSQLite.queryAll(mDb, query, []);
|
|
962
|
+
for (const rValue of retValues) {
|
|
963
|
+
const row = [];
|
|
964
|
+
for (const rName of rowNames) {
|
|
965
|
+
if (Object.keys(rValue).includes(rName)) {
|
|
966
|
+
row.push(rValue[rName]);
|
|
967
|
+
}
|
|
968
|
+
else {
|
|
969
|
+
row.push('NULL');
|
|
970
|
+
}
|
|
971
|
+
}
|
|
972
|
+
values.push(row);
|
|
973
|
+
}
|
|
974
|
+
return Promise.resolve(values);
|
|
975
|
+
}
|
|
976
|
+
catch (err) {
|
|
977
|
+
return Promise.reject(`GetValues: ${err}`);
|
|
978
|
+
}
|
|
979
|
+
}
|
|
895
980
|
/**
|
|
896
981
|
* GetTableColumnNamesTypes
|
|
897
982
|
* @param mDB
|
|
@@ -1539,7 +1624,7 @@ class ExportToJson {
|
|
|
1539
1624
|
}
|
|
1540
1625
|
// create Table's Data
|
|
1541
1626
|
const query = `SELECT * FROM ${tableName};`;
|
|
1542
|
-
const values = await this.getValues(mDb, query, tableName);
|
|
1627
|
+
const values = await this._uJson.getValues(mDb, query, tableName);
|
|
1543
1628
|
table.name = tableName;
|
|
1544
1629
|
if (schema.length > 0) {
|
|
1545
1630
|
table.schema = schema;
|
|
@@ -1742,43 +1827,6 @@ class ExportToJson {
|
|
|
1742
1827
|
return Promise.reject(`GetTriggers: ${err}`);
|
|
1743
1828
|
}
|
|
1744
1829
|
}
|
|
1745
|
-
/**
|
|
1746
|
-
* GetValues
|
|
1747
|
-
* @param mDb
|
|
1748
|
-
* @param query
|
|
1749
|
-
* @param tableName
|
|
1750
|
-
*/
|
|
1751
|
-
async getValues(mDb, query, tableName) {
|
|
1752
|
-
const values = [];
|
|
1753
|
-
try {
|
|
1754
|
-
// get table column names and types
|
|
1755
|
-
const tableNamesTypes = await this._uJson.getTableColumnNamesTypes(mDb, tableName);
|
|
1756
|
-
let rowNames = [];
|
|
1757
|
-
if (Object.keys(tableNamesTypes).includes('names')) {
|
|
1758
|
-
rowNames = tableNamesTypes.names;
|
|
1759
|
-
}
|
|
1760
|
-
else {
|
|
1761
|
-
return Promise.reject(`GetValues: Table ${tableName} no names`);
|
|
1762
|
-
}
|
|
1763
|
-
const retValues = await this._uSQLite.queryAll(mDb, query, []);
|
|
1764
|
-
for (const rValue of retValues) {
|
|
1765
|
-
const row = [];
|
|
1766
|
-
for (const rName of rowNames) {
|
|
1767
|
-
if (Object.keys(rValue).includes(rName)) {
|
|
1768
|
-
row.push(rValue[rName]);
|
|
1769
|
-
}
|
|
1770
|
-
else {
|
|
1771
|
-
row.push('NULL');
|
|
1772
|
-
}
|
|
1773
|
-
}
|
|
1774
|
-
values.push(row);
|
|
1775
|
-
}
|
|
1776
|
-
return Promise.resolve(values);
|
|
1777
|
-
}
|
|
1778
|
-
catch (err) {
|
|
1779
|
-
return Promise.reject(`GetValues: ${err}`);
|
|
1780
|
-
}
|
|
1781
|
-
}
|
|
1782
1830
|
/**
|
|
1783
1831
|
* GetTablesPartial
|
|
1784
1832
|
* @param mDb
|
|
@@ -1858,7 +1906,7 @@ class ExportToJson {
|
|
|
1858
1906
|
`SELECT * FROM ${tableName} ` +
|
|
1859
1907
|
`WHERE last_modified > ${syncDate};`;
|
|
1860
1908
|
}
|
|
1861
|
-
const values = await this.getValues(mDb, query, tableName);
|
|
1909
|
+
const values = await this._uJson.getValues(mDb, query, tableName);
|
|
1862
1910
|
// check the table object validity
|
|
1863
1911
|
table.name = tableName;
|
|
1864
1912
|
if (schema.length > 0) {
|
|
@@ -2687,15 +2735,17 @@ class UtilsUpgrade {
|
|
|
2687
2735
|
if (Object.keys(this._commonColumns).length > 0) {
|
|
2688
2736
|
await this.updateNewTablesData(mDB);
|
|
2689
2737
|
}
|
|
2738
|
+
return Promise.resolve();
|
|
2739
|
+
}
|
|
2740
|
+
catch (err) {
|
|
2741
|
+
return Promise.reject(`ExecuteStatementProcess: ${err}`);
|
|
2742
|
+
}
|
|
2743
|
+
finally {
|
|
2690
2744
|
// -> Drop _temp_tables
|
|
2691
2745
|
await this._uDrop.dropTempTables(mDB, this._alterTables);
|
|
2692
2746
|
// -> Do some cleanup
|
|
2693
2747
|
this._alterTables = {};
|
|
2694
2748
|
this._commonColumns = {};
|
|
2695
|
-
return Promise.resolve();
|
|
2696
|
-
}
|
|
2697
|
-
catch (err) {
|
|
2698
|
-
return Promise.reject(`ExecuteStatementProcess: ${err}`);
|
|
2699
2749
|
}
|
|
2700
2750
|
}
|
|
2701
2751
|
/**
|
|
@@ -2764,9 +2814,13 @@ class UtilsUpgrade {
|
|
|
2764
2814
|
// get the table's column names
|
|
2765
2815
|
const colNames = await this.getTableColumnNames(mDB, table);
|
|
2766
2816
|
this._alterTables[`${table}`] = colNames;
|
|
2817
|
+
const tmpTable = `_temp_${table}`;
|
|
2818
|
+
// Drop the tmpTable if exists
|
|
2819
|
+
const delStmt = `DROP TABLE IF EXISTS ${tmpTable};`;
|
|
2820
|
+
await this._uSQLite.prepareRun(mDB, delStmt, []);
|
|
2767
2821
|
// prefix the table with _temp_
|
|
2768
2822
|
let stmt = `ALTER TABLE ${table} RENAME `;
|
|
2769
|
-
stmt += `TO
|
|
2823
|
+
stmt += `TO ${tmpTable};`;
|
|
2770
2824
|
const lastId = await this._uSQLite.prepareRun(mDB, stmt, []);
|
|
2771
2825
|
if (lastId < 0) {
|
|
2772
2826
|
let msg = 'BackupTable: lastId < 0';
|
|
@@ -2915,24 +2969,24 @@ class Database {
|
|
|
2915
2969
|
// encrypted: boolean,
|
|
2916
2970
|
// mode: string,
|
|
2917
2971
|
version, upgDict) {
|
|
2918
|
-
this.
|
|
2919
|
-
this.
|
|
2920
|
-
this.
|
|
2921
|
-
this.
|
|
2972
|
+
this.fileUtil = new utilsFile_1$1.UtilsFile();
|
|
2973
|
+
this.sqliteUtil = new utilsSQLite_1.UtilsSQLite();
|
|
2974
|
+
this.jsonUtil = new utilsJson_1$1.UtilsJson();
|
|
2975
|
+
this.dropUtil = new utilsDrop_1.UtilsDrop();
|
|
2922
2976
|
// private _uGlobal: GlobalSQLite = new GlobalSQLite();
|
|
2923
2977
|
// private _uEncrypt: UtilsEncryption = new UtilsEncryption();
|
|
2924
|
-
this.
|
|
2925
|
-
this.
|
|
2926
|
-
this.
|
|
2927
|
-
this.
|
|
2928
|
-
this.
|
|
2978
|
+
this.upgradeUtil = new utilsUpgrade_1.UtilsUpgrade();
|
|
2979
|
+
this.importFromJsonUtil = new importFromJson_1.ImportFromJson();
|
|
2980
|
+
this.exportToJsonUtil = new exportToJson_1.ExportToJson();
|
|
2981
|
+
this.upgradeVersionDict = {};
|
|
2982
|
+
this.dbName = dbName;
|
|
2929
2983
|
// this._encrypted = encrypted;
|
|
2930
2984
|
// this._mode = mode;
|
|
2931
|
-
this.
|
|
2932
|
-
this.
|
|
2933
|
-
this.
|
|
2934
|
-
this.
|
|
2935
|
-
if (this.
|
|
2985
|
+
this.version = version;
|
|
2986
|
+
this.upgradeVersionDict = upgDict;
|
|
2987
|
+
this.pathDB = this.fileUtil.getFilePath(dbName);
|
|
2988
|
+
this._isDbOpen = false;
|
|
2989
|
+
if (this.pathDB.length === 0)
|
|
2936
2990
|
throw new Error('Could not generate a path to ' + dbName);
|
|
2937
2991
|
}
|
|
2938
2992
|
/**
|
|
@@ -2943,7 +2997,7 @@ class Database {
|
|
|
2943
2997
|
* @since 0.0.1
|
|
2944
2998
|
*/
|
|
2945
2999
|
isDBOpen() {
|
|
2946
|
-
return this.
|
|
3000
|
+
return this._isDbOpen;
|
|
2947
3001
|
}
|
|
2948
3002
|
/**
|
|
2949
3003
|
* Open
|
|
@@ -2951,7 +3005,7 @@ class Database {
|
|
|
2951
3005
|
* @returns Promise<boolean>
|
|
2952
3006
|
*/
|
|
2953
3007
|
async open() {
|
|
2954
|
-
this.
|
|
3008
|
+
this._isDbOpen = false;
|
|
2955
3009
|
// let password = '';
|
|
2956
3010
|
try {
|
|
2957
3011
|
/*
|
|
@@ -2973,34 +3027,34 @@ class Database {
|
|
|
2973
3027
|
await this._uEncrypt.encryptDatabase(this._pathDB, password);
|
|
2974
3028
|
}
|
|
2975
3029
|
*/
|
|
2976
|
-
this.
|
|
3030
|
+
this.database = await this.sqliteUtil.openOrCreateDatabase(this.pathDB /*,
|
|
2977
3031
|
password,*/);
|
|
2978
|
-
const curVersion = await this.
|
|
2979
|
-
this.
|
|
2980
|
-
if (this.
|
|
2981
|
-
Object.keys(this.
|
|
3032
|
+
const curVersion = await this.sqliteUtil.getVersion(this.database);
|
|
3033
|
+
this._isDbOpen = true;
|
|
3034
|
+
if (this.version > curVersion &&
|
|
3035
|
+
Object.keys(this.upgradeVersionDict).length > 0) {
|
|
2982
3036
|
try {
|
|
2983
3037
|
// execute the upgrade flow process
|
|
2984
|
-
await this.
|
|
3038
|
+
await this.upgradeUtil.onUpgrade(this.database, this.upgradeVersionDict, this.dbName, curVersion, this.version);
|
|
2985
3039
|
// delete the backup database
|
|
2986
|
-
await this.
|
|
3040
|
+
await this.fileUtil.deleteFileName(`backup-${this.dbName}`);
|
|
2987
3041
|
}
|
|
2988
3042
|
catch (err) {
|
|
2989
3043
|
// restore the database from backup
|
|
2990
3044
|
try {
|
|
2991
|
-
await this.
|
|
3045
|
+
await this.fileUtil.restoreFileName(this.dbName, 'backup');
|
|
2992
3046
|
}
|
|
2993
3047
|
catch (err) {
|
|
2994
|
-
|
|
3048
|
+
throw new Error(`Open: ${err}`);
|
|
2995
3049
|
}
|
|
2996
3050
|
}
|
|
2997
3051
|
}
|
|
2998
|
-
return
|
|
3052
|
+
return;
|
|
2999
3053
|
}
|
|
3000
3054
|
catch (err) {
|
|
3001
|
-
if (this.
|
|
3055
|
+
if (this._isDbOpen)
|
|
3002
3056
|
this.close();
|
|
3003
|
-
|
|
3057
|
+
throw new Error(`Open: ${err}`);
|
|
3004
3058
|
}
|
|
3005
3059
|
}
|
|
3006
3060
|
/**
|
|
@@ -3009,18 +3063,13 @@ class Database {
|
|
|
3009
3063
|
* @returns Promise<boolean>
|
|
3010
3064
|
*/
|
|
3011
3065
|
async close() {
|
|
3012
|
-
|
|
3013
|
-
|
|
3014
|
-
|
|
3015
|
-
|
|
3016
|
-
|
|
3017
|
-
|
|
3018
|
-
|
|
3019
|
-
this._isDBOpen = false;
|
|
3020
|
-
return Promise.resolve();
|
|
3021
|
-
});
|
|
3022
|
-
}
|
|
3023
|
-
return Promise.resolve();
|
|
3066
|
+
this.ensureDatabaseIsOpen();
|
|
3067
|
+
this.database.close((err) => {
|
|
3068
|
+
if (err) {
|
|
3069
|
+
throw new Error('Close failed: ${this.dbName} ${err}');
|
|
3070
|
+
}
|
|
3071
|
+
this._isDbOpen = false;
|
|
3072
|
+
});
|
|
3024
3073
|
}
|
|
3025
3074
|
/**
|
|
3026
3075
|
* GetVersion
|
|
@@ -3028,21 +3077,15 @@ class Database {
|
|
|
3028
3077
|
* @returns Promise<number>
|
|
3029
3078
|
*/
|
|
3030
3079
|
async getVersion() {
|
|
3031
|
-
|
|
3032
|
-
|
|
3033
|
-
|
|
3034
|
-
|
|
3035
|
-
}
|
|
3036
|
-
catch (err) {
|
|
3037
|
-
if (this._isDBOpen)
|
|
3038
|
-
this.close();
|
|
3039
|
-
return Promise.reject(`getVersion: ${err}`);
|
|
3040
|
-
}
|
|
3080
|
+
this.ensureDatabaseIsOpen();
|
|
3081
|
+
try {
|
|
3082
|
+
const currentVersion = await this.sqliteUtil.getVersion(this.database);
|
|
3083
|
+
return currentVersion;
|
|
3041
3084
|
}
|
|
3042
|
-
|
|
3043
|
-
|
|
3044
|
-
|
|
3045
|
-
|
|
3085
|
+
catch (err) {
|
|
3086
|
+
if (this._isDbOpen)
|
|
3087
|
+
this.close();
|
|
3088
|
+
throw new Error(`getVersion: ${err}`);
|
|
3046
3089
|
}
|
|
3047
3090
|
}
|
|
3048
3091
|
/**
|
|
@@ -3053,14 +3096,14 @@ class Database {
|
|
|
3053
3096
|
*/
|
|
3054
3097
|
async deleteDB(dbName) {
|
|
3055
3098
|
// test if file exists
|
|
3056
|
-
const isExists = this.
|
|
3057
|
-
if (isExists && !this.
|
|
3099
|
+
const isExists = this.fileUtil.isFileExists(dbName);
|
|
3100
|
+
if (isExists && !this._isDbOpen) {
|
|
3058
3101
|
// open the database
|
|
3059
3102
|
try {
|
|
3060
3103
|
await this.open();
|
|
3061
3104
|
}
|
|
3062
3105
|
catch (err) {
|
|
3063
|
-
|
|
3106
|
+
throw new Error(`DeleteDB: ${err}`);
|
|
3064
3107
|
}
|
|
3065
3108
|
}
|
|
3066
3109
|
// close the database
|
|
@@ -3068,20 +3111,18 @@ class Database {
|
|
|
3068
3111
|
await this.close();
|
|
3069
3112
|
}
|
|
3070
3113
|
catch (err) {
|
|
3071
|
-
|
|
3114
|
+
throw new Error('DeleteDB: Close failed');
|
|
3072
3115
|
}
|
|
3073
3116
|
// delete the database
|
|
3074
3117
|
if (isExists) {
|
|
3075
3118
|
try {
|
|
3076
|
-
await this.
|
|
3119
|
+
await this.fileUtil.deleteFileName(dbName);
|
|
3077
3120
|
}
|
|
3078
3121
|
catch (err) {
|
|
3079
|
-
|
|
3080
|
-
msg += ` failed ${err}`;
|
|
3081
|
-
return Promise.reject(msg);
|
|
3122
|
+
throw new Error(`DeleteDB: deleteFile ${dbName} failed ${err}`);
|
|
3082
3123
|
}
|
|
3083
3124
|
}
|
|
3084
|
-
return
|
|
3125
|
+
return;
|
|
3085
3126
|
}
|
|
3086
3127
|
/**
|
|
3087
3128
|
* IsTableExists
|
|
@@ -3089,20 +3130,14 @@ class Database {
|
|
|
3089
3130
|
* @returns
|
|
3090
3131
|
*/
|
|
3091
3132
|
async isTableExists(tableName) {
|
|
3092
|
-
|
|
3093
|
-
|
|
3094
|
-
|
|
3095
|
-
|
|
3096
|
-
|
|
3097
|
-
}
|
|
3098
|
-
catch (err) {
|
|
3099
|
-
return Promise.reject(`IsTableExists: ${err}`);
|
|
3100
|
-
}
|
|
3133
|
+
this.ensureDatabaseIsOpen();
|
|
3134
|
+
const isOpen = this._isDbOpen;
|
|
3135
|
+
try {
|
|
3136
|
+
const tableExistsResult = await this.jsonUtil.isTableExists(this.database, isOpen, tableName);
|
|
3137
|
+
return tableExistsResult;
|
|
3101
3138
|
}
|
|
3102
|
-
|
|
3103
|
-
|
|
3104
|
-
msg += `not opened`;
|
|
3105
|
-
return Promise.reject(msg);
|
|
3139
|
+
catch (err) {
|
|
3140
|
+
throw new Error(`IsTableExists: ${err}`);
|
|
3106
3141
|
}
|
|
3107
3142
|
}
|
|
3108
3143
|
/**
|
|
@@ -3111,18 +3146,14 @@ class Database {
|
|
|
3111
3146
|
* @returns Promise<number>
|
|
3112
3147
|
*/
|
|
3113
3148
|
async createSyncTable() {
|
|
3114
|
-
|
|
3115
|
-
let msg = `CreateSyncTable: Database ${this._dbName} `;
|
|
3116
|
-
msg += `not opened`;
|
|
3117
|
-
return Promise.reject(msg);
|
|
3118
|
-
}
|
|
3149
|
+
this.ensureDatabaseIsOpen();
|
|
3119
3150
|
let changes = -1;
|
|
3120
|
-
const isOpen = this.
|
|
3151
|
+
const isOpen = this._isDbOpen;
|
|
3121
3152
|
// check if the table has already being created
|
|
3122
3153
|
try {
|
|
3123
|
-
const retB = await this.
|
|
3154
|
+
const retB = await this.jsonUtil.isTableExists(this.database, isOpen, 'sync_table');
|
|
3124
3155
|
if (!retB) {
|
|
3125
|
-
const isLastModified = await this.
|
|
3156
|
+
const isLastModified = await this.jsonUtil.isLastModified(this.database, isOpen);
|
|
3126
3157
|
if (isLastModified) {
|
|
3127
3158
|
const date = Math.round(new Date().getTime() / 1000);
|
|
3128
3159
|
let stmts = `
|
|
@@ -3132,23 +3163,23 @@ class Database {
|
|
|
3132
3163
|
);`;
|
|
3133
3164
|
stmts += `INSERT INTO sync_table (sync_date) VALUES (
|
|
3134
3165
|
"${date}");`;
|
|
3135
|
-
changes = await this.
|
|
3166
|
+
changes = await this.sqliteUtil.execute(this.database, stmts);
|
|
3136
3167
|
if (changes < 0) {
|
|
3137
|
-
|
|
3168
|
+
throw new Error(`CreateSyncTable: failed changes < 0`);
|
|
3138
3169
|
}
|
|
3139
3170
|
}
|
|
3140
3171
|
else {
|
|
3141
|
-
|
|
3172
|
+
throw new Error('No last_modified column in tables');
|
|
3142
3173
|
}
|
|
3143
3174
|
}
|
|
3144
3175
|
else {
|
|
3145
3176
|
changes = 0;
|
|
3146
3177
|
}
|
|
3147
3178
|
console.log(`>>> CreateSyncTable changes: ${changes}`);
|
|
3148
|
-
return
|
|
3179
|
+
return changes;
|
|
3149
3180
|
}
|
|
3150
3181
|
catch (err) {
|
|
3151
|
-
|
|
3182
|
+
throw new Error(`CreateSyncTable: ${err}`);
|
|
3152
3183
|
}
|
|
3153
3184
|
}
|
|
3154
3185
|
/**
|
|
@@ -3158,20 +3189,16 @@ class Database {
|
|
|
3158
3189
|
* @returns Promise<{result: boolean, message: string}>
|
|
3159
3190
|
*/
|
|
3160
3191
|
async setSyncDate(syncDate) {
|
|
3161
|
-
|
|
3162
|
-
let msg = `SetSyncDate: Database ${this._dbName} `;
|
|
3163
|
-
msg += `not opened`;
|
|
3164
|
-
return { result: false, message: msg };
|
|
3165
|
-
}
|
|
3192
|
+
this.ensureDatabaseIsOpen();
|
|
3166
3193
|
try {
|
|
3167
|
-
const isTable = await this.
|
|
3194
|
+
const isTable = await this.jsonUtil.isTableExists(this.database, this._isDbOpen, 'sync_table');
|
|
3168
3195
|
if (!isTable) {
|
|
3169
|
-
|
|
3196
|
+
throw new Error('No sync_table available');
|
|
3170
3197
|
}
|
|
3171
|
-
const
|
|
3198
|
+
const syncDateUnixTimestamp = Math.round(new Date(syncDate).getTime() / 1000);
|
|
3172
3199
|
let stmt = `UPDATE sync_table SET sync_date = `;
|
|
3173
|
-
stmt += `${
|
|
3174
|
-
const changes = await this.
|
|
3200
|
+
stmt += `${syncDateUnixTimestamp} WHERE id = 1;`;
|
|
3201
|
+
const changes = await this.sqliteUtil.execute(this.database, stmt);
|
|
3175
3202
|
if (changes < 0) {
|
|
3176
3203
|
return { result: false, message: 'setSyncDate failed' };
|
|
3177
3204
|
}
|
|
@@ -3189,19 +3216,15 @@ class Database {
|
|
|
3189
3216
|
* @returns Promise<{syncDate: number, message: string}>
|
|
3190
3217
|
*/
|
|
3191
3218
|
async getSyncDate() {
|
|
3192
|
-
|
|
3193
|
-
let msg = `GetSyncDate: Database ${this._dbName} `;
|
|
3194
|
-
msg += `not opened`;
|
|
3195
|
-
return { syncDate: 0, message: msg };
|
|
3196
|
-
}
|
|
3219
|
+
this.ensureDatabaseIsOpen();
|
|
3197
3220
|
try {
|
|
3198
|
-
const isTable = await this.
|
|
3221
|
+
const isTable = await this.jsonUtil.isTableExists(this.database, this._isDbOpen, 'sync_table');
|
|
3199
3222
|
if (!isTable) {
|
|
3200
|
-
|
|
3223
|
+
throw new Error('No sync_table available');
|
|
3201
3224
|
}
|
|
3202
|
-
const syncDate = await this.
|
|
3225
|
+
const syncDate = await this.exportToJsonUtil.getSyncDate(this.database);
|
|
3203
3226
|
if (syncDate > 0) {
|
|
3204
|
-
return { syncDate
|
|
3227
|
+
return { syncDate };
|
|
3205
3228
|
}
|
|
3206
3229
|
else {
|
|
3207
3230
|
return { syncDate: 0, message: `setSyncDate failed` };
|
|
@@ -3218,32 +3241,31 @@ class Database {
|
|
|
3218
3241
|
* @returns Promise<number>
|
|
3219
3242
|
*/
|
|
3220
3243
|
async executeSQL(sql, transaction) {
|
|
3221
|
-
|
|
3222
|
-
let msg = `ExecuteSQL: Database ${this._dbName} `;
|
|
3223
|
-
msg += `not opened`;
|
|
3224
|
-
return Promise.reject(msg);
|
|
3225
|
-
}
|
|
3244
|
+
this.ensureDatabaseIsOpen();
|
|
3226
3245
|
try {
|
|
3227
|
-
if (transaction)
|
|
3228
|
-
await this.
|
|
3229
|
-
|
|
3246
|
+
if (transaction) {
|
|
3247
|
+
await this.sqliteUtil.beginTransaction(this.database, this._isDbOpen);
|
|
3248
|
+
}
|
|
3249
|
+
const changes = await this.sqliteUtil.execute(this.database, sql);
|
|
3230
3250
|
if (changes < 0) {
|
|
3231
|
-
|
|
3251
|
+
throw new Error('ExecuteSQL: changes < 0');
|
|
3232
3252
|
}
|
|
3233
|
-
if (transaction)
|
|
3234
|
-
await this.
|
|
3235
|
-
|
|
3253
|
+
if (transaction) {
|
|
3254
|
+
await this.sqliteUtil.commitTransaction(this.database, this._isDbOpen);
|
|
3255
|
+
}
|
|
3256
|
+
return changes;
|
|
3236
3257
|
}
|
|
3237
|
-
catch (
|
|
3238
|
-
let
|
|
3258
|
+
catch (executeError) {
|
|
3259
|
+
let message = `${executeError}`;
|
|
3239
3260
|
try {
|
|
3240
|
-
if (transaction)
|
|
3241
|
-
await this.
|
|
3261
|
+
if (transaction) {
|
|
3262
|
+
await this.sqliteUtil.rollbackTransaction(this.database, this._isDbOpen);
|
|
3263
|
+
}
|
|
3242
3264
|
}
|
|
3243
|
-
catch (
|
|
3244
|
-
|
|
3265
|
+
catch (rollbackErr) {
|
|
3266
|
+
message += ` : ${rollbackErr}`;
|
|
3245
3267
|
}
|
|
3246
|
-
|
|
3268
|
+
throw new Error(`ExecuteSQL: ${message}`);
|
|
3247
3269
|
}
|
|
3248
3270
|
}
|
|
3249
3271
|
/**
|
|
@@ -3254,17 +3276,13 @@ class Database {
|
|
|
3254
3276
|
* @returns Promise<any[]>
|
|
3255
3277
|
*/
|
|
3256
3278
|
async selectSQL(sql, values) {
|
|
3257
|
-
|
|
3258
|
-
let msg = `SelectSQL: Database ${this._dbName} `;
|
|
3259
|
-
msg += `not opened`;
|
|
3260
|
-
return Promise.reject(msg);
|
|
3261
|
-
}
|
|
3279
|
+
this.ensureDatabaseIsOpen();
|
|
3262
3280
|
try {
|
|
3263
|
-
const
|
|
3264
|
-
return
|
|
3281
|
+
const selectResult = await this.sqliteUtil.queryAll(this.database, sql, values);
|
|
3282
|
+
return selectResult;
|
|
3265
3283
|
}
|
|
3266
3284
|
catch (err) {
|
|
3267
|
-
|
|
3285
|
+
throw new Error(`SelectSQL: ${err}`);
|
|
3268
3286
|
}
|
|
3269
3287
|
}
|
|
3270
3288
|
/**
|
|
@@ -3275,39 +3293,40 @@ class Database {
|
|
|
3275
3293
|
* @returns Promise<{changes:number, lastId:number}>
|
|
3276
3294
|
*/
|
|
3277
3295
|
async runSQL(statement, values, transaction) {
|
|
3278
|
-
|
|
3279
|
-
|
|
3280
|
-
msg += `not opened`;
|
|
3281
|
-
return Promise.reject(msg);
|
|
3282
|
-
}
|
|
3283
|
-
const retRes = { changes: -1, lastId: -1 };
|
|
3296
|
+
this.ensureDatabaseIsOpen();
|
|
3297
|
+
const result = { changes: -1, lastId: -1 };
|
|
3284
3298
|
let initChanges = -1;
|
|
3285
3299
|
try {
|
|
3286
|
-
initChanges = await this.
|
|
3300
|
+
initChanges = await this.sqliteUtil.dbChanges(this.database);
|
|
3287
3301
|
// start a transaction
|
|
3288
|
-
if (transaction)
|
|
3289
|
-
await this.
|
|
3302
|
+
if (transaction) {
|
|
3303
|
+
await this.sqliteUtil.beginTransaction(this.database, this._isDbOpen);
|
|
3304
|
+
}
|
|
3290
3305
|
}
|
|
3291
3306
|
catch (err) {
|
|
3292
|
-
|
|
3307
|
+
throw new Error(`RunSQL: ${err}`);
|
|
3293
3308
|
}
|
|
3294
3309
|
try {
|
|
3295
|
-
const lastId = await this.
|
|
3310
|
+
const lastId = await this.sqliteUtil.prepareRun(this.database, statement, values);
|
|
3296
3311
|
if (lastId < 0) {
|
|
3297
|
-
if (transaction)
|
|
3298
|
-
await this.
|
|
3299
|
-
|
|
3312
|
+
if (transaction) {
|
|
3313
|
+
await this.sqliteUtil.rollbackTransaction(this.database, this._isDbOpen);
|
|
3314
|
+
}
|
|
3315
|
+
throw new Error(`RunSQL: return LastId < 0`);
|
|
3300
3316
|
}
|
|
3301
|
-
if (transaction)
|
|
3302
|
-
await this.
|
|
3303
|
-
|
|
3304
|
-
|
|
3305
|
-
|
|
3317
|
+
if (transaction) {
|
|
3318
|
+
await this.sqliteUtil.commitTransaction(this.database, this._isDbOpen);
|
|
3319
|
+
}
|
|
3320
|
+
result.changes =
|
|
3321
|
+
(await this.sqliteUtil.dbChanges(this.database)) - initChanges;
|
|
3322
|
+
result.lastId = lastId;
|
|
3323
|
+
return result;
|
|
3306
3324
|
}
|
|
3307
3325
|
catch (err) {
|
|
3308
|
-
if (transaction)
|
|
3309
|
-
await this.
|
|
3310
|
-
|
|
3326
|
+
if (transaction) {
|
|
3327
|
+
await this.sqliteUtil.rollbackTransaction(this.database, this._isDbOpen);
|
|
3328
|
+
}
|
|
3329
|
+
throw new Error(`RunSQL: ${err}`);
|
|
3311
3330
|
}
|
|
3312
3331
|
}
|
|
3313
3332
|
/**
|
|
@@ -3317,103 +3336,99 @@ class Database {
|
|
|
3317
3336
|
* @returns Promise<{changes:number, lastId:number}>
|
|
3318
3337
|
*/
|
|
3319
3338
|
async execSet(set, transaction) {
|
|
3320
|
-
|
|
3321
|
-
|
|
3322
|
-
msg += `not opened`;
|
|
3323
|
-
return Promise.reject(msg);
|
|
3324
|
-
}
|
|
3325
|
-
const retRes = { changes: -1, lastId: -1 };
|
|
3339
|
+
this.ensureDatabaseIsOpen();
|
|
3340
|
+
const result = { changes: -1, lastId: -1 };
|
|
3326
3341
|
let initChanges = -1;
|
|
3327
3342
|
try {
|
|
3328
|
-
initChanges = await this.
|
|
3343
|
+
initChanges = await this.sqliteUtil.dbChanges(this.database);
|
|
3329
3344
|
// start a transaction
|
|
3330
|
-
if (transaction)
|
|
3331
|
-
await this.
|
|
3345
|
+
if (transaction) {
|
|
3346
|
+
await this.sqliteUtil.beginTransaction(this.database, this._isDbOpen);
|
|
3347
|
+
}
|
|
3332
3348
|
}
|
|
3333
3349
|
catch (err) {
|
|
3334
|
-
|
|
3350
|
+
throw new Error(`ExecSet: ${err}`);
|
|
3335
3351
|
}
|
|
3336
3352
|
try {
|
|
3337
|
-
|
|
3338
|
-
if (transaction)
|
|
3339
|
-
await this.
|
|
3340
|
-
|
|
3341
|
-
|
|
3353
|
+
result.lastId = await this.sqliteUtil.executeSet(this.database, set);
|
|
3354
|
+
if (transaction) {
|
|
3355
|
+
await this.sqliteUtil.commitTransaction(this.database, this._isDbOpen);
|
|
3356
|
+
}
|
|
3357
|
+
result.changes =
|
|
3358
|
+
(await this.sqliteUtil.dbChanges(this.database)) - initChanges;
|
|
3359
|
+
return result;
|
|
3342
3360
|
}
|
|
3343
3361
|
catch (err) {
|
|
3344
|
-
const
|
|
3362
|
+
const message = err;
|
|
3345
3363
|
try {
|
|
3346
|
-
if (transaction)
|
|
3347
|
-
await this.
|
|
3364
|
+
if (transaction) {
|
|
3365
|
+
await this.sqliteUtil.rollbackTransaction(this.database, this._isDbOpen);
|
|
3366
|
+
}
|
|
3348
3367
|
}
|
|
3349
3368
|
catch (err) {
|
|
3350
|
-
|
|
3369
|
+
throw new Error(`ExecSet: ${message}: ` + `${err}`);
|
|
3351
3370
|
}
|
|
3352
3371
|
}
|
|
3353
3372
|
}
|
|
3354
3373
|
async getTableList() {
|
|
3355
|
-
|
|
3356
|
-
let msg = `GetTableList: Database ${this._dbName} `;
|
|
3357
|
-
msg += `not opened`;
|
|
3358
|
-
return Promise.reject(msg);
|
|
3359
|
-
}
|
|
3374
|
+
this.ensureDatabaseIsOpen();
|
|
3360
3375
|
try {
|
|
3361
|
-
const
|
|
3362
|
-
return
|
|
3376
|
+
const tableNames = await this.dropUtil.getTablesNames(this.database);
|
|
3377
|
+
return tableNames;
|
|
3363
3378
|
}
|
|
3364
3379
|
catch (err) {
|
|
3365
|
-
|
|
3380
|
+
throw new Error(`GetTableList: ${err}`);
|
|
3366
3381
|
}
|
|
3367
3382
|
}
|
|
3368
3383
|
async importJson(jsonData) {
|
|
3369
3384
|
let changes = 0;
|
|
3370
|
-
|
|
3371
|
-
|
|
3372
|
-
|
|
3373
|
-
|
|
3374
|
-
|
|
3375
|
-
|
|
3376
|
-
|
|
3377
|
-
|
|
3378
|
-
}
|
|
3379
|
-
}
|
|
3380
|
-
if (jsonData.views && jsonData.views.length > 0) {
|
|
3381
|
-
// create the views
|
|
3382
|
-
changes += await this._iFJson.createViews(this._mDB, jsonData);
|
|
3385
|
+
this.ensureDatabaseIsOpen();
|
|
3386
|
+
try {
|
|
3387
|
+
if (jsonData.tables && jsonData.tables.length > 0) {
|
|
3388
|
+
// create the database schema
|
|
3389
|
+
changes = await this.importFromJsonUtil.createDatabaseSchema(this.database, jsonData);
|
|
3390
|
+
if (changes != -1) {
|
|
3391
|
+
// create the tables data
|
|
3392
|
+
changes += await this.importFromJsonUtil.createTablesData(this.database, jsonData);
|
|
3383
3393
|
}
|
|
3384
|
-
return Promise.resolve(changes);
|
|
3385
3394
|
}
|
|
3386
|
-
|
|
3387
|
-
|
|
3395
|
+
if (jsonData.views && jsonData.views.length > 0) {
|
|
3396
|
+
// create the views
|
|
3397
|
+
changes += await this.importFromJsonUtil.createViews(this.database, jsonData);
|
|
3388
3398
|
}
|
|
3399
|
+
return changes;
|
|
3389
3400
|
}
|
|
3390
|
-
|
|
3391
|
-
|
|
3401
|
+
catch (err) {
|
|
3402
|
+
throw new Error(`ImportJson: ${err}`);
|
|
3392
3403
|
}
|
|
3393
3404
|
}
|
|
3394
3405
|
async exportJson(mode) {
|
|
3395
3406
|
const inJson = {};
|
|
3396
|
-
inJson.database = this.
|
|
3397
|
-
inJson.version = this.
|
|
3407
|
+
inJson.database = this.dbName.slice(0, -9);
|
|
3408
|
+
inJson.version = this.version;
|
|
3398
3409
|
inJson.encrypted = false;
|
|
3399
3410
|
inJson.mode = mode;
|
|
3400
|
-
|
|
3401
|
-
|
|
3402
|
-
|
|
3403
|
-
|
|
3404
|
-
|
|
3405
|
-
|
|
3406
|
-
}
|
|
3407
|
-
else {
|
|
3408
|
-
return Promise.reject(`ExportJson: retJson not valid`);
|
|
3409
|
-
}
|
|
3411
|
+
this.ensureDatabaseIsOpen();
|
|
3412
|
+
try {
|
|
3413
|
+
const jsonResult = await this.exportToJsonUtil.createExportObject(this.database, inJson);
|
|
3414
|
+
const isValid = this.jsonUtil.isJsonSQLite(jsonResult);
|
|
3415
|
+
if (isValid) {
|
|
3416
|
+
return jsonResult;
|
|
3410
3417
|
}
|
|
3411
|
-
|
|
3412
|
-
|
|
3418
|
+
else {
|
|
3419
|
+
throw new Error(`ExportJson: retJson not valid`);
|
|
3413
3420
|
}
|
|
3414
3421
|
}
|
|
3415
|
-
|
|
3416
|
-
|
|
3422
|
+
catch (err) {
|
|
3423
|
+
throw new Error(`ExportJson: ${err}`);
|
|
3424
|
+
}
|
|
3425
|
+
}
|
|
3426
|
+
/**
|
|
3427
|
+
* Throws an error if `this._isDbOpen` is `false`.
|
|
3428
|
+
*/
|
|
3429
|
+
ensureDatabaseIsOpen() {
|
|
3430
|
+
if (!this._isDbOpen || !this.database) {
|
|
3431
|
+
throw new Error(`getVersion: Database ${this.dbName} is not open yet. You should open it first.`);
|
|
3417
3432
|
}
|
|
3418
3433
|
}
|
|
3419
3434
|
}
|
|
@@ -3426,49 +3441,15 @@ const utilsJson_1 = utilsJson;
|
|
|
3426
3441
|
const utilsFile_1 = utilsFile;
|
|
3427
3442
|
class CapacitorSQLite {
|
|
3428
3443
|
constructor() {
|
|
3429
|
-
this.
|
|
3430
|
-
this.
|
|
3431
|
-
this.
|
|
3432
|
-
this.
|
|
3433
|
-
}
|
|
3434
|
-
async initWebStore() {
|
|
3435
|
-
return Promise.reject('Method not implemented.');
|
|
3436
|
-
}
|
|
3437
|
-
async saveToStore(options) {
|
|
3438
|
-
console.log(`${JSON.stringify(options)}`);
|
|
3439
|
-
return Promise.reject('Method not implemented.');
|
|
3440
|
-
}
|
|
3441
|
-
async isSecretStored() {
|
|
3442
|
-
return Promise.reject('Method not implemented.');
|
|
3443
|
-
}
|
|
3444
|
-
async setEncryptionSecret(options) {
|
|
3445
|
-
console.log(`${JSON.stringify(options)}`);
|
|
3446
|
-
return Promise.reject('Method not implemented.');
|
|
3447
|
-
}
|
|
3448
|
-
async changeEncryptionSecret(options) {
|
|
3449
|
-
console.log(`${JSON.stringify(options)}`);
|
|
3450
|
-
return Promise.reject('Method not implemented.');
|
|
3451
|
-
}
|
|
3452
|
-
async getNCDatabasePath(options) {
|
|
3453
|
-
console.log('getNCDatabasePath', options);
|
|
3454
|
-
return Promise.reject('Method not implemented.');
|
|
3455
|
-
}
|
|
3456
|
-
async createNCConnection(options) {
|
|
3457
|
-
console.log('createNCConnection', options);
|
|
3458
|
-
return Promise.reject('Method not implemented.');
|
|
3459
|
-
}
|
|
3460
|
-
async closeNCConnection(options) {
|
|
3461
|
-
console.log('closeNCConnection', options);
|
|
3462
|
-
return Promise.reject('Method not implemented.');
|
|
3463
|
-
}
|
|
3464
|
-
async isNCDatabase(options) {
|
|
3465
|
-
console.log('isNCDatabase', options);
|
|
3466
|
-
return Promise.reject('Method not implemented.');
|
|
3444
|
+
this.versionUpgrades = {};
|
|
3445
|
+
this.databases = {};
|
|
3446
|
+
this.fileUtil = new utilsFile_1.UtilsFile();
|
|
3447
|
+
this.jsonUtil = new utilsJson_1.UtilsJson();
|
|
3467
3448
|
}
|
|
3468
3449
|
async createConnection(options) {
|
|
3469
|
-
const
|
|
3470
|
-
if (!
|
|
3471
|
-
|
|
3450
|
+
const optionKeys = Object.keys(options);
|
|
3451
|
+
if (!optionKeys.includes('database')) {
|
|
3452
|
+
throw new Error('Must provide a database name');
|
|
3472
3453
|
}
|
|
3473
3454
|
const dbName = options.database;
|
|
3474
3455
|
const version = options.version ? options.version : 1;
|
|
@@ -3484,612 +3465,382 @@ class CapacitorSQLite {
|
|
|
3484
3465
|
? options.mode
|
|
3485
3466
|
: 'no-encryption';
|
|
3486
3467
|
*/
|
|
3487
|
-
let
|
|
3488
|
-
const
|
|
3489
|
-
if (
|
|
3490
|
-
|
|
3491
|
-
|
|
3492
|
-
|
|
3493
|
-
|
|
3494
|
-
|
|
3495
|
-
|
|
3496
|
-
|
|
3497
|
-
|
|
3498
|
-
|
|
3499
|
-
|
|
3500
|
-
}
|
|
3501
|
-
catch (err) {
|
|
3502
|
-
return Promise.reject(err);
|
|
3503
|
-
}
|
|
3468
|
+
let upgrades = {};
|
|
3469
|
+
const versionUpgradeKeys = Object.keys(this.versionUpgrades);
|
|
3470
|
+
if (versionUpgradeKeys.length !== 0 &&
|
|
3471
|
+
versionUpgradeKeys.includes(dbName)) {
|
|
3472
|
+
upgrades = this.versionUpgrades[dbName];
|
|
3473
|
+
}
|
|
3474
|
+
const databaseConnection = new Database_1.Database(dbName + 'SQLite.db',
|
|
3475
|
+
/* encrypted,
|
|
3476
|
+
inMode,
|
|
3477
|
+
*/
|
|
3478
|
+
version, upgrades);
|
|
3479
|
+
this.databases[dbName] = databaseConnection;
|
|
3480
|
+
return;
|
|
3504
3481
|
}
|
|
3505
3482
|
async closeConnection(options) {
|
|
3506
|
-
|
|
3507
|
-
|
|
3508
|
-
|
|
3509
|
-
}
|
|
3510
|
-
const dbName = options.database;
|
|
3511
|
-
keys = Object.keys(this._dbDict);
|
|
3512
|
-
if (!keys.includes(dbName)) {
|
|
3513
|
-
return Promise.resolve();
|
|
3514
|
-
}
|
|
3515
|
-
const mDB = this._dbDict[dbName];
|
|
3516
|
-
if (mDB.isDBOpen()) {
|
|
3483
|
+
const dbName = this.getOptionValue(options, 'database');
|
|
3484
|
+
const database = this.getDatabaseConnectionOrThrowError(dbName);
|
|
3485
|
+
if (database.isDBOpen()) {
|
|
3517
3486
|
// close the database
|
|
3518
3487
|
try {
|
|
3519
|
-
await
|
|
3488
|
+
await database.close();
|
|
3520
3489
|
}
|
|
3521
3490
|
catch (err) {
|
|
3522
|
-
|
|
3523
|
-
'close ' +
|
|
3524
|
-
dbName +
|
|
3525
|
-
' failed ' +
|
|
3526
|
-
err);
|
|
3491
|
+
throw new Error(`CloseConnection command failed: close ${dbName} failed ${err.message}`);
|
|
3527
3492
|
}
|
|
3528
3493
|
}
|
|
3529
3494
|
// remove the connection from dictionary
|
|
3530
|
-
delete this.
|
|
3531
|
-
return Promise.resolve();
|
|
3495
|
+
delete this.databases[dbName];
|
|
3532
3496
|
}
|
|
3533
3497
|
async echo(options) {
|
|
3534
|
-
const
|
|
3535
|
-
|
|
3536
|
-
|
|
3537
|
-
|
|
3538
|
-
const ret = {};
|
|
3539
|
-
ret.value = options.value;
|
|
3540
|
-
return Promise.resolve(ret);
|
|
3498
|
+
const echoValue = this.getOptionValue(options, 'value');
|
|
3499
|
+
const echoResult = {};
|
|
3500
|
+
echoResult.value = echoValue;
|
|
3501
|
+
return echoResult;
|
|
3541
3502
|
}
|
|
3542
3503
|
async open(options) {
|
|
3543
|
-
|
|
3544
|
-
|
|
3545
|
-
return Promise.reject('Must provide a database name');
|
|
3546
|
-
}
|
|
3547
|
-
const dbName = options.database;
|
|
3548
|
-
keys = Object.keys(this._dbDict);
|
|
3549
|
-
if (!keys.includes(dbName)) {
|
|
3550
|
-
return Promise.reject(`Open: No available connection for ${dbName}`);
|
|
3551
|
-
}
|
|
3552
|
-
const mDB = this._dbDict[dbName];
|
|
3504
|
+
const dbName = this.getOptionValue(options, 'database');
|
|
3505
|
+
const database = this.getDatabaseConnectionOrThrowError(dbName);
|
|
3553
3506
|
try {
|
|
3554
|
-
await
|
|
3555
|
-
return
|
|
3507
|
+
await database.open();
|
|
3508
|
+
return;
|
|
3556
3509
|
}
|
|
3557
3510
|
catch (err) {
|
|
3558
|
-
|
|
3511
|
+
throw new Error(`Open: ${err}`);
|
|
3559
3512
|
}
|
|
3560
3513
|
}
|
|
3561
3514
|
async close(options) {
|
|
3562
|
-
|
|
3563
|
-
|
|
3564
|
-
return Promise.reject('Must provide a database name');
|
|
3565
|
-
}
|
|
3566
|
-
const dbName = options.database;
|
|
3567
|
-
keys = Object.keys(this._dbDict);
|
|
3568
|
-
if (!keys.includes(dbName)) {
|
|
3569
|
-
return Promise.reject(`Close: No available connection for ${dbName}`);
|
|
3570
|
-
}
|
|
3571
|
-
const mDB = this._dbDict[dbName];
|
|
3515
|
+
const dbName = this.getOptionValue(options, 'database');
|
|
3516
|
+
const database = this.getDatabaseConnectionOrThrowError(dbName);
|
|
3572
3517
|
try {
|
|
3573
|
-
await
|
|
3574
|
-
return
|
|
3518
|
+
await database.close();
|
|
3519
|
+
return;
|
|
3575
3520
|
}
|
|
3576
3521
|
catch (err) {
|
|
3577
|
-
|
|
3522
|
+
throw new Error(`Close: ${err}`);
|
|
3578
3523
|
}
|
|
3579
3524
|
}
|
|
3580
|
-
async getUrl() {
|
|
3581
|
-
return Promise.reject('Method not implemented.');
|
|
3582
|
-
}
|
|
3583
3525
|
async getVersion(options) {
|
|
3584
|
-
|
|
3585
|
-
|
|
3586
|
-
return Promise.reject('Must provide a database name');
|
|
3587
|
-
}
|
|
3588
|
-
const dbName = options.database;
|
|
3589
|
-
keys = Object.keys(this._dbDict);
|
|
3590
|
-
if (!keys.includes(dbName)) {
|
|
3591
|
-
return Promise.reject(`Open: No available connection for ${dbName}`);
|
|
3592
|
-
}
|
|
3593
|
-
const mDB = this._dbDict[dbName];
|
|
3526
|
+
const dbName = this.getOptionValue(options, 'database');
|
|
3527
|
+
const database = this.getDatabaseConnectionOrThrowError(dbName);
|
|
3594
3528
|
try {
|
|
3595
|
-
const version = await
|
|
3596
|
-
const
|
|
3597
|
-
|
|
3598
|
-
return
|
|
3529
|
+
const version = await database.getVersion();
|
|
3530
|
+
const versionResult = {};
|
|
3531
|
+
versionResult.version = version;
|
|
3532
|
+
return versionResult;
|
|
3599
3533
|
}
|
|
3600
3534
|
catch (err) {
|
|
3601
|
-
|
|
3535
|
+
throw new Error(`GetVersion: ${err}`);
|
|
3602
3536
|
}
|
|
3603
3537
|
}
|
|
3604
3538
|
async getTableList(options) {
|
|
3605
|
-
|
|
3606
|
-
|
|
3607
|
-
return Promise.reject('Must provide a database name');
|
|
3608
|
-
}
|
|
3609
|
-
const dbName = options.database;
|
|
3610
|
-
keys = Object.keys(this._dbDict);
|
|
3611
|
-
if (!keys.includes(dbName)) {
|
|
3612
|
-
return Promise.reject(`Open: No available connection for ${dbName}`);
|
|
3613
|
-
}
|
|
3614
|
-
const mDB = this._dbDict[dbName];
|
|
3539
|
+
const dbName = this.getOptionValue(options, 'database');
|
|
3540
|
+
const database = this.getDatabaseConnectionOrThrowError(dbName);
|
|
3615
3541
|
try {
|
|
3616
|
-
const tableList = await
|
|
3617
|
-
const
|
|
3618
|
-
|
|
3619
|
-
return
|
|
3542
|
+
const tableList = await database.getTableList();
|
|
3543
|
+
const tableListResult = {};
|
|
3544
|
+
tableListResult.values = tableList;
|
|
3545
|
+
return tableListResult;
|
|
3620
3546
|
}
|
|
3621
3547
|
catch (err) {
|
|
3622
|
-
|
|
3548
|
+
throw new Error(`GetTableList: ${err}`);
|
|
3623
3549
|
}
|
|
3624
3550
|
}
|
|
3625
3551
|
async execute(options) {
|
|
3626
|
-
|
|
3627
|
-
|
|
3628
|
-
|
|
3629
|
-
|
|
3630
|
-
if (!keys.includes('statements') || options.statements.length === 0) {
|
|
3631
|
-
return Promise.reject('Must provide raw SQL statements');
|
|
3632
|
-
}
|
|
3633
|
-
const dbName = options.database;
|
|
3634
|
-
const statements = options.statements;
|
|
3635
|
-
let transaction;
|
|
3636
|
-
if (!keys.includes('transaction')) {
|
|
3637
|
-
transaction = true;
|
|
3638
|
-
}
|
|
3639
|
-
else {
|
|
3640
|
-
transaction = options.transaction;
|
|
3641
|
-
}
|
|
3642
|
-
keys = Object.keys(this._dbDict);
|
|
3643
|
-
if (!keys.includes(dbName)) {
|
|
3644
|
-
return Promise.reject(`Execute: No available connection for ${dbName}`);
|
|
3645
|
-
}
|
|
3646
|
-
const mDB = this._dbDict[dbName];
|
|
3552
|
+
const dbName = this.getOptionValue(options, 'database');
|
|
3553
|
+
const statements = this.getOptionValue(options, 'statements');
|
|
3554
|
+
const transaction = this.getOptionValue(options, 'transaction', true);
|
|
3555
|
+
const database = this.getDatabaseConnectionOrThrowError(dbName);
|
|
3647
3556
|
try {
|
|
3648
|
-
const
|
|
3649
|
-
if (
|
|
3650
|
-
|
|
3557
|
+
const executeResult = await database.executeSQL(statements, transaction);
|
|
3558
|
+
if (executeResult < 0) {
|
|
3559
|
+
throw new Error('Execute failed changes < 0');
|
|
3651
3560
|
}
|
|
3652
3561
|
else {
|
|
3653
|
-
return
|
|
3562
|
+
return { changes: { changes: executeResult } };
|
|
3654
3563
|
}
|
|
3655
3564
|
}
|
|
3656
3565
|
catch (err) {
|
|
3657
|
-
|
|
3566
|
+
throw new Error(`Execute failed: ${err}`);
|
|
3658
3567
|
}
|
|
3659
3568
|
}
|
|
3660
3569
|
async executeSet(options) {
|
|
3661
|
-
|
|
3662
|
-
|
|
3663
|
-
|
|
3664
|
-
|
|
3665
|
-
if (!keys.includes('set') || options.set.length === 0) {
|
|
3666
|
-
return Promise.reject('Must provide a non-empty set of SQL statements');
|
|
3667
|
-
}
|
|
3668
|
-
const dbName = options.database;
|
|
3669
|
-
const setOfStatements = options.set;
|
|
3670
|
-
let transaction;
|
|
3671
|
-
if (!keys.includes('transaction')) {
|
|
3672
|
-
transaction = true;
|
|
3673
|
-
}
|
|
3674
|
-
else {
|
|
3675
|
-
transaction = options.transaction;
|
|
3676
|
-
}
|
|
3677
|
-
keys = Object.keys(this._dbDict);
|
|
3678
|
-
if (!keys.includes(dbName)) {
|
|
3679
|
-
return Promise.reject(`ExecuteSet: No available connection for ${dbName}`);
|
|
3680
|
-
}
|
|
3681
|
-
const mDB = this._dbDict[dbName];
|
|
3570
|
+
const dbName = this.getOptionValue(options, 'database');
|
|
3571
|
+
const setOfStatements = this.getOptionValue(options, 'set');
|
|
3572
|
+
const transaction = this.getOptionValue(options, 'transaction', true);
|
|
3573
|
+
const database = this.getDatabaseConnectionOrThrowError(dbName);
|
|
3682
3574
|
for (const sStmt of setOfStatements) {
|
|
3683
3575
|
if (!('statement' in sStmt) || !('values' in sStmt)) {
|
|
3684
|
-
|
|
3576
|
+
throw new Error('ExecuteSet: Must provide a set as ' + 'Array of {statement,values}');
|
|
3685
3577
|
}
|
|
3686
3578
|
}
|
|
3687
3579
|
try {
|
|
3688
|
-
const
|
|
3689
|
-
if (
|
|
3690
|
-
|
|
3580
|
+
const execSetResult = await database.execSet(setOfStatements, transaction);
|
|
3581
|
+
if (execSetResult < 0) {
|
|
3582
|
+
throw new Error(`ExecuteSet failed changes <0`);
|
|
3691
3583
|
}
|
|
3692
3584
|
else {
|
|
3693
|
-
return
|
|
3585
|
+
return { changes: execSetResult };
|
|
3694
3586
|
}
|
|
3695
3587
|
}
|
|
3696
3588
|
catch (err) {
|
|
3697
|
-
|
|
3589
|
+
throw new Error(`ExecuteSet failed: ${err}`);
|
|
3698
3590
|
}
|
|
3699
3591
|
}
|
|
3700
3592
|
async run(options) {
|
|
3701
|
-
|
|
3702
|
-
|
|
3703
|
-
|
|
3704
|
-
|
|
3705
|
-
|
|
3706
|
-
return Promise.reject('Must provide a query statement');
|
|
3707
|
-
}
|
|
3708
|
-
if (!keys.includes('values')) {
|
|
3709
|
-
return Promise.reject('Must provide an Array of values');
|
|
3710
|
-
}
|
|
3711
|
-
const dbName = options.database;
|
|
3712
|
-
const statement = options.statement;
|
|
3713
|
-
const values = options.values.length > 0 ? options.values : [];
|
|
3714
|
-
let transaction;
|
|
3715
|
-
if (!keys.includes('transaction')) {
|
|
3716
|
-
transaction = true;
|
|
3717
|
-
}
|
|
3718
|
-
else {
|
|
3719
|
-
transaction = options.transaction;
|
|
3720
|
-
}
|
|
3721
|
-
keys = Object.keys(this._dbDict);
|
|
3722
|
-
if (!keys.includes(dbName)) {
|
|
3723
|
-
return Promise.reject(`Run: No available connection for ${dbName}`);
|
|
3724
|
-
}
|
|
3725
|
-
const mDB = this._dbDict[dbName];
|
|
3593
|
+
const dbName = this.getOptionValue(options, 'database');
|
|
3594
|
+
const statement = this.getOptionValue(options, 'statement');
|
|
3595
|
+
const values = this.getOptionValue(options, 'values', []);
|
|
3596
|
+
const transaction = this.getOptionValue(options, 'transaction', true);
|
|
3597
|
+
const database = this.getDatabaseConnectionOrThrowError(dbName);
|
|
3726
3598
|
try {
|
|
3727
|
-
const
|
|
3728
|
-
return
|
|
3599
|
+
const runResult = await database.runSQL(statement, values, transaction);
|
|
3600
|
+
return { changes: runResult };
|
|
3729
3601
|
}
|
|
3730
3602
|
catch (err) {
|
|
3731
|
-
|
|
3603
|
+
throw new Error(`RUN failed: ${err} `);
|
|
3732
3604
|
}
|
|
3733
3605
|
}
|
|
3734
3606
|
async query(options) {
|
|
3735
|
-
|
|
3736
|
-
|
|
3737
|
-
|
|
3738
|
-
|
|
3739
|
-
|
|
3740
|
-
return Promise.reject('Must provide a query statement');
|
|
3607
|
+
const dbName = this.getOptionValue(options, 'database');
|
|
3608
|
+
const statement = this.getOptionValue(options, 'statement');
|
|
3609
|
+
const values = this.getOptionValue(options, 'values', []);
|
|
3610
|
+
if (statement.length === 0) {
|
|
3611
|
+
throw new Error('Statement may not be an empty string.');
|
|
3741
3612
|
}
|
|
3742
|
-
|
|
3743
|
-
return Promise.reject('Must provide an Array of any');
|
|
3744
|
-
}
|
|
3745
|
-
const dbName = options.database;
|
|
3746
|
-
const statement = options.statement;
|
|
3747
|
-
const values = options.values.length > 0 ? options.values : [];
|
|
3748
|
-
keys = Object.keys(this._dbDict);
|
|
3749
|
-
if (!keys.includes(dbName)) {
|
|
3750
|
-
return Promise.reject(`Query: No available connection for ${dbName}`);
|
|
3751
|
-
}
|
|
3752
|
-
const mDB = this._dbDict[dbName];
|
|
3753
|
-
let ret = [];
|
|
3613
|
+
const database = this.getDatabaseConnectionOrThrowError(dbName);
|
|
3754
3614
|
try {
|
|
3755
|
-
|
|
3756
|
-
return
|
|
3615
|
+
const queryResult = await database.selectSQL(statement, values);
|
|
3616
|
+
return { values: queryResult };
|
|
3757
3617
|
}
|
|
3758
3618
|
catch (err) {
|
|
3759
|
-
|
|
3619
|
+
throw new Error(`Query failed: ${err}`);
|
|
3760
3620
|
}
|
|
3761
3621
|
}
|
|
3762
3622
|
async isDBExists(options) {
|
|
3763
|
-
|
|
3764
|
-
if
|
|
3765
|
-
|
|
3766
|
-
|
|
3767
|
-
|
|
3768
|
-
keys = Object.keys(this._dbDict);
|
|
3769
|
-
if (!keys.includes(dbName)) {
|
|
3770
|
-
return Promise.reject('IsDBExists command failed: No available ' + 'connection for ' + dbName);
|
|
3771
|
-
}
|
|
3772
|
-
const isExists = this._uFile.isFileExists(dbName + 'SQLite.db');
|
|
3773
|
-
return Promise.resolve({
|
|
3774
|
-
result: isExists,
|
|
3775
|
-
});
|
|
3623
|
+
const dbName = this.getOptionValue(options, 'database');
|
|
3624
|
+
// Throw an error, if db connection is not opened yet:
|
|
3625
|
+
this.getDatabaseConnectionOrThrowError(dbName);
|
|
3626
|
+
const isExists = this.fileUtil.isFileExists(dbName + 'SQLite.db');
|
|
3627
|
+
return { result: isExists };
|
|
3776
3628
|
}
|
|
3777
3629
|
async isDBOpen(options) {
|
|
3778
|
-
|
|
3779
|
-
|
|
3780
|
-
|
|
3781
|
-
}
|
|
3782
|
-
const dbName = options.database;
|
|
3783
|
-
keys = Object.keys(this._dbDict);
|
|
3784
|
-
if (!keys.includes(dbName)) {
|
|
3785
|
-
return Promise.reject('isDBOpen command failed: No available ' + 'connection for ' + dbName);
|
|
3786
|
-
}
|
|
3787
|
-
const mDB = this._dbDict[dbName];
|
|
3788
|
-
const isOpen = await mDB.isDBOpen();
|
|
3789
|
-
return Promise.resolve({ result: isOpen });
|
|
3630
|
+
const dbName = this.getOptionValue(options, 'database');
|
|
3631
|
+
const database = this.getDatabaseConnectionOrThrowError(dbName);
|
|
3632
|
+
const isOpen = await database.isDBOpen();
|
|
3633
|
+
return { result: isOpen };
|
|
3790
3634
|
}
|
|
3791
3635
|
async isDatabase(options) {
|
|
3792
|
-
const
|
|
3793
|
-
|
|
3794
|
-
|
|
3795
|
-
}
|
|
3796
|
-
const dbName = options.database;
|
|
3797
|
-
const isExists = this._uFile.isFileExists(dbName + 'SQLite.db');
|
|
3798
|
-
return Promise.resolve({
|
|
3799
|
-
result: isExists,
|
|
3800
|
-
});
|
|
3636
|
+
const dbName = this.getOptionValue(options, 'database');
|
|
3637
|
+
const isExists = this.fileUtil.isFileExists(dbName + 'SQLite.db');
|
|
3638
|
+
return { result: isExists };
|
|
3801
3639
|
}
|
|
3802
3640
|
async isTableExists(options) {
|
|
3803
|
-
|
|
3804
|
-
|
|
3805
|
-
|
|
3806
|
-
}
|
|
3807
|
-
const dbName = options.database;
|
|
3808
|
-
if (!keys.includes('table')) {
|
|
3809
|
-
return Promise.reject('Must provide a table name');
|
|
3810
|
-
}
|
|
3811
|
-
const tableName = options.table;
|
|
3812
|
-
keys = Object.keys(this._dbDict);
|
|
3813
|
-
if (!keys.includes(dbName)) {
|
|
3814
|
-
return Promise.reject('isTableExists command failed: No available ' +
|
|
3815
|
-
'connection for ' +
|
|
3816
|
-
dbName);
|
|
3817
|
-
}
|
|
3818
|
-
const mDB = this._dbDict[dbName];
|
|
3641
|
+
const dbName = this.getOptionValue(options, 'database');
|
|
3642
|
+
const tableName = this.getOptionValue(options, 'table');
|
|
3643
|
+
const database = this.getDatabaseConnectionOrThrowError(dbName);
|
|
3819
3644
|
try {
|
|
3820
|
-
const
|
|
3821
|
-
return
|
|
3645
|
+
const isTableExistsResult = await database.isTableExists(tableName);
|
|
3646
|
+
return { result: isTableExistsResult };
|
|
3822
3647
|
}
|
|
3823
3648
|
catch (err) {
|
|
3824
|
-
|
|
3649
|
+
throw new Error(`isTableExists: ${err}`);
|
|
3825
3650
|
}
|
|
3826
3651
|
}
|
|
3827
3652
|
async deleteDatabase(options) {
|
|
3828
|
-
|
|
3829
|
-
|
|
3830
|
-
return Promise.reject('Must provide a database name');
|
|
3831
|
-
}
|
|
3832
|
-
const dbName = options.database;
|
|
3833
|
-
keys = Object.keys(this._dbDict);
|
|
3834
|
-
if (!keys.includes(dbName)) {
|
|
3835
|
-
return Promise.reject('deleteDatabase: No available connection for ' + `${dbName}`);
|
|
3836
|
-
}
|
|
3837
|
-
const mDB = this._dbDict[dbName];
|
|
3653
|
+
const dbName = this.getOptionValue(options, 'database');
|
|
3654
|
+
const database = this.getDatabaseConnectionOrThrowError(dbName);
|
|
3838
3655
|
try {
|
|
3839
|
-
await
|
|
3840
|
-
return
|
|
3656
|
+
await database.deleteDB(dbName + 'SQLite.db');
|
|
3657
|
+
return;
|
|
3841
3658
|
}
|
|
3842
3659
|
catch (err) {
|
|
3843
|
-
|
|
3660
|
+
throw new Error(`Delete: ${err}`);
|
|
3844
3661
|
}
|
|
3845
3662
|
}
|
|
3846
3663
|
async isJsonValid(options) {
|
|
3847
|
-
const
|
|
3848
|
-
|
|
3849
|
-
|
|
3850
|
-
}
|
|
3851
|
-
const jsonStrObj = options.jsonstring;
|
|
3852
|
-
const jsonObj = JSON.parse(jsonStrObj);
|
|
3853
|
-
const isValid = this._uJson.isJsonSQLite(jsonObj);
|
|
3664
|
+
const jsonString = this.getOptionValue(options, 'jsonstring');
|
|
3665
|
+
const jsonObj = JSON.parse(jsonString);
|
|
3666
|
+
const isValid = this.jsonUtil.isJsonSQLite(jsonObj);
|
|
3854
3667
|
if (!isValid) {
|
|
3855
|
-
|
|
3668
|
+
throw new Error('Stringify Json Object not Valid');
|
|
3856
3669
|
}
|
|
3857
3670
|
else {
|
|
3858
|
-
return
|
|
3671
|
+
return { result: true };
|
|
3859
3672
|
}
|
|
3860
3673
|
}
|
|
3861
3674
|
async importFromJson(options) {
|
|
3862
3675
|
var _a, _b;
|
|
3863
|
-
const
|
|
3864
|
-
|
|
3865
|
-
|
|
3866
|
-
}
|
|
3867
|
-
const jsonStrObj = options.jsonstring;
|
|
3868
|
-
const jsonObj = JSON.parse(jsonStrObj);
|
|
3869
|
-
const isValid = this._uJson.isJsonSQLite(jsonObj);
|
|
3676
|
+
const jsonString = this.getOptionValue(options, 'jsonstring');
|
|
3677
|
+
const jsonObj = JSON.parse(jsonString);
|
|
3678
|
+
const isValid = this.jsonUtil.isJsonSQLite(jsonObj);
|
|
3870
3679
|
if (!isValid) {
|
|
3871
|
-
|
|
3680
|
+
throw new Error('Must provide a valid JsonSQLite Object');
|
|
3872
3681
|
}
|
|
3873
3682
|
const vJsonObj = jsonObj;
|
|
3874
3683
|
const dbName = `${vJsonObj.database}SQLite.db`;
|
|
3875
|
-
const
|
|
3684
|
+
const targetDbVersion = (_a = vJsonObj.version) !== null && _a !== void 0 ? _a : 1;
|
|
3876
3685
|
const mode = vJsonObj.mode;
|
|
3877
3686
|
const overwrite = (_b = vJsonObj.overwrite) !== null && _b !== void 0 ? _b : false;
|
|
3878
3687
|
// const encrypted: boolean = vJsonObj.encrypted ?? false;
|
|
3879
3688
|
// const mode: string = encrypted ? 'secret' : 'no-encryption';
|
|
3880
3689
|
// Create the database
|
|
3881
|
-
const
|
|
3882
|
-
/*encrypted, mode, */
|
|
3690
|
+
const database = new Database_1.Database(dbName,
|
|
3691
|
+
/*encrypted, mode, */
|
|
3692
|
+
targetDbVersion, {});
|
|
3883
3693
|
try {
|
|
3884
3694
|
if (overwrite && mode === 'full') {
|
|
3885
|
-
const isExists = this.
|
|
3695
|
+
const isExists = this.fileUtil.isFileExists(dbName);
|
|
3886
3696
|
if (isExists) {
|
|
3887
|
-
await this.
|
|
3697
|
+
await this.fileUtil.deleteFileName(dbName);
|
|
3888
3698
|
}
|
|
3889
3699
|
}
|
|
3890
3700
|
// Open the database
|
|
3891
|
-
await
|
|
3892
|
-
const tableList = await
|
|
3701
|
+
await database.open();
|
|
3702
|
+
const tableList = await database.getTableList();
|
|
3893
3703
|
if (mode === 'full' && tableList.length > 0) {
|
|
3894
|
-
const
|
|
3895
|
-
if (
|
|
3896
|
-
|
|
3704
|
+
const currentVersion = await database.getVersion();
|
|
3705
|
+
if (targetDbVersion < currentVersion) {
|
|
3706
|
+
throw new Error(`ImportFromJson: Cannot import a version lower than ${currentVersion}`);
|
|
3897
3707
|
}
|
|
3898
|
-
if (
|
|
3899
|
-
return
|
|
3708
|
+
if (currentVersion === targetDbVersion) {
|
|
3709
|
+
return { changes: { changes: 0 } };
|
|
3900
3710
|
}
|
|
3901
3711
|
}
|
|
3902
3712
|
// Import the JsonSQLite Object
|
|
3903
|
-
const changes = await
|
|
3713
|
+
const changes = await database.importJson(vJsonObj);
|
|
3904
3714
|
// Close the database
|
|
3905
|
-
await
|
|
3906
|
-
return
|
|
3715
|
+
await database.close();
|
|
3716
|
+
return { changes: { changes: changes } };
|
|
3907
3717
|
}
|
|
3908
3718
|
catch (err) {
|
|
3909
|
-
|
|
3719
|
+
throw new Error(`ImportFromJson: ${err}`);
|
|
3910
3720
|
}
|
|
3911
3721
|
}
|
|
3912
3722
|
async exportToJson(options) {
|
|
3913
|
-
|
|
3914
|
-
|
|
3915
|
-
|
|
3916
|
-
}
|
|
3917
|
-
if (!keys.includes('jsonexportmode')) {
|
|
3918
|
-
return Promise.reject('Must provide a json export mode');
|
|
3919
|
-
}
|
|
3920
|
-
const dbName = options.database;
|
|
3921
|
-
const exportMode = options.jsonexportmode;
|
|
3922
|
-
keys = Object.keys(this._dbDict);
|
|
3923
|
-
if (!keys.includes(dbName)) {
|
|
3924
|
-
return Promise.reject('exportToJson: No available connection for ' + `${dbName}`);
|
|
3925
|
-
}
|
|
3926
|
-
const mDB = this._dbDict[dbName];
|
|
3723
|
+
const dbName = this.getOptionValue(options, 'database');
|
|
3724
|
+
const exportMode = this.getOptionValue(options, 'jsonexportmode');
|
|
3725
|
+
const database = this.getDatabaseConnectionOrThrowError(dbName);
|
|
3927
3726
|
try {
|
|
3928
|
-
const
|
|
3929
|
-
const
|
|
3930
|
-
if (
|
|
3931
|
-
|
|
3727
|
+
const exportJsonResult = await database.exportJson(exportMode);
|
|
3728
|
+
const resultKeys = Object.keys(exportJsonResult);
|
|
3729
|
+
if (resultKeys.includes('message')) {
|
|
3730
|
+
throw new Error(`exportToJson: ${exportJsonResult.message}`);
|
|
3932
3731
|
}
|
|
3933
3732
|
else {
|
|
3934
|
-
return
|
|
3733
|
+
return { export: exportJsonResult };
|
|
3935
3734
|
}
|
|
3936
3735
|
}
|
|
3937
3736
|
catch (err) {
|
|
3938
|
-
|
|
3737
|
+
throw new Error(`exportToJson: ${err}`);
|
|
3939
3738
|
}
|
|
3940
3739
|
}
|
|
3941
3740
|
async createSyncTable(options) {
|
|
3942
|
-
|
|
3943
|
-
|
|
3944
|
-
return Promise.reject('Must provide a database name');
|
|
3945
|
-
}
|
|
3946
|
-
const dbName = options.database;
|
|
3947
|
-
keys = Object.keys(this._dbDict);
|
|
3948
|
-
if (!keys.includes(dbName)) {
|
|
3949
|
-
return Promise.reject('CreateSyncTable: No available connection for ' + `${dbName}`);
|
|
3950
|
-
}
|
|
3951
|
-
const mDB = this._dbDict[dbName];
|
|
3741
|
+
const dbName = this.getOptionValue(options, 'database');
|
|
3742
|
+
const database = this.getDatabaseConnectionOrThrowError(dbName);
|
|
3952
3743
|
try {
|
|
3953
|
-
const
|
|
3954
|
-
return
|
|
3744
|
+
const createTableSyncResult = await database.createSyncTable();
|
|
3745
|
+
return {
|
|
3746
|
+
changes: { changes: createTableSyncResult },
|
|
3747
|
+
};
|
|
3955
3748
|
}
|
|
3956
3749
|
catch (err) {
|
|
3957
|
-
|
|
3750
|
+
throw new Error(`createSyncTable: ${err}`);
|
|
3958
3751
|
}
|
|
3959
3752
|
}
|
|
3960
3753
|
async setSyncDate(options) {
|
|
3961
|
-
|
|
3962
|
-
|
|
3963
|
-
|
|
3964
|
-
}
|
|
3965
|
-
if (!keys.includes('syncdate')) {
|
|
3966
|
-
return Promise.reject('Must provide a synchronization date');
|
|
3967
|
-
}
|
|
3968
|
-
const dbName = options.database;
|
|
3969
|
-
const syncDate = options.syncdate;
|
|
3970
|
-
keys = Object.keys(this._dbDict);
|
|
3971
|
-
if (!keys.includes(dbName)) {
|
|
3972
|
-
return Promise.reject(`SetSyncDate: No available connection for ${dbName}`);
|
|
3973
|
-
}
|
|
3974
|
-
const mDB = this._dbDict[dbName];
|
|
3754
|
+
const dbName = this.getOptionValue(options, 'database');
|
|
3755
|
+
const syncDate = this.getOptionValue(options, 'syncdate');
|
|
3756
|
+
const database = this.getDatabaseConnectionOrThrowError(dbName);
|
|
3975
3757
|
try {
|
|
3976
|
-
await
|
|
3977
|
-
return
|
|
3758
|
+
await database.setSyncDate(syncDate);
|
|
3759
|
+
return;
|
|
3978
3760
|
}
|
|
3979
3761
|
catch (err) {
|
|
3980
|
-
|
|
3762
|
+
throw new Error(`SetSyncDate: ${err}`);
|
|
3981
3763
|
}
|
|
3982
3764
|
}
|
|
3983
3765
|
async getSyncDate(options) {
|
|
3984
|
-
|
|
3985
|
-
|
|
3986
|
-
return Promise.reject('Must provide a database name');
|
|
3987
|
-
}
|
|
3988
|
-
const dbName = options.database;
|
|
3989
|
-
keys = Object.keys(this._dbDict);
|
|
3990
|
-
if (!keys.includes(dbName)) {
|
|
3991
|
-
return Promise.reject(`GetSyncDate: No available connection for ${dbName}`);
|
|
3992
|
-
}
|
|
3993
|
-
const mDB = this._dbDict[dbName];
|
|
3766
|
+
const dbName = this.getOptionValue(options, 'database');
|
|
3767
|
+
const database = this.getDatabaseConnectionOrThrowError(dbName);
|
|
3994
3768
|
try {
|
|
3995
|
-
const ret = await
|
|
3769
|
+
const ret = await database.getSyncDate();
|
|
3996
3770
|
return Promise.resolve(ret);
|
|
3997
3771
|
}
|
|
3998
3772
|
catch (err) {
|
|
3999
|
-
|
|
3773
|
+
throw new Error(`GetSyncDate: ${err}`);
|
|
4000
3774
|
}
|
|
4001
3775
|
}
|
|
4002
3776
|
async addUpgradeStatement(options) {
|
|
4003
|
-
|
|
4004
|
-
|
|
4005
|
-
|
|
4006
|
-
|
|
4007
|
-
if (!
|
|
4008
|
-
|
|
4009
|
-
|
|
4010
|
-
|
|
4011
|
-
|
|
4012
|
-
|
|
4013
|
-
|
|
4014
|
-
|
|
4015
|
-
|
|
4016
|
-
|
|
4017
|
-
|
|
4018
|
-
|
|
4019
|
-
return Promise.reject('ugrade.fromVersion must be a number');
|
|
4020
|
-
}
|
|
4021
|
-
const upgVDict = {};
|
|
4022
|
-
upgVDict[upgrade.fromVersion] = upgrade;
|
|
4023
|
-
this._versionUpgrades[dbName] = upgVDict;
|
|
4024
|
-
return Promise.resolve();
|
|
3777
|
+
const dbName = this.getOptionValue(options, 'database');
|
|
3778
|
+
const upgrades = this.getOptionValue(options, 'upgrade');
|
|
3779
|
+
const firstUpgrade = upgrades[0];
|
|
3780
|
+
const versionUpgradeKeys = Object.keys(firstUpgrade);
|
|
3781
|
+
if (!versionUpgradeKeys.includes('fromVersion') ||
|
|
3782
|
+
!versionUpgradeKeys.includes('toVersion') ||
|
|
3783
|
+
!versionUpgradeKeys.includes('statement')) {
|
|
3784
|
+
throw new Error('Must provide an upgrade capSQLiteVersionUpgrade Object');
|
|
3785
|
+
}
|
|
3786
|
+
if (typeof firstUpgrade.fromVersion != 'number') {
|
|
3787
|
+
throw new Error('upgrade.fromVersion must be a number');
|
|
3788
|
+
}
|
|
3789
|
+
const upgradeVersionDict = {};
|
|
3790
|
+
upgradeVersionDict[firstUpgrade.fromVersion] = firstUpgrade;
|
|
3791
|
+
this.versionUpgrades[dbName] = upgradeVersionDict;
|
|
3792
|
+
return;
|
|
4025
3793
|
}
|
|
4026
3794
|
async copyFromAssets(options) {
|
|
4027
|
-
const
|
|
4028
|
-
const mOverwrite = keys.includes('overwrite') ? options.overwrite : true;
|
|
3795
|
+
const overwrite = this.getOptionValue(options, 'overwrite', false);
|
|
4029
3796
|
// check if the assets/database folder exists
|
|
4030
|
-
const assetsDbPath = this.
|
|
4031
|
-
const
|
|
4032
|
-
if (
|
|
3797
|
+
const assetsDbPath = this.fileUtil.getAssetsDatabasesPath();
|
|
3798
|
+
const pathExists = this.fileUtil.isPathExists(assetsDbPath);
|
|
3799
|
+
if (pathExists) {
|
|
4033
3800
|
// get the database files
|
|
4034
|
-
const dbList = await this.
|
|
3801
|
+
const dbList = await this.fileUtil.getFileList(assetsDbPath);
|
|
4035
3802
|
// loop through the database files
|
|
4036
3803
|
dbList.forEach(async (db) => {
|
|
4037
3804
|
if (db.substring(db.length - 3) === '.db') {
|
|
4038
3805
|
// for each copy the file to the Application database folder
|
|
4039
|
-
await this.
|
|
3806
|
+
await this.fileUtil.copyFromAssetToDatabase(db, overwrite);
|
|
4040
3807
|
}
|
|
4041
3808
|
if (db.substring(db.length - 4) === '.zip') {
|
|
4042
|
-
await this.
|
|
3809
|
+
await this.fileUtil.unzipDatabase(db, overwrite);
|
|
4043
3810
|
}
|
|
4044
3811
|
});
|
|
4045
|
-
return
|
|
3812
|
+
return;
|
|
4046
3813
|
}
|
|
4047
3814
|
else {
|
|
4048
|
-
|
|
3815
|
+
throw new Error('CopyFromAssets: assets/databases folder does not exist');
|
|
4049
3816
|
}
|
|
4050
3817
|
}
|
|
4051
3818
|
async getDatabaseList() {
|
|
4052
3819
|
// get the database folder
|
|
4053
|
-
const pathDatabase = this.
|
|
3820
|
+
const pathDatabase = this.fileUtil.getDatabasesPath();
|
|
4054
3821
|
// get the list of databases
|
|
4055
|
-
const files = await this.
|
|
3822
|
+
const files = await this.fileUtil.getFileList(pathDatabase);
|
|
4056
3823
|
if (files.length > 0) {
|
|
4057
|
-
return
|
|
3824
|
+
return { values: files };
|
|
4058
3825
|
}
|
|
4059
3826
|
else {
|
|
4060
|
-
|
|
3827
|
+
throw new Error(`isTableExists: No databases found`);
|
|
4061
3828
|
}
|
|
4062
3829
|
}
|
|
4063
|
-
async getMigratableDbList(options) {
|
|
4064
|
-
console.log('getCordovaDbList', options);
|
|
4065
|
-
return Promise.reject('Method not implemented.');
|
|
4066
|
-
}
|
|
4067
|
-
async addSQLiteSuffix(options) {
|
|
4068
|
-
console.log(`${JSON.stringify(options)}`);
|
|
4069
|
-
throw new Error('Method not implemented.');
|
|
4070
|
-
}
|
|
4071
|
-
async deleteOldDatabases(options) {
|
|
4072
|
-
console.log(`${JSON.stringify(options)}`);
|
|
4073
|
-
throw new Error('Method not implemented.');
|
|
4074
|
-
}
|
|
4075
3830
|
async checkConnectionsConsistency(options) {
|
|
4076
|
-
const
|
|
4077
|
-
|
|
4078
|
-
|
|
4079
|
-
}
|
|
4080
|
-
const dbNames = options.dbNames;
|
|
4081
|
-
const ret = {};
|
|
4082
|
-
ret.result = false;
|
|
3831
|
+
const dbNames = this.getOptionValue(options, 'dbNames');
|
|
3832
|
+
const checkConsistencyResult = {};
|
|
3833
|
+
checkConsistencyResult.result = false;
|
|
4083
3834
|
try {
|
|
4084
|
-
let inConnectionsSet = new Set(Object.keys(this.
|
|
3835
|
+
let inConnectionsSet = new Set(Object.keys(this.databases));
|
|
4085
3836
|
const outConnectionSet = new Set(dbNames);
|
|
4086
3837
|
if (outConnectionSet.size === 0) {
|
|
4087
|
-
await this.resetDbDict(Object.keys(this.
|
|
4088
|
-
return Promise.resolve(
|
|
3838
|
+
await this.resetDbDict(Object.keys(this.databases));
|
|
3839
|
+
return Promise.resolve(checkConsistencyResult);
|
|
4089
3840
|
}
|
|
4090
3841
|
if (inConnectionsSet.size < outConnectionSet.size) {
|
|
4091
|
-
await this.resetDbDict(Object.keys(this.
|
|
4092
|
-
return Promise.resolve(
|
|
3842
|
+
await this.resetDbDict(Object.keys(this.databases));
|
|
3843
|
+
return Promise.resolve(checkConsistencyResult);
|
|
4093
3844
|
}
|
|
4094
3845
|
if (inConnectionsSet.size > outConnectionSet.size) {
|
|
4095
3846
|
for (const key of inConnectionsSet) {
|
|
@@ -4100,25 +3851,25 @@ class CapacitorSQLite {
|
|
|
4100
3851
|
}
|
|
4101
3852
|
}
|
|
4102
3853
|
}
|
|
4103
|
-
inConnectionsSet = new Set(Object.keys(this.
|
|
3854
|
+
inConnectionsSet = new Set(Object.keys(this.databases));
|
|
4104
3855
|
if (inConnectionsSet.size === outConnectionSet.size) {
|
|
4105
|
-
const
|
|
4106
|
-
if (
|
|
4107
|
-
|
|
4108
|
-
return
|
|
3856
|
+
const symmetricDifferenceSet = await this.symmetricDifference(inConnectionsSet, outConnectionSet);
|
|
3857
|
+
if (symmetricDifferenceSet.size === 0) {
|
|
3858
|
+
checkConsistencyResult.result = true;
|
|
3859
|
+
return checkConsistencyResult;
|
|
4109
3860
|
}
|
|
4110
3861
|
else {
|
|
4111
|
-
await this.resetDbDict(Object.keys(this.
|
|
4112
|
-
return
|
|
3862
|
+
await this.resetDbDict(Object.keys(this.databases));
|
|
3863
|
+
return checkConsistencyResult;
|
|
4113
3864
|
}
|
|
4114
3865
|
}
|
|
4115
3866
|
else {
|
|
4116
|
-
await this.resetDbDict(Object.keys(this.
|
|
4117
|
-
return
|
|
3867
|
+
await this.resetDbDict(Object.keys(this.databases));
|
|
3868
|
+
return checkConsistencyResult;
|
|
4118
3869
|
}
|
|
4119
3870
|
}
|
|
4120
3871
|
catch (err) {
|
|
4121
|
-
|
|
3872
|
+
throw new Error(`CheckConnectionsConsistency: ${err}`);
|
|
4122
3873
|
}
|
|
4123
3874
|
}
|
|
4124
3875
|
async resetDbDict(keys) {
|
|
@@ -4130,7 +3881,7 @@ class CapacitorSQLite {
|
|
|
4130
3881
|
}
|
|
4131
3882
|
}
|
|
4132
3883
|
catch (err) {
|
|
4133
|
-
|
|
3884
|
+
throw new Error(`ResetDbDict: ${err}`);
|
|
4134
3885
|
}
|
|
4135
3886
|
}
|
|
4136
3887
|
async symmetricDifference(setA, setB) {
|
|
@@ -4143,7 +3894,101 @@ class CapacitorSQLite {
|
|
|
4143
3894
|
difference.add(elem);
|
|
4144
3895
|
}
|
|
4145
3896
|
}
|
|
4146
|
-
return
|
|
3897
|
+
return difference;
|
|
3898
|
+
}
|
|
3899
|
+
/**
|
|
3900
|
+
* Returns a database connection, if it already exists.
|
|
3901
|
+
* If the conneciton does not exist yet, it throws an error.
|
|
3902
|
+
*
|
|
3903
|
+
* @param dbName
|
|
3904
|
+
* @returns
|
|
3905
|
+
*/
|
|
3906
|
+
getDatabaseConnectionOrThrowError(dbName) {
|
|
3907
|
+
const databaseNames = Object.keys(this.databases);
|
|
3908
|
+
if (!databaseNames.includes(dbName)) {
|
|
3909
|
+
throw new Error(`No connection available for database "${dbName}"`);
|
|
3910
|
+
}
|
|
3911
|
+
return this.databases[dbName];
|
|
3912
|
+
}
|
|
3913
|
+
/**
|
|
3914
|
+
* Gets the value of an option from the options object.
|
|
3915
|
+
* If the `optionKey` does not exist and there is no `defaultValue` defined, an exception is thrown.
|
|
3916
|
+
* If the `optionKey` does not exist but there is a `defaultValue`, the `defaultValue` is returned.
|
|
3917
|
+
*
|
|
3918
|
+
* @param options
|
|
3919
|
+
* @param optionKey
|
|
3920
|
+
* @param defaultValue
|
|
3921
|
+
* @returns
|
|
3922
|
+
*/
|
|
3923
|
+
getOptionValue(options, optionKey, defaultValue = undefined) {
|
|
3924
|
+
const optionKeys = Object.keys(options);
|
|
3925
|
+
if (!optionKeys.includes(optionKey)) {
|
|
3926
|
+
if (defaultValue === undefined) {
|
|
3927
|
+
throw new Error(`Must provide "${optionKey}" in options.`);
|
|
3928
|
+
}
|
|
3929
|
+
else {
|
|
3930
|
+
return defaultValue;
|
|
3931
|
+
}
|
|
3932
|
+
}
|
|
3933
|
+
return options[optionKey];
|
|
3934
|
+
}
|
|
3935
|
+
////////////////////////////////
|
|
3936
|
+
//// UNIMPLEMENTED MTEHODS
|
|
3937
|
+
////////////////////////////////
|
|
3938
|
+
async getMigratableDbList(options) {
|
|
3939
|
+
console.log('getCordovaDbList', options);
|
|
3940
|
+
throw new Error('Method not implemented.');
|
|
3941
|
+
}
|
|
3942
|
+
async addSQLiteSuffix(options) {
|
|
3943
|
+
console.log(`${JSON.stringify(options)}`);
|
|
3944
|
+
throw new Error('Method not implemented.');
|
|
3945
|
+
}
|
|
3946
|
+
async deleteOldDatabases(options) {
|
|
3947
|
+
console.log(`${JSON.stringify(options)}`);
|
|
3948
|
+
throw new Error('Method not implemented.');
|
|
3949
|
+
}
|
|
3950
|
+
async getUrl() {
|
|
3951
|
+
throw new Error('Method not implemented.');
|
|
3952
|
+
}
|
|
3953
|
+
async initWebStore() {
|
|
3954
|
+
throw new Error('Method not implemented.');
|
|
3955
|
+
}
|
|
3956
|
+
async saveToStore(options) {
|
|
3957
|
+
console.log(`${JSON.stringify(options)}`);
|
|
3958
|
+
throw new Error('Method not implemented.');
|
|
3959
|
+
}
|
|
3960
|
+
async isSecretStored() {
|
|
3961
|
+
throw new Error('Method not implemented.');
|
|
3962
|
+
}
|
|
3963
|
+
async setEncryptionSecret(options) {
|
|
3964
|
+
console.log(`${JSON.stringify(options)}`);
|
|
3965
|
+
throw new Error('Method not implemented.');
|
|
3966
|
+
}
|
|
3967
|
+
async changeEncryptionSecret(options) {
|
|
3968
|
+
console.log(`${JSON.stringify(options)}`);
|
|
3969
|
+
throw new Error('Method not implemented.');
|
|
3970
|
+
}
|
|
3971
|
+
async getNCDatabasePath(options) {
|
|
3972
|
+
console.log('getNCDatabasePath', options);
|
|
3973
|
+
throw new Error('Method not implemented.');
|
|
3974
|
+
}
|
|
3975
|
+
async createNCConnection(options) {
|
|
3976
|
+
console.log('createNCConnection', options);
|
|
3977
|
+
throw new Error('Method not implemented.');
|
|
3978
|
+
}
|
|
3979
|
+
async closeNCConnection(options) {
|
|
3980
|
+
console.log('closeNCConnection', options);
|
|
3981
|
+
throw new Error('Method not implemented.');
|
|
3982
|
+
}
|
|
3983
|
+
async isNCDatabase(options) {
|
|
3984
|
+
console.log('isNCDatabase', options);
|
|
3985
|
+
throw new Error('Method not implemented.');
|
|
3986
|
+
}
|
|
3987
|
+
async deleteExportedRows(options) {
|
|
3988
|
+
const dbName = this.getOptionValue(options, 'database');
|
|
3989
|
+
// const database = this.getDatabaseConnectionOrThrowError(dbName);
|
|
3990
|
+
console.log('deleteExportedRows', dbName);
|
|
3991
|
+
throw new Error('Method not implemented.');
|
|
4147
3992
|
}
|
|
4148
3993
|
}
|
|
4149
3994
|
exports.CapacitorSQLite = src.CapacitorSQLite = CapacitorSQLite;
|