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