@capacitor-community/sqlite 6.0.1 → 6.0.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 +71 -91
- package/android/build.gradle +1 -1
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/CapacitorSQLitePlugin.java +12 -16
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/Database.java +2 -1
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/ImportExportJson/ImportFromJson.java +73 -69
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/UtilsDownloadFromHTTP.java +13 -12
- package/dist/esm/definitions.js +1 -3
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +2 -4
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +2 -4
- package/dist/plugin.js.map +1 -1
- package/electron/dist/plugin.js +56 -144
- package/electron/dist/plugin.js.map +1 -1
- package/electron/rollup.config.js +1 -3
- package/ios/Plugin/CapacitorSQLite.swift +5 -5
- package/ios/Plugin/Database.swift +1 -1
- package/ios/Plugin/ImportExportJson/ExportToJson.swift +7 -7
- package/ios/Plugin/Models/KeychainServices.swift +1 -1
- package/ios/Plugin/Utils/UtilsBinding.swift +2 -2
- package/ios/Plugin/Utils/UtilsDelete.swift +4 -4
- package/ios/Plugin/Utils/UtilsDownloadFromHTTP.swift +2 -2
- package/ios/Plugin/Utils/UtilsDrop.swift +1 -1
- package/ios/Plugin/Utils/UtilsSQLCipher.swift +17 -17
- package/ios/Plugin/Utils/UtilsSQLStatement.swift +120 -121
- package/package.json +23 -21
- package/src/definitions.ts +44 -128
- package/src/index.ts +4 -8
- package/src/web.ts +60 -132
package/electron/dist/plugin.js
CHANGED
|
@@ -148,8 +148,8 @@ class UtilsSQL92Compatibility {
|
|
|
148
148
|
const newTokens = [];
|
|
149
149
|
const tokens = whereStatement
|
|
150
150
|
.split(/(\s|,|\(|\))/)
|
|
151
|
-
.filter(item => item !== ' ')
|
|
152
|
-
.filter(item => item !== '');
|
|
151
|
+
.filter((item) => item !== ' ')
|
|
152
|
+
.filter((item) => item !== '');
|
|
153
153
|
let inClause = false;
|
|
154
154
|
let inValues = false;
|
|
155
155
|
let modValue = false;
|
|
@@ -179,9 +179,7 @@ class UtilsSQL92Compatibility {
|
|
|
179
179
|
opsClause = false;
|
|
180
180
|
modValue = true;
|
|
181
181
|
}
|
|
182
|
-
else if (token.toUpperCase() === 'AND' ||
|
|
183
|
-
token.toUpperCase() === 'OR' ||
|
|
184
|
-
token.toUpperCase() === 'NOT') {
|
|
182
|
+
else if (token.toUpperCase() === 'AND' || token.toUpperCase() === 'OR' || token.toUpperCase() === 'NOT') {
|
|
185
183
|
newTokens.push(token);
|
|
186
184
|
opsClause = true;
|
|
187
185
|
}
|
|
@@ -407,8 +405,7 @@ class UtilsFile {
|
|
|
407
405
|
else {
|
|
408
406
|
this.capConfig = JSON.parse(this.NodeFs.readFileSync(this.Path.join(this.appPath, 'capacitor.config.json')).toString());
|
|
409
407
|
}
|
|
410
|
-
this.isEncryption = this.capConfig.plugins.CapacitorSQLite
|
|
411
|
-
.electronIsEncryption
|
|
408
|
+
this.isEncryption = this.capConfig.plugins.CapacitorSQLite.electronIsEncryption
|
|
412
409
|
? this.capConfig.plugins.CapacitorSQLite.electronIsEncryption
|
|
413
410
|
: false;
|
|
414
411
|
this.osType = this.Os.type();
|
|
@@ -419,14 +416,12 @@ class UtilsFile {
|
|
|
419
416
|
: 'Databases';
|
|
420
417
|
break;
|
|
421
418
|
case 'Linux':
|
|
422
|
-
this.pathDB = this.capConfig.plugins.CapacitorSQLite
|
|
423
|
-
.electronLinuxLocation
|
|
419
|
+
this.pathDB = this.capConfig.plugins.CapacitorSQLite.electronLinuxLocation
|
|
424
420
|
? this.capConfig.plugins.CapacitorSQLite.electronLinuxLocation
|
|
425
421
|
: 'Databases';
|
|
426
422
|
break;
|
|
427
423
|
case 'Windows_NT':
|
|
428
|
-
this.pathDB = this.capConfig.plugins.CapacitorSQLite
|
|
429
|
-
.electronWindowsLocation
|
|
424
|
+
this.pathDB = this.capConfig.plugins.CapacitorSQLite.electronWindowsLocation
|
|
430
425
|
? this.capConfig.plugins.CapacitorSQLite.electronWindowsLocation
|
|
431
426
|
: 'Databases';
|
|
432
427
|
break;
|
|
@@ -600,7 +595,7 @@ class UtilsFile {
|
|
|
600
595
|
const contents = await zip.loadAsync(data);
|
|
601
596
|
// Create an array to store promises for writing files
|
|
602
597
|
const writePromises = [];
|
|
603
|
-
Object.keys(contents.files).forEach(filename => {
|
|
598
|
+
Object.keys(contents.files).forEach((filename) => {
|
|
604
599
|
writePromises.push(zip
|
|
605
600
|
.file(filename)
|
|
606
601
|
.async('nodebuffer')
|
|
@@ -724,7 +719,7 @@ class UtilsFile {
|
|
|
724
719
|
*/
|
|
725
720
|
const deleteFile = async () => {
|
|
726
721
|
try {
|
|
727
|
-
await promises_1.unlink(filePath);
|
|
722
|
+
await (0, promises_1.unlink)(filePath);
|
|
728
723
|
}
|
|
729
724
|
catch (err) {
|
|
730
725
|
unlinkRetries--;
|
|
@@ -777,7 +772,7 @@ class UtilsFile {
|
|
|
777
772
|
return;
|
|
778
773
|
}
|
|
779
774
|
try {
|
|
780
|
-
const stream = await promises_1.open(filePath, 'r+');
|
|
775
|
+
const stream = await (0, promises_1.open)(filePath, 'r+');
|
|
781
776
|
// We need to close the stream afterwards, because otherwise, we're locking the file
|
|
782
777
|
await stream.close();
|
|
783
778
|
resolve();
|
|
@@ -972,9 +967,7 @@ class UtilsFile {
|
|
|
972
967
|
const path = directory.replace(/\/$/, '').split(sep);
|
|
973
968
|
for (let i = 1; i <= path.length; i++) {
|
|
974
969
|
const segment = path.slice(0, i).join(sep);
|
|
975
|
-
segment.length > 0 && !this.NodeFs.existsSync(segment)
|
|
976
|
-
? this.NodeFs.mkdirSync(segment)
|
|
977
|
-
: null;
|
|
970
|
+
segment.length > 0 && !this.NodeFs.existsSync(segment) ? this.NodeFs.mkdirSync(segment) : null;
|
|
978
971
|
}
|
|
979
972
|
return;
|
|
980
973
|
}
|
|
@@ -990,9 +983,7 @@ class UtilsSQLStatement {
|
|
|
990
983
|
this.replaceString = (originalStr, searchStr, replaceStr) => {
|
|
991
984
|
const range = originalStr.indexOf(searchStr);
|
|
992
985
|
if (range !== -1) {
|
|
993
|
-
const modifiedStr = originalStr.substring(0, range) +
|
|
994
|
-
replaceStr +
|
|
995
|
-
originalStr.substring(range + searchStr.length);
|
|
986
|
+
const modifiedStr = originalStr.substring(0, range) + replaceStr + originalStr.substring(range + searchStr.length);
|
|
996
987
|
return modifiedStr;
|
|
997
988
|
}
|
|
998
989
|
return originalStr;
|
|
@@ -1021,12 +1012,12 @@ class UtilsSQLStatement {
|
|
|
1021
1012
|
if (whereClause.includes('AND')) {
|
|
1022
1013
|
// Split the WHERE clause based on the "AND" keyword
|
|
1023
1014
|
const subSequenceArray = whereClause.split('AND');
|
|
1024
|
-
columnValuePairs = subSequenceArray.map(pair => pair.trim());
|
|
1015
|
+
columnValuePairs = subSequenceArray.map((pair) => pair.trim());
|
|
1025
1016
|
}
|
|
1026
1017
|
else {
|
|
1027
1018
|
columnValuePairs = [whereClause];
|
|
1028
1019
|
}
|
|
1029
|
-
const modifiedPairs = columnValuePairs.map(pair => {
|
|
1020
|
+
const modifiedPairs = columnValuePairs.map((pair) => {
|
|
1030
1021
|
const match = pair.match(/(\w+)\s*(=|IN|BETWEEN|LIKE)\s*(.+)/);
|
|
1031
1022
|
if (!match) {
|
|
1032
1023
|
return pair;
|
|
@@ -1062,9 +1053,9 @@ class UtilsSQLStatement {
|
|
|
1062
1053
|
const matches = sqlStatement.match(foreignKeyPattern);
|
|
1063
1054
|
if (matches) {
|
|
1064
1055
|
const foreignKeyInfo = {
|
|
1065
|
-
forKeys: matches[1].split(',').map(key => key.trim()),
|
|
1056
|
+
forKeys: matches[1].split(',').map((key) => key.trim()),
|
|
1066
1057
|
tableName: matches[2],
|
|
1067
|
-
refKeys: matches[3].split(',').map(key => key.trim()),
|
|
1058
|
+
refKeys: matches[3].split(',').map((key) => key.trim()),
|
|
1068
1059
|
action: matches[5] ? matches[5] : 'NO ACTION',
|
|
1069
1060
|
};
|
|
1070
1061
|
return foreignKeyInfo;
|
|
@@ -1074,15 +1065,7 @@ class UtilsSQLStatement {
|
|
|
1074
1065
|
}
|
|
1075
1066
|
}
|
|
1076
1067
|
extractColumnNames(whereClause) {
|
|
1077
|
-
const keywords = new Set([
|
|
1078
|
-
'AND',
|
|
1079
|
-
'OR',
|
|
1080
|
-
'IN',
|
|
1081
|
-
'VALUES',
|
|
1082
|
-
'LIKE',
|
|
1083
|
-
'BETWEEN',
|
|
1084
|
-
'NOT',
|
|
1085
|
-
]);
|
|
1068
|
+
const keywords = new Set(['AND', 'OR', 'IN', 'VALUES', 'LIKE', 'BETWEEN', 'NOT']);
|
|
1086
1069
|
const regex = /\b[a-zA-Z]\w*\b(?=\s*(?:<=?|>=?|<>?|=|AND|OR|BETWEEN|NOT|IN|LIKE))|\b[a-zA-Z]\w*\b\s+BETWEEN\s+'[^']+'\s+AND\s+'[^']+'|\(([^)]+)\)\s+IN\s+\(?\s*VALUES\s*\(/g;
|
|
1087
1070
|
let match;
|
|
1088
1071
|
const columns = [];
|
|
@@ -1114,7 +1097,7 @@ class UtilsSQLStatement {
|
|
|
1114
1097
|
const primaryKeySets = [];
|
|
1115
1098
|
for (const match of matches) {
|
|
1116
1099
|
const keysString = match[1].trim();
|
|
1117
|
-
const keys = keysString.split(',').map(key => key.trim());
|
|
1100
|
+
const keys = keysString.split(',').map((key) => key.trim());
|
|
1118
1101
|
primaryKeySets.push(keys);
|
|
1119
1102
|
}
|
|
1120
1103
|
return primaryKeySets.length === 0 ? null : primaryKeySets;
|
|
@@ -1526,7 +1509,7 @@ class UtilsSQLite {
|
|
|
1526
1509
|
}
|
|
1527
1510
|
statementsToSQL92(mDB, sql, fromJson, isSQL92) {
|
|
1528
1511
|
// split the statements in an array of statement
|
|
1529
|
-
let sqlStmt = sql /*.replace(/\n/g, '')
|
|
1512
|
+
let sqlStmt = sql; /*.replace(/\n/g, '')*/
|
|
1530
1513
|
// deal with trigger
|
|
1531
1514
|
sqlStmt = sqlStmt.replace(/end;/g, 'END;');
|
|
1532
1515
|
sqlStmt = sqlStmt.replace(/;END;/g, '&END;');
|
|
@@ -1535,9 +1518,7 @@ class UtilsSQLite {
|
|
|
1535
1518
|
// loop through the statement
|
|
1536
1519
|
for (const stmt of sqlStmts) {
|
|
1537
1520
|
let rStmt = stmt.trim();
|
|
1538
|
-
const stmtType = rStmt
|
|
1539
|
-
.split(" ")[0]
|
|
1540
|
-
.toUpperCase();
|
|
1521
|
+
const stmtType = rStmt.split(' ')[0].toUpperCase();
|
|
1541
1522
|
switch (stmtType) {
|
|
1542
1523
|
case 'CREATE':
|
|
1543
1524
|
if (rStmt.includes('&END')) {
|
|
@@ -1545,8 +1526,7 @@ class UtilsSQLite {
|
|
|
1545
1526
|
}
|
|
1546
1527
|
break;
|
|
1547
1528
|
case 'DELETE':
|
|
1548
|
-
if (!fromJson &&
|
|
1549
|
-
rStmt.toLowerCase().includes('WHERE'.toLowerCase())) {
|
|
1529
|
+
if (!fromJson && rStmt.toLowerCase().includes('WHERE'.toLowerCase())) {
|
|
1550
1530
|
let whereStmt = rStmt;
|
|
1551
1531
|
if (!isSQL92)
|
|
1552
1532
|
whereStmt = this.cleanStatement(rStmt);
|
|
@@ -1566,8 +1546,7 @@ class UtilsSQLite {
|
|
|
1566
1546
|
}
|
|
1567
1547
|
break;
|
|
1568
1548
|
case 'SELECT':
|
|
1569
|
-
if (!fromJson &&
|
|
1570
|
-
rStmt.toLowerCase().includes('WHERE'.toLowerCase())) {
|
|
1549
|
+
if (!fromJson && rStmt.toLowerCase().includes('WHERE'.toLowerCase())) {
|
|
1571
1550
|
if (!isSQL92)
|
|
1572
1551
|
rStmt = this.cleanStatement(rStmt);
|
|
1573
1552
|
}
|
|
@@ -1663,10 +1642,7 @@ class UtilsSQLite {
|
|
|
1663
1642
|
prepareRun(mDB, statement, values, fromJson, returnMode) {
|
|
1664
1643
|
const result = { changes: 0, lastId: -1 };
|
|
1665
1644
|
const msg = 'PrepareRun';
|
|
1666
|
-
const stmtType = statement
|
|
1667
|
-
.trim()
|
|
1668
|
-
.split(" ")[0]
|
|
1669
|
-
.toUpperCase();
|
|
1645
|
+
const stmtType = statement.trim().split(' ')[0].toUpperCase();
|
|
1670
1646
|
let sqlStmt = statement;
|
|
1671
1647
|
try {
|
|
1672
1648
|
if (!fromJson && stmtType === 'DELETE') {
|
|
@@ -1816,9 +1792,7 @@ class UtilsSQLite {
|
|
|
1816
1792
|
// column
|
|
1817
1793
|
const hasToUpdate = this.findReferencesAndUpdate(mDB, tableName, whereClause, colNames, values);
|
|
1818
1794
|
if (hasToUpdate) {
|
|
1819
|
-
const whereStmt = whereClause.endsWith(';')
|
|
1820
|
-
? whereClause.slice(0, -1)
|
|
1821
|
-
: whereClause;
|
|
1795
|
+
const whereStmt = whereClause.endsWith(';') ? whereClause.slice(0, -1) : whereClause;
|
|
1822
1796
|
sqlStmt = `UPDATE ${tableName} SET ${setStmt} WHERE ${whereStmt} AND sql_deleted = 0;`;
|
|
1823
1797
|
}
|
|
1824
1798
|
else {
|
|
@@ -2250,8 +2224,8 @@ class UtilsSQLite {
|
|
|
2250
2224
|
searchForRelatedItems(mDB, updTableName, tableName, whStmt, withRefsNames, colNames, values) {
|
|
2251
2225
|
const relatedItems = [];
|
|
2252
2226
|
let key = '';
|
|
2253
|
-
const t1Names = withRefsNames.map(name => `t1.${name}`);
|
|
2254
|
-
const t2Names = colNames.map(name => `t2.${name}`);
|
|
2227
|
+
const t1Names = withRefsNames.map((name) => `t1.${name}`);
|
|
2228
|
+
const t2Names = colNames.map((name) => `t2.${name}`);
|
|
2255
2229
|
try {
|
|
2256
2230
|
// addPrefix to the whereClause and swap colNames with withRefsNames
|
|
2257
2231
|
let whereClause = this.statUtil.addPrefixToWhereClause(whStmt, colNames, withRefsNames, 't2.');
|
|
@@ -2259,9 +2233,7 @@ class UtilsSQLite {
|
|
|
2259
2233
|
if (whereClause.endsWith(';')) {
|
|
2260
2234
|
whereClause = whereClause.slice(0, -1);
|
|
2261
2235
|
}
|
|
2262
|
-
const resultString = t1Names
|
|
2263
|
-
.map((t1, index) => `${t1} = ${t2Names[index]}`)
|
|
2264
|
-
.join(' AND ');
|
|
2236
|
+
const resultString = t1Names.map((t1, index) => `${t1} = ${t2Names[index]}`).join(' AND ');
|
|
2265
2237
|
const sql = `SELECT t1.rowid FROM ${updTableName} t1 ` +
|
|
2266
2238
|
`JOIN ${tableName} t2 ON ${resultString} ` +
|
|
2267
2239
|
`WHERE ${whereClause} AND t1.sql_deleted = 0;`;
|
|
@@ -2355,8 +2327,7 @@ class UtilsSQLite {
|
|
|
2355
2327
|
if (isReturningOutsideMessage) {
|
|
2356
2328
|
const joinedWords = wordsBeforeReturning.join(' ') + ';';
|
|
2357
2329
|
let joinedReturningString = returningString.join(' ');
|
|
2358
|
-
if (joinedReturningString.length > 0 &&
|
|
2359
|
-
!joinedReturningString.endsWith(';')) {
|
|
2330
|
+
if (joinedReturningString.length > 0 && !joinedReturningString.endsWith(';')) {
|
|
2360
2331
|
joinedReturningString += ';';
|
|
2361
2332
|
}
|
|
2362
2333
|
return {
|
|
@@ -2714,9 +2685,7 @@ class UtilsJson {
|
|
|
2714
2685
|
createRowStatement(mDB, tColNames, row, j, tableName, mode) {
|
|
2715
2686
|
// Check the row number of columns
|
|
2716
2687
|
const msg = 'CreateRowStatement';
|
|
2717
|
-
if (row.length != tColNames.length ||
|
|
2718
|
-
row.length === 0 ||
|
|
2719
|
-
tColNames.length === 0) {
|
|
2688
|
+
if (row.length != tColNames.length || row.length === 0 || tColNames.length === 0) {
|
|
2720
2689
|
throw new Error(`${msg} Table ${tableName} ` + `values row ${j} not correct length`);
|
|
2721
2690
|
}
|
|
2722
2691
|
try {
|
|
@@ -2750,8 +2719,7 @@ class UtilsJson {
|
|
|
2750
2719
|
// Update
|
|
2751
2720
|
const setString = this.setNameForUpdate(tColNames);
|
|
2752
2721
|
if (setString.length === 0) {
|
|
2753
|
-
throw new Error(`${msg} Table ${tableName} ` +
|
|
2754
|
-
`values row ${j} not set to String`);
|
|
2722
|
+
throw new Error(`${msg} Table ${tableName} ` + `values row ${j} not set to String`);
|
|
2755
2723
|
}
|
|
2756
2724
|
stmt = `UPDATE ${tableName} SET ${setString} WHERE `;
|
|
2757
2725
|
if (typeof row[0] == 'string') {
|
|
@@ -2793,9 +2761,7 @@ class UtilsJson {
|
|
|
2793
2761
|
if (resQuery.length > 0) {
|
|
2794
2762
|
resValues = resQuery[0];
|
|
2795
2763
|
}
|
|
2796
|
-
if (values.length > 0 &&
|
|
2797
|
-
resValues.length > 0 &&
|
|
2798
|
-
values.length === resValues.length) {
|
|
2764
|
+
if (values.length > 0 && resValues.length > 0 && values.length === resValues.length) {
|
|
2799
2765
|
for (let i = 0; i < values.length; i++) {
|
|
2800
2766
|
if (values[i] !== resValues[i]) {
|
|
2801
2767
|
return true;
|
|
@@ -2907,8 +2873,7 @@ class UtilsJson {
|
|
|
2907
2873
|
isIdExists(mDB, dbName, firstColumnName, key) {
|
|
2908
2874
|
const msg = 'IsIdExists';
|
|
2909
2875
|
let ret = false;
|
|
2910
|
-
let query = `SELECT ${firstColumnName} FROM ` +
|
|
2911
|
-
`${dbName} WHERE ${firstColumnName} = `;
|
|
2876
|
+
let query = `SELECT ${firstColumnName} FROM ` + `${dbName} WHERE ${firstColumnName} = `;
|
|
2912
2877
|
if (typeof key === 'number')
|
|
2913
2878
|
query += `${key};`;
|
|
2914
2879
|
if (typeof key === 'string')
|
|
@@ -2964,17 +2929,8 @@ class UtilsJson {
|
|
|
2964
2929
|
* @param obj
|
|
2965
2930
|
*/
|
|
2966
2931
|
isJsonSQLite(obj) {
|
|
2967
|
-
const keyFirstLevel = [
|
|
2968
|
-
|
|
2969
|
-
'version',
|
|
2970
|
-
'overwrite',
|
|
2971
|
-
'encrypted',
|
|
2972
|
-
'mode',
|
|
2973
|
-
'tables',
|
|
2974
|
-
'views',
|
|
2975
|
-
];
|
|
2976
|
-
if (obj == null ||
|
|
2977
|
-
(Object.keys(obj).length === 0 && obj.constructor === Object))
|
|
2932
|
+
const keyFirstLevel = ['database', 'version', 'overwrite', 'encrypted', 'mode', 'tables', 'views'];
|
|
2933
|
+
if (obj == null || (Object.keys(obj).length === 0 && obj.constructor === Object))
|
|
2978
2934
|
return false;
|
|
2979
2935
|
for (const key of Object.keys(obj)) {
|
|
2980
2936
|
if (keyFirstLevel.indexOf(key) === -1)
|
|
@@ -3015,16 +2971,9 @@ class UtilsJson {
|
|
|
3015
2971
|
* @param obj
|
|
3016
2972
|
*/
|
|
3017
2973
|
isTable(obj) {
|
|
3018
|
-
const keyTableLevel = [
|
|
3019
|
-
'name',
|
|
3020
|
-
'schema',
|
|
3021
|
-
'indexes',
|
|
3022
|
-
'triggers',
|
|
3023
|
-
'values',
|
|
3024
|
-
];
|
|
2974
|
+
const keyTableLevel = ['name', 'schema', 'indexes', 'triggers', 'values'];
|
|
3025
2975
|
let nbColumn = 0;
|
|
3026
|
-
if (obj == null ||
|
|
3027
|
-
(Object.keys(obj).length === 0 && obj.constructor === Object))
|
|
2976
|
+
if (obj == null || (Object.keys(obj).length === 0 && obj.constructor === Object))
|
|
3028
2977
|
return false;
|
|
3029
2978
|
for (const key of Object.keys(obj)) {
|
|
3030
2979
|
if (keyTableLevel.indexOf(key) === -1)
|
|
@@ -3081,15 +3030,8 @@ class UtilsJson {
|
|
|
3081
3030
|
* @param obj
|
|
3082
3031
|
*/
|
|
3083
3032
|
isSchema(obj) {
|
|
3084
|
-
const keySchemaLevel = [
|
|
3085
|
-
|
|
3086
|
-
'value',
|
|
3087
|
-
'foreignkey',
|
|
3088
|
-
'primarykey',
|
|
3089
|
-
'constraint',
|
|
3090
|
-
];
|
|
3091
|
-
if (obj == null ||
|
|
3092
|
-
(Object.keys(obj).length === 0 && obj.constructor === Object))
|
|
3033
|
+
const keySchemaLevel = ['column', 'value', 'foreignkey', 'primarykey', 'constraint'];
|
|
3034
|
+
if (obj == null || (Object.keys(obj).length === 0 && obj.constructor === Object))
|
|
3093
3035
|
return false;
|
|
3094
3036
|
for (const key of Object.keys(obj)) {
|
|
3095
3037
|
if (keySchemaLevel.indexOf(key) === -1)
|
|
@@ -3113,8 +3055,7 @@ class UtilsJson {
|
|
|
3113
3055
|
*/
|
|
3114
3056
|
isIndexes(obj) {
|
|
3115
3057
|
const keyIndexesLevel = ['name', 'value', 'mode'];
|
|
3116
|
-
if (obj == null ||
|
|
3117
|
-
(Object.keys(obj).length === 0 && obj.constructor === Object))
|
|
3058
|
+
if (obj == null || (Object.keys(obj).length === 0 && obj.constructor === Object))
|
|
3118
3059
|
return false;
|
|
3119
3060
|
for (const key of Object.keys(obj)) {
|
|
3120
3061
|
if (keyIndexesLevel.indexOf(key) === -1)
|
|
@@ -3123,8 +3064,7 @@ class UtilsJson {
|
|
|
3123
3064
|
return false;
|
|
3124
3065
|
if (key === 'value' && typeof obj[key] != 'string')
|
|
3125
3066
|
return false;
|
|
3126
|
-
if (key === 'mode' &&
|
|
3127
|
-
(typeof obj[key] != 'string' || obj[key].toUpperCase() != 'UNIQUE'))
|
|
3067
|
+
if (key === 'mode' && (typeof obj[key] != 'string' || obj[key].toUpperCase() != 'UNIQUE'))
|
|
3128
3068
|
return false;
|
|
3129
3069
|
}
|
|
3130
3070
|
return true;
|
|
@@ -3134,14 +3074,8 @@ class UtilsJson {
|
|
|
3134
3074
|
* @param obj
|
|
3135
3075
|
*/
|
|
3136
3076
|
isTriggers(obj) {
|
|
3137
|
-
const keyTriggersLevel = [
|
|
3138
|
-
|
|
3139
|
-
'timeevent',
|
|
3140
|
-
'condition',
|
|
3141
|
-
'logic',
|
|
3142
|
-
];
|
|
3143
|
-
if (obj == null ||
|
|
3144
|
-
(Object.keys(obj).length === 0 && obj.constructor === Object))
|
|
3077
|
+
const keyTriggersLevel = ['name', 'timeevent', 'condition', 'logic'];
|
|
3078
|
+
if (obj == null || (Object.keys(obj).length === 0 && obj.constructor === Object))
|
|
3145
3079
|
return false;
|
|
3146
3080
|
for (const key of Object.keys(obj)) {
|
|
3147
3081
|
if (keyTriggersLevel.indexOf(key) === -1)
|
|
@@ -3163,8 +3097,7 @@ class UtilsJson {
|
|
|
3163
3097
|
*/
|
|
3164
3098
|
isView(obj) {
|
|
3165
3099
|
const keyViewLevel = ['name', 'value'];
|
|
3166
|
-
if (obj == null ||
|
|
3167
|
-
(Object.keys(obj).length === 0 && obj.constructor === Object))
|
|
3100
|
+
if (obj == null || (Object.keys(obj).length === 0 && obj.constructor === Object))
|
|
3168
3101
|
return false;
|
|
3169
3102
|
for (const key of Object.keys(obj)) {
|
|
3170
3103
|
if (keyViewLevel.indexOf(key) === -1)
|
|
@@ -3835,9 +3768,7 @@ class ExportToJson {
|
|
|
3835
3768
|
errmsg = `${msg} no sql`;
|
|
3836
3769
|
break;
|
|
3837
3770
|
}
|
|
3838
|
-
if (modTablesKeys.length == 0 ||
|
|
3839
|
-
modTablesKeys.indexOf(tableName) === -1 ||
|
|
3840
|
-
modTables[tableName] == 'No') {
|
|
3771
|
+
if (modTablesKeys.length == 0 || modTablesKeys.indexOf(tableName) === -1 || modTables[tableName] == 'No') {
|
|
3841
3772
|
continue;
|
|
3842
3773
|
}
|
|
3843
3774
|
const table = {};
|
|
@@ -3871,9 +3802,7 @@ class ExportToJson {
|
|
|
3871
3802
|
query = `SELECT * FROM ${tableName};`;
|
|
3872
3803
|
}
|
|
3873
3804
|
else {
|
|
3874
|
-
query =
|
|
3875
|
-
`SELECT * FROM ${tableName} ` +
|
|
3876
|
-
`WHERE last_modified > ${syncDate};`;
|
|
3805
|
+
query = `SELECT * FROM ${tableName} ` + `WHERE last_modified > ${syncDate};`;
|
|
3877
3806
|
}
|
|
3878
3807
|
const values = this.jsonUtil.getValues(mDb, query, tableName);
|
|
3879
3808
|
// check the table object validity
|
|
@@ -4015,7 +3944,7 @@ class ExportToJson {
|
|
|
4015
3944
|
indexOfChar(str, char) {
|
|
4016
3945
|
const tmpArr = [...str];
|
|
4017
3946
|
char = char.toLowerCase();
|
|
4018
|
-
return tmpArr.reduce((results, elem, idx) => elem.toLowerCase() === char ? [...results, idx] : results, []);
|
|
3947
|
+
return tmpArr.reduce((results, elem, idx) => (elem.toLowerCase() === char ? [...results, idx] : results), []);
|
|
4019
3948
|
}
|
|
4020
3949
|
}
|
|
4021
3950
|
exportToJson.ExportToJson = ExportToJson;
|
|
@@ -4565,7 +4494,7 @@ class UtilsUpgrade {
|
|
|
4565
4494
|
*/
|
|
4566
4495
|
async onUpgrade(mDB, vUpgDict, curVersion, targetVersion) {
|
|
4567
4496
|
let changes;
|
|
4568
|
-
const sortedKeys = new Int32Array(Object.keys(vUpgDict).map(item => parseInt(item))).sort();
|
|
4497
|
+
const sortedKeys = new Int32Array(Object.keys(vUpgDict).map((item) => parseInt(item))).sort();
|
|
4569
4498
|
for (const versionKey of sortedKeys) {
|
|
4570
4499
|
if (versionKey > curVersion && versionKey <= targetVersion) {
|
|
4571
4500
|
const statements = vUpgDict[versionKey].statements;
|
|
@@ -4580,8 +4509,7 @@ class UtilsUpgrade {
|
|
|
4580
4509
|
this.sqliteUtil.setVersion(mDB.database, versionKey);
|
|
4581
4510
|
// set Foreign Keys On
|
|
4582
4511
|
this.sqliteUtil.setForeignKeyConstraintsEnabled(mDB.database, true);
|
|
4583
|
-
changes =
|
|
4584
|
-
(await this.sqliteUtil.dbChanges(mDB.database)) - initChanges;
|
|
4512
|
+
changes = (await this.sqliteUtil.dbChanges(mDB.database)) - initChanges;
|
|
4585
4513
|
}
|
|
4586
4514
|
catch (err) {
|
|
4587
4515
|
return Promise.reject(`onUpgrade: ${err}`);
|
|
@@ -4676,10 +4604,7 @@ class Database {
|
|
|
4676
4604
|
this._isDbOpen = false;
|
|
4677
4605
|
let password = '';
|
|
4678
4606
|
try {
|
|
4679
|
-
if (this._encrypted &&
|
|
4680
|
-
(this._mode === 'secret' ||
|
|
4681
|
-
this._mode === 'encryption' ||
|
|
4682
|
-
this._mode === 'decryption')) {
|
|
4607
|
+
if (this._encrypted && (this._mode === 'secret' || this._mode === 'encryption' || this._mode === 'decryption')) {
|
|
4683
4608
|
password = this.secretUtil.getPassphrase();
|
|
4684
4609
|
if (password.length <= 0) {
|
|
4685
4610
|
password = this.globalUtil.secret;
|
|
@@ -4696,8 +4621,7 @@ class Database {
|
|
|
4696
4621
|
this._isDbOpen = true;
|
|
4697
4622
|
if (!this.readonly) {
|
|
4698
4623
|
const curVersion = this.sqliteUtil.getVersion(this.database);
|
|
4699
|
-
if (this.version > curVersion &&
|
|
4700
|
-
Object.keys(this.upgradeVersionDict).length > 0) {
|
|
4624
|
+
if (this.version > curVersion && Object.keys(this.upgradeVersionDict).length > 0) {
|
|
4701
4625
|
try {
|
|
4702
4626
|
await this.fileUtil.copyFileName(this.dbName, `backup-${this.dbName}`);
|
|
4703
4627
|
// execute the upgrade flow process
|
|
@@ -5285,8 +5209,7 @@ class CapacitorSQLite {
|
|
|
5285
5209
|
const readonly = options.readonly ? options.readonly : false;
|
|
5286
5210
|
let upgrades = {};
|
|
5287
5211
|
const versionUpgradeKeys = Object.keys(this.versionUpgrades);
|
|
5288
|
-
if (versionUpgradeKeys.length !== 0 &&
|
|
5289
|
-
versionUpgradeKeys.includes(dbName)) {
|
|
5212
|
+
if (versionUpgradeKeys.length !== 0 && versionUpgradeKeys.includes(dbName)) {
|
|
5290
5213
|
upgrades = this.versionUpgrades[dbName];
|
|
5291
5214
|
}
|
|
5292
5215
|
const connName = readonly ? 'RO_' + dbName : 'RW_' + dbName;
|
|
@@ -5471,9 +5394,7 @@ class CapacitorSQLite {
|
|
|
5471
5394
|
const statements = this.getOptionValue(options, 'statements');
|
|
5472
5395
|
const transaction = this.getOptionValue(options, 'transaction', true);
|
|
5473
5396
|
const readonly = options.readonly ? options.readonly : false;
|
|
5474
|
-
const isSQL92 = Object.keys(options).includes('isSQL92')
|
|
5475
|
-
? options.isSQL92
|
|
5476
|
-
: true;
|
|
5397
|
+
const isSQL92 = Object.keys(options).includes('isSQL92') ? options.isSQL92 : true;
|
|
5477
5398
|
const connName = 'RW_' + dbName;
|
|
5478
5399
|
const database = this.getDatabaseConnectionOrThrowError(connName);
|
|
5479
5400
|
if (database.isDBOpen()) {
|
|
@@ -5504,12 +5425,8 @@ class CapacitorSQLite {
|
|
|
5504
5425
|
const setOfStatements = this.getOptionValue(options, 'set');
|
|
5505
5426
|
const transaction = this.getOptionValue(options, 'transaction', true);
|
|
5506
5427
|
const readonly = options.readonly ? options.readonly : false;
|
|
5507
|
-
const returnMode = Object.keys(options).includes('returnMode')
|
|
5508
|
-
|
|
5509
|
-
: 'no';
|
|
5510
|
-
const isSQL92 = Object.keys(options).includes('isSQL92')
|
|
5511
|
-
? options.isSQL92
|
|
5512
|
-
: true;
|
|
5428
|
+
const returnMode = Object.keys(options).includes('returnMode') ? options.returnMode : 'no';
|
|
5429
|
+
const isSQL92 = Object.keys(options).includes('isSQL92') ? options.isSQL92 : true;
|
|
5513
5430
|
const connName = 'RW_' + dbName;
|
|
5514
5431
|
const database = this.getDatabaseConnectionOrThrowError(connName);
|
|
5515
5432
|
for (const sStmt of setOfStatements) {
|
|
@@ -5547,9 +5464,7 @@ class CapacitorSQLite {
|
|
|
5547
5464
|
const transaction = this.getOptionValue(options, 'transaction', true);
|
|
5548
5465
|
const readonly = options.readonly ? options.readonly : false;
|
|
5549
5466
|
const returnMode = options.returnMode ? options.returnMode : 'no';
|
|
5550
|
-
const isSQL92 = Object.keys(options).includes('isSQL92')
|
|
5551
|
-
? options.isSQL92
|
|
5552
|
-
: true;
|
|
5467
|
+
const isSQL92 = Object.keys(options).includes('isSQL92') ? options.isSQL92 : true;
|
|
5553
5468
|
const connName = 'RW_' + dbName;
|
|
5554
5469
|
const database = this.getDatabaseConnectionOrThrowError(connName);
|
|
5555
5470
|
if (database.isDBOpen()) {
|
|
@@ -5578,9 +5493,7 @@ class CapacitorSQLite {
|
|
|
5578
5493
|
throw new Error('Query: Statement may not be an empty string.');
|
|
5579
5494
|
}
|
|
5580
5495
|
const readonly = options.readonly ? options.readonly : false;
|
|
5581
|
-
const isSQL92 = Object.keys(options).includes('isSQL92')
|
|
5582
|
-
? options.isSQL92
|
|
5583
|
-
: true;
|
|
5496
|
+
const isSQL92 = Object.keys(options).includes('isSQL92') ? options.isSQL92 : true;
|
|
5584
5497
|
const connName = readonly ? 'RO_' + dbName : 'RW_' + dbName;
|
|
5585
5498
|
const database = this.getDatabaseConnectionOrThrowError(connName);
|
|
5586
5499
|
if (database.isDBOpen()) {
|
|
@@ -5848,8 +5761,7 @@ class CapacitorSQLite {
|
|
|
5848
5761
|
const upgrades = this.getOptionValue(options, 'upgrade');
|
|
5849
5762
|
for (const upgrade of upgrades) {
|
|
5850
5763
|
const versionUpgradeKeys = Object.keys(upgrade);
|
|
5851
|
-
if (!versionUpgradeKeys.includes('toVersion') ||
|
|
5852
|
-
!versionUpgradeKeys.includes('statements')) {
|
|
5764
|
+
if (!versionUpgradeKeys.includes('toVersion') || !versionUpgradeKeys.includes('statements')) {
|
|
5853
5765
|
throw new Error('Must provide an upgrade capSQLiteVersionUpgrade Object');
|
|
5854
5766
|
}
|
|
5855
5767
|
if (typeof upgrade.toVersion != 'number') {
|