Updates
This commit is contained in:
parent
14ea760373
commit
0d9f313dc0
@ -7,12 +7,13 @@ exports.default = grabParsedValue;
|
|||||||
const sanitize_html_1 = __importDefault(require("sanitize-html"));
|
const sanitize_html_1 = __importDefault(require("sanitize-html"));
|
||||||
const sanitizeHtmlOptions_1 = __importDefault(require("../html/sanitizeHtmlOptions"));
|
const sanitizeHtmlOptions_1 = __importDefault(require("../html/sanitizeHtmlOptions"));
|
||||||
const encrypt_1 = __importDefault(require("../../dsql/encrypt"));
|
const encrypt_1 = __importDefault(require("../../dsql/encrypt"));
|
||||||
|
const numberfy_1 = __importDefault(require("../../../utils/numberfy"));
|
||||||
/**
|
/**
|
||||||
* # Update DB Function
|
* # Update DB Function
|
||||||
* @description
|
* @description
|
||||||
*/
|
*/
|
||||||
function grabParsedValue({ value, tableSchema, encryptionKey, encryptionSalt, dataKey, }) {
|
function grabParsedValue({ value, tableSchema, encryptionKey, encryptionSalt, dataKey, }) {
|
||||||
var _a, _b, _c;
|
var _a, _b, _c, _d;
|
||||||
let newValue = value;
|
let newValue = value;
|
||||||
const targetFieldSchema = tableSchema
|
const targetFieldSchema = tableSchema
|
||||||
? (_a = tableSchema === null || tableSchema === void 0 ? void 0 : tableSchema.fields) === null || _a === void 0 ? void 0 : _a.find((field) => field.fieldName === dataKey)
|
? (_a = tableSchema === null || tableSchema === void 0 ? void 0 : tableSchema.fields) === null || _a === void 0 ? void 0 : _a.find((field) => field.fieldName === dataKey)
|
||||||
@ -37,6 +38,10 @@ function grabParsedValue({ value, tableSchema, encryptionKey, encryptionSalt, da
|
|||||||
!(value === null || value === void 0 ? void 0 : value.match(/./))) {
|
!(value === null || value === void 0 ? void 0 : value.match(/./))) {
|
||||||
newValue = "";
|
newValue = "";
|
||||||
}
|
}
|
||||||
|
if (((_c = targetFieldSchema === null || targetFieldSchema === void 0 ? void 0 : targetFieldSchema.dataType) === null || _c === void 0 ? void 0 : _c.match(/int$|decimal|float|double/i)) &&
|
||||||
|
typeof value == "string") {
|
||||||
|
newValue = (0, numberfy_1.default)(value);
|
||||||
|
}
|
||||||
if (targetFieldSchema === null || targetFieldSchema === void 0 ? void 0 : targetFieldSchema.encrypted) {
|
if (targetFieldSchema === null || targetFieldSchema === void 0 ? void 0 : targetFieldSchema.encrypted) {
|
||||||
newValue =
|
newValue =
|
||||||
(0, encrypt_1.default)({
|
(0, encrypt_1.default)({
|
||||||
@ -60,7 +65,7 @@ function grabParsedValue({ value, tableSchema, encryptionKey, encryptionSalt, da
|
|||||||
newValue = undefined;
|
newValue = undefined;
|
||||||
}
|
}
|
||||||
if (typeof newValue === "boolean" ||
|
if (typeof newValue === "boolean" ||
|
||||||
((_c = targetFieldSchema === null || targetFieldSchema === void 0 ? void 0 : targetFieldSchema.dataType) === null || _c === void 0 ? void 0 : _c.match(/boolean/i))) {
|
((_d = targetFieldSchema === null || targetFieldSchema === void 0 ? void 0 : targetFieldSchema.dataType) === null || _d === void 0 ? void 0 : _d.match(/boolean/i))) {
|
||||||
newValue = newValue ? 1 : 0;
|
newValue = newValue ? 1 : 0;
|
||||||
}
|
}
|
||||||
return newValue;
|
return newValue;
|
||||||
|
|||||||
@ -261,10 +261,11 @@ function sqlGenerator({ tableName, genObject, dbFullName, count }) {
|
|||||||
}
|
}
|
||||||
return genSqlSrchStr({ queryObj, field, join: genObject === null || genObject === void 0 ? void 0 : genObject.join });
|
return genSqlSrchStr({ queryObj, field, join: genObject === null || genObject === void 0 ? void 0 : genObject.join });
|
||||||
});
|
});
|
||||||
const isSearchStr = (sqlSearhString === null || sqlSearhString === void 0 ? void 0 : sqlSearhString[0]) && sqlSearhString.find((str) => str);
|
const cleanedUpSearchStr = sqlSearhString === null || sqlSearhString === void 0 ? void 0 : sqlSearhString.filter((str) => typeof str == "string");
|
||||||
|
const isSearchStr = (cleanedUpSearchStr === null || cleanedUpSearchStr === void 0 ? void 0 : cleanedUpSearchStr[0]) && cleanedUpSearchStr.find((str) => str);
|
||||||
if (isSearchStr) {
|
if (isSearchStr) {
|
||||||
const stringOperator = (genObject === null || genObject === void 0 ? void 0 : genObject.searchOperator) || "AND";
|
const stringOperator = (genObject === null || genObject === void 0 ? void 0 : genObject.searchOperator) || "AND";
|
||||||
queryString += ` WHERE ${sqlSearhString.join(` ${stringOperator} `)}`;
|
queryString += ` WHERE ${cleanedUpSearchStr.join(` ${stringOperator} `)}`;
|
||||||
}
|
}
|
||||||
if ((genObject === null || genObject === void 0 ? void 0 : genObject.fullTextSearch) && fullTextSearchStr && fullTextMatchStr) {
|
if ((genObject === null || genObject === void 0 ? void 0 : genObject.fullTextSearch) && fullTextSearchStr && fullTextMatchStr) {
|
||||||
queryString += `${isSearchStr ? " AND" : " WHERE"} ${fullTextMatchStr}`;
|
queryString += `${isSearchStr ? " AND" : " WHERE"} ${fullTextMatchStr}`;
|
||||||
|
|||||||
@ -2,6 +2,7 @@ import sanitizeHtml from "sanitize-html";
|
|||||||
import sanitizeHtmlOptions from "../html/sanitizeHtmlOptions";
|
import sanitizeHtmlOptions from "../html/sanitizeHtmlOptions";
|
||||||
import encrypt from "../../dsql/encrypt";
|
import encrypt from "../../dsql/encrypt";
|
||||||
import { DSQL_TableSchemaType } from "../../../types";
|
import { DSQL_TableSchemaType } from "../../../types";
|
||||||
|
import numberfy from "../../../utils/numberfy";
|
||||||
import _ from "lodash";
|
import _ from "lodash";
|
||||||
|
|
||||||
type Param = {
|
type Param = {
|
||||||
@ -57,6 +58,13 @@ export default function grabParsedValue({
|
|||||||
newValue = "";
|
newValue = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
targetFieldSchema?.dataType?.match(/int$|decimal|float|double/i) &&
|
||||||
|
typeof value == "string"
|
||||||
|
) {
|
||||||
|
newValue = numberfy(value);
|
||||||
|
}
|
||||||
|
|
||||||
if (targetFieldSchema?.encrypted) {
|
if (targetFieldSchema?.encrypted) {
|
||||||
newValue =
|
newValue =
|
||||||
encrypt({
|
encrypt({
|
||||||
|
|||||||
@ -359,12 +359,18 @@ export default function sqlGenerator<
|
|||||||
return genSqlSrchStr({ queryObj, field, join: genObject?.join });
|
return genSqlSrchStr({ queryObj, field, join: genObject?.join });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const cleanedUpSearchStr = sqlSearhString?.filter(
|
||||||
|
(str) => typeof str == "string"
|
||||||
|
);
|
||||||
|
|
||||||
const isSearchStr =
|
const isSearchStr =
|
||||||
sqlSearhString?.[0] && sqlSearhString.find((str) => str);
|
cleanedUpSearchStr?.[0] && cleanedUpSearchStr.find((str) => str);
|
||||||
|
|
||||||
if (isSearchStr) {
|
if (isSearchStr) {
|
||||||
const stringOperator = genObject?.searchOperator || "AND";
|
const stringOperator = genObject?.searchOperator || "AND";
|
||||||
queryString += ` WHERE ${sqlSearhString.join(` ${stringOperator} `)}`;
|
queryString += ` WHERE ${cleanedUpSearchStr.join(
|
||||||
|
` ${stringOperator} `
|
||||||
|
)}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (genObject?.fullTextSearch && fullTextSearchStr && fullTextMatchStr) {
|
if (genObject?.fullTextSearch && fullTextSearchStr && fullTextMatchStr) {
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@moduletrace/datasquirel",
|
"name": "@moduletrace/datasquirel",
|
||||||
"version": "5.5.4",
|
"version": "5.5.5",
|
||||||
"description": "Cloud-based SQL data management tool",
|
"description": "Cloud-based SQL data management tool",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"bin": {
|
"bin": {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user