From f51096bec48d98d834acdd79ce6ed58c5e9e6496 Mon Sep 17 00:00:00 2001 From: Tben Date: Sat, 8 Jul 2023 08:19:31 +0100 Subject: [PATCH] updates --- engine/db/addDb.js | 5 +++- engine/utils/parseDbResults.js | 42 ++++++++++++++++++++++------------ package.json | 2 +- 3 files changed, 32 insertions(+), 17 deletions(-) diff --git a/engine/db/addDb.js b/engine/db/addDb.js index 434e0df..fe7435d 100644 --- a/engine/db/addDb.js +++ b/engine/db/addDb.js @@ -87,7 +87,7 @@ async function addDb({ dbFullName, tableName, data, tableSchema, duplicateColumn const dataKey = dataKeys[i]; let value = data[dataKey]; - const targetFieldSchemaArray = tableSchema ? tableSchema?.fields.filter((field) => field.fieldName === dataKey) : null; + const targetFieldSchemaArray = tableSchema ? tableSchema?.fields?.filter((field) => field.fieldName === dataKey) : null; const targetFieldSchema = targetFieldSchemaArray && targetFieldSchemaArray[0] ? targetFieldSchemaArray[0] : null; if (!value) continue; @@ -109,6 +109,7 @@ async function addDb({ dbFullName, tableName, data, tableSchema, duplicateColumn insertValuesArray.push(value); } catch (error) { console.log("DSQL: Error in parsing data keys =>", error.message); + continue; } } @@ -145,6 +146,8 @@ async function addDb({ dbFullName, tableName, data, tableSchema, duplicateColumn tableSchema, }); + console.log(newInsert); + //////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// diff --git a/engine/utils/parseDbResults.js b/engine/utils/parseDbResults.js index 52ae234..6ec3e1f 100644 --- a/engine/utils/parseDbResults.js +++ b/engine/utils/parseDbResults.js @@ -22,6 +22,13 @@ module.exports = async function parseDbResults({ unparsedResults, tableSchema, e */ let parsedResults = []; + /** + * Check if query values array is an array + */ + if (!unparsedResults || !Array.isArray(unparsedResults) || !unparsedResults[0]) { + return unparsedResults; + } + try { /** * Declare variables @@ -34,23 +41,28 @@ module.exports = async function parseDbResults({ unparsedResults, tableSchema, e let resultFieldNames = Object.keys(result); for (let i = 0; i < resultFieldNames.length; i++) { - const resultFieldName = resultFieldNames[i]; - let resultFieldSchema = tableSchema.fields[i]; + try { + const resultFieldName = resultFieldNames[i]; + let resultFieldSchema = tableSchema?.fields[i]; - if (resultFieldName?.match(defaultFieldsRegexp)) { - continue; - } - - let value = result[resultFieldName]; - - if (typeof value !== "number" && !value) { - continue; - } - - if (resultFieldSchema?.encrypted) { - if (value?.match(/./)) { - result[resultFieldName] = decrypt({ encryptedString: value, encryptionKey, encryptionSalt }); + if (resultFieldName?.match(defaultFieldsRegexp)) { + continue; } + + let value = result[resultFieldName]; + + if (typeof value !== "number" && !value) { + continue; + } + + if (resultFieldSchema?.encrypted) { + if (value?.match(/./)) { + result[resultFieldName] = decrypt({ encryptedString: value, encryptionKey, encryptionSalt }); + } + } + } catch (error) { + console.log("ERROR in parseDbResults Function =>", error.message); + continue; } } diff --git a/package.json b/package.json index 644d4e7..9be1385 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "datasquirel", - "version": "1.1.77", + "version": "1.1.78", "description": "Cloud-based SQL data management tool", "main": "index.js", "scripts": {