updates
This commit is contained in:
parent
f51096bec4
commit
e825506757
@ -146,8 +146,6 @@ async function addDb({ dbFullName, tableName, data, tableSchema, duplicateColumn
|
|||||||
tableSchema,
|
tableSchema,
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log(newInsert);
|
|
||||||
|
|
||||||
////////////////////////////////////////
|
////////////////////////////////////////
|
||||||
////////////////////////////////////////
|
////////////////////////////////////////
|
||||||
////////////////////////////////////////
|
////////////////////////////////////////
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
/**
|
/**
|
||||||
* Imports: Handle imports
|
* Imports: Handle imports
|
||||||
*/
|
*/
|
||||||
|
const encrypt = require("../../functions/encrypt");
|
||||||
|
const sanitizeHtml = require("sanitize-html");
|
||||||
|
const sanitizeHtmlOptions = require("../utils/sanitizeHtmlOptions");
|
||||||
const dsqlDbHandler = require("../utils/dsqlDbHandler");
|
const dsqlDbHandler = require("../utils/dsqlDbHandler");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -46,24 +49,52 @@ async function updateDb({ dbFullName, tableName, data, tableSchema, identifierCo
|
|||||||
let updateValues = [];
|
let updateValues = [];
|
||||||
|
|
||||||
for (let i = 0; i < dataKeys.length; i++) {
|
for (let i = 0; i < dataKeys.length; i++) {
|
||||||
|
try {
|
||||||
const dataKey = dataKeys[i];
|
const dataKey = dataKeys[i];
|
||||||
|
|
||||||
let value = data[dataKey];
|
let value = data[dataKey];
|
||||||
|
|
||||||
|
const targetFieldSchemaArray = tableSchema ? tableSchema?.fields?.filter((field) => field.fieldName === dataKey) : null;
|
||||||
|
const targetFieldSchema = targetFieldSchemaArray && targetFieldSchemaArray[0] ? targetFieldSchemaArray[0] : null;
|
||||||
|
|
||||||
|
if (!value) continue;
|
||||||
|
|
||||||
|
if (targetFieldSchema?.encrypted) {
|
||||||
|
value = encrypt({ data: value, encryptionKey, encryptionSalt });
|
||||||
|
}
|
||||||
|
|
||||||
|
if (targetFieldSchema?.richText) {
|
||||||
|
value = sanitizeHtml(value, sanitizeHtmlOptions);
|
||||||
|
}
|
||||||
|
|
||||||
if (typeof value === "string" && value.match(/^null$/i)) value = "";
|
if (typeof value === "string" && value.match(/^null$/i)) value = "";
|
||||||
|
if (typeof value === "object") {
|
||||||
|
value = JSON.stringify(value);
|
||||||
|
}
|
||||||
|
|
||||||
if (!value && value != 0) continue;
|
if (!value && value != 0) continue;
|
||||||
|
|
||||||
updateKeyValueArray.push(`\`${dataKey}\`=?`);
|
updateKeyValueArray.push(`\`${dataKey}\`=?`);
|
||||||
updateValues.push(value);
|
updateValues.push(value);
|
||||||
|
|
||||||
|
////////////////////////////////////////
|
||||||
|
////////////////////////////////////////
|
||||||
|
} catch (error) {
|
||||||
|
////////////////////////////////////////
|
||||||
|
////////////////////////////////////////
|
||||||
|
|
||||||
|
console.log("DSQL: Error in parsing data keys in update function =>", error.message);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** ********************************************** */
|
////////////////////////////////////////
|
||||||
|
////////////////////////////////////////
|
||||||
|
|
||||||
updateKeyValueArray.push(`date_updated='${Date()}'`);
|
updateKeyValueArray.push(`date_updated='${Date()}'`);
|
||||||
updateKeyValueArray.push(`date_updated_code='${Date.now()}'`);
|
updateKeyValueArray.push(`date_updated_code='${Date.now()}'`);
|
||||||
|
|
||||||
/** ********************************************** */
|
////////////////////////////////////////
|
||||||
|
////////////////////////////////////////
|
||||||
|
|
||||||
const query = `UPDATE ${tableName} SET ${updateKeyValueArray.join(",")} WHERE \`${identifierColumnName}\`=?`;
|
const query = `UPDATE ${tableName} SET ${updateKeyValueArray.join(",")} WHERE \`${identifierColumnName}\`=?`;
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "datasquirel",
|
"name": "datasquirel",
|
||||||
"version": "1.1.78",
|
"version": "1.1.79",
|
||||||
"description": "Cloud-based SQL data management tool",
|
"description": "Cloud-based SQL data management tool",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
Loading…
Reference in New Issue
Block a user