Updates
This commit is contained in:
parent
0858b18344
commit
7959014721
@ -13,6 +13,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
exports.default = addDbEntry;
|
exports.default = addDbEntry;
|
||||||
|
const sql_formatter_1 = require("sql-formatter");
|
||||||
const updateDbEntry_1 = __importDefault(require("./updateDbEntry"));
|
const updateDbEntry_1 = __importDefault(require("./updateDbEntry"));
|
||||||
const lodash_1 = __importDefault(require("lodash"));
|
const lodash_1 = __importDefault(require("lodash"));
|
||||||
const conn_db_handler_1 = __importDefault(require("../../../utils/db/conn-db-handler"));
|
const conn_db_handler_1 = __importDefault(require("../../../utils/db/conn-db-handler"));
|
||||||
@ -191,7 +192,7 @@ function addDbEntry(_a) {
|
|||||||
success: Boolean(newInsert === null || newInsert === void 0 ? void 0 : newInsert.insertId),
|
success: Boolean(newInsert === null || newInsert === void 0 ? void 0 : newInsert.insertId),
|
||||||
payload: newInsert,
|
payload: newInsert,
|
||||||
queryObject: {
|
queryObject: {
|
||||||
sql: query,
|
sql: (0, sql_formatter_1.format)(query),
|
||||||
params: finalQueryValues,
|
params: finalQueryValues,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@ -13,6 +13,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
exports.default = updateDbEntry;
|
exports.default = updateDbEntry;
|
||||||
|
const sql_formatter_1 = require("sql-formatter");
|
||||||
const check_if_is_master_1 = __importDefault(require("../../../utils/check-if-is-master"));
|
const check_if_is_master_1 = __importDefault(require("../../../utils/check-if-is-master"));
|
||||||
const conn_db_handler_1 = __importDefault(require("../../../utils/db/conn-db-handler"));
|
const conn_db_handler_1 = __importDefault(require("../../../utils/db/conn-db-handler"));
|
||||||
const lodash_1 = __importDefault(require("lodash"));
|
const lodash_1 = __importDefault(require("lodash"));
|
||||||
@ -109,7 +110,7 @@ function updateDbEntry(_a) {
|
|||||||
success: Boolean(updatedEntry === null || updatedEntry === void 0 ? void 0 : updatedEntry.affectedRows),
|
success: Boolean(updatedEntry === null || updatedEntry === void 0 ? void 0 : updatedEntry.affectedRows),
|
||||||
payload: updatedEntry,
|
payload: updatedEntry,
|
||||||
queryObject: {
|
queryObject: {
|
||||||
sql: query,
|
sql: (0, sql_formatter_1.format)(query),
|
||||||
params: updateValues,
|
params: updateValues,
|
||||||
},
|
},
|
||||||
debug: debug ? { data, newData } : undefined,
|
debug: debug ? { data, newData } : undefined,
|
||||||
|
|||||||
@ -77,55 +77,9 @@ function sqlGenerator({ tableName, genObject, dbFullName, count }) {
|
|||||||
else if (operatorStrParam.str) {
|
else if (operatorStrParam.str) {
|
||||||
str = operatorStrParam.str;
|
str = operatorStrParam.str;
|
||||||
}
|
}
|
||||||
// if (queryObj.equality == "LIKE") {
|
|
||||||
// str = `LOWER(${finalFieldName}) LIKE LOWER('%${valueParsed}%')`;
|
|
||||||
// } else if (queryObj.equality == "LIKE_RAW") {
|
|
||||||
// str = `LOWER(${finalFieldName}) LIKE LOWER(?)`;
|
|
||||||
// sqlSearhValues.push(valueParsed);
|
|
||||||
// } else if (queryObj.equality == "NOT LIKE") {
|
|
||||||
// str = `LOWER(${finalFieldName}) NOT LIKE LOWER('%${valueParsed}%')`;
|
|
||||||
// } else if (queryObj.equality == "NOT LIKE_RAW") {
|
|
||||||
// str = `LOWER(${finalFieldName}) NOT LIKE LOWER(?)`;
|
|
||||||
// sqlSearhValues.push(valueParsed);
|
|
||||||
// } else if (queryObj.equality == "REGEXP") {
|
|
||||||
// str = `LOWER(${finalFieldName}) REGEXP LOWER(?)`;
|
|
||||||
// sqlSearhValues.push(valueParsed);
|
|
||||||
// } else if (queryObj.equality == "FULLTEXT") {
|
|
||||||
// str = `MATCH(${finalFieldName}) AGAINST(? IN BOOLEAN MODE)`;
|
|
||||||
// sqlSearhValues.push(valueParsed);
|
|
||||||
// } else if (queryObj.equality == "NOT EQUAL") {
|
|
||||||
// str = `${finalFieldName} != ?`;
|
|
||||||
// sqlSearhValues.push(valueParsed);
|
|
||||||
// } else if (queryObj.equality) {
|
|
||||||
// str = `${finalFieldName} ${operator} ?`;
|
|
||||||
// sqlSearhValues.push(valueParsed);
|
|
||||||
// } else {
|
|
||||||
// sqlSearhValues.push(valueParsed);
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
const sqlSearhString = queryKeys === null || queryKeys === void 0 ? void 0 : queryKeys.map((field) => {
|
|
||||||
const queryObj = finalQuery === null || finalQuery === void 0 ? void 0 : finalQuery[field];
|
|
||||||
if (!queryObj)
|
|
||||||
return;
|
|
||||||
if (queryObj.__query) {
|
|
||||||
const subQueryGroup = queryObj.__query;
|
|
||||||
const subSearchKeys = Object.keys(subQueryGroup);
|
|
||||||
const subSearchString = subSearchKeys.map((_field) => {
|
|
||||||
const newSubQueryObj = subQueryGroup === null || subQueryGroup === void 0 ? void 0 : subQueryGroup[_field];
|
|
||||||
return genSqlSrchStr({
|
|
||||||
queryObj: newSubQueryObj,
|
|
||||||
field: _field,
|
|
||||||
join: genObject === null || genObject === void 0 ? void 0 : genObject.join,
|
|
||||||
});
|
|
||||||
});
|
|
||||||
return ("(" +
|
|
||||||
subSearchString.join(` ${queryObj.operator || "AND"} `) +
|
|
||||||
")");
|
|
||||||
}
|
|
||||||
return genSqlSrchStr({ queryObj, field, join: genObject === null || genObject === void 0 ? void 0 : genObject.join });
|
|
||||||
});
|
|
||||||
function generateJoinStr(mtch, join) {
|
function generateJoinStr(mtch, join) {
|
||||||
return `${finalDbName}${typeof mtch.source == "object" ? mtch.source.tableName : tableName}.${typeof mtch.source == "object" ? mtch.source.fieldName : mtch.source}=${(() => {
|
return `${finalDbName}${typeof mtch.source == "object" ? mtch.source.tableName : tableName}.${typeof mtch.source == "object" ? mtch.source.fieldName : mtch.source}=${(() => {
|
||||||
if (mtch.targetLiteral) {
|
if (mtch.targetLiteral) {
|
||||||
@ -173,6 +127,32 @@ function sqlGenerator({ tableName, genObject, dbFullName, count }) {
|
|||||||
str += " *";
|
str += " *";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (genObject === null || genObject === void 0 ? void 0 : genObject.countSubQueries) {
|
||||||
|
let countSqls = [];
|
||||||
|
for (let i = 0; i < genObject.countSubQueries.length; i++) {
|
||||||
|
const countSubQuery = genObject.countSubQueries[i];
|
||||||
|
let subQStr = `(SELECT COUNT(*)`;
|
||||||
|
subQStr += ` FROM ${countSubQuery.table}`;
|
||||||
|
subQStr += ` WHERE (`;
|
||||||
|
for (let j = 0; j < countSubQuery.srcTrgMap.length; j++) {
|
||||||
|
const csqSrc = countSubQuery.srcTrgMap[j];
|
||||||
|
subQStr += ` ${countSubQuery.table}.${csqSrc.src}`;
|
||||||
|
if (typeof csqSrc.trg == "string") {
|
||||||
|
subQStr += ` = ?`;
|
||||||
|
sqlSearhValues.push(csqSrc.trg);
|
||||||
|
}
|
||||||
|
else if (typeof csqSrc.trg == "object") {
|
||||||
|
subQStr += ` = ${csqSrc.trg.table}.${csqSrc.trg.field}`;
|
||||||
|
}
|
||||||
|
if (j < countSubQuery.srcTrgMap.length - 1) {
|
||||||
|
subQStr += ` AND `;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
subQStr += ` )) AS ${countSubQuery.alias}`;
|
||||||
|
countSqls.push(subQStr);
|
||||||
|
}
|
||||||
|
str += `, ${countSqls.join(",")}`;
|
||||||
|
}
|
||||||
if ((genObject === null || genObject === void 0 ? void 0 : genObject.join) && !count) {
|
if ((genObject === null || genObject === void 0 ? void 0 : genObject.join) && !count) {
|
||||||
const existingJoinTableNames = [tableName];
|
const existingJoinTableNames = [tableName];
|
||||||
str +=
|
str +=
|
||||||
@ -242,6 +222,27 @@ function sqlGenerator({ tableName, genObject, dbFullName, count }) {
|
|||||||
}
|
}
|
||||||
return str;
|
return str;
|
||||||
})();
|
})();
|
||||||
|
const sqlSearhString = queryKeys === null || queryKeys === void 0 ? void 0 : queryKeys.map((field) => {
|
||||||
|
const queryObj = finalQuery === null || finalQuery === void 0 ? void 0 : finalQuery[field];
|
||||||
|
if (!queryObj)
|
||||||
|
return;
|
||||||
|
if (queryObj.__query) {
|
||||||
|
const subQueryGroup = queryObj.__query;
|
||||||
|
const subSearchKeys = Object.keys(subQueryGroup);
|
||||||
|
const subSearchString = subSearchKeys.map((_field) => {
|
||||||
|
const newSubQueryObj = subQueryGroup === null || subQueryGroup === void 0 ? void 0 : subQueryGroup[_field];
|
||||||
|
return genSqlSrchStr({
|
||||||
|
queryObj: newSubQueryObj,
|
||||||
|
field: _field,
|
||||||
|
join: genObject === null || genObject === void 0 ? void 0 : genObject.join,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
return ("(" +
|
||||||
|
subSearchString.join(` ${queryObj.operator || "AND"} `) +
|
||||||
|
")");
|
||||||
|
}
|
||||||
|
return genSqlSrchStr({ queryObj, field, join: genObject === null || genObject === void 0 ? void 0 : genObject.join });
|
||||||
|
});
|
||||||
if ((sqlSearhString === null || sqlSearhString === void 0 ? void 0 : sqlSearhString[0]) && sqlSearhString.find((str) => str)) {
|
if ((sqlSearhString === null || sqlSearhString === void 0 ? void 0 : sqlSearhString[0]) && sqlSearhString.find((str) => str)) {
|
||||||
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 ${sqlSearhString.join(` ${stringOperator} `)}`;
|
||||||
|
|||||||
15
dist/package-shared/types/index.d.ts
vendored
15
dist/package-shared/types/index.d.ts
vendored
@ -827,8 +827,21 @@ export type ServerQueryParam<T extends {
|
|||||||
};
|
};
|
||||||
join?: ServerQueryParamsJoin<K>[];
|
join?: ServerQueryParamsJoin<K>[];
|
||||||
group?: (keyof T)[];
|
group?: (keyof T)[];
|
||||||
|
countSubQueries?: ServerQueryParamsCount[];
|
||||||
[key: string]: any;
|
[key: string]: any;
|
||||||
};
|
};
|
||||||
|
export type ServerQueryParamsCount = {
|
||||||
|
table: string;
|
||||||
|
srcTrgMap: {
|
||||||
|
src: string;
|
||||||
|
trg: string | ServerQueryParamsCountSrcTrgMap;
|
||||||
|
}[];
|
||||||
|
alias: string;
|
||||||
|
};
|
||||||
|
export type ServerQueryParamsCountSrcTrgMap = {
|
||||||
|
table: string;
|
||||||
|
field: string;
|
||||||
|
};
|
||||||
export type TableSelectFieldsObject<T extends {
|
export type TableSelectFieldsObject<T extends {
|
||||||
[k: string]: any;
|
[k: string]: any;
|
||||||
} = {
|
} = {
|
||||||
@ -1543,8 +1556,8 @@ export type MediaUploadDataType = ImageObjectType & FileObjectType & {
|
|||||||
existingMediaRecordId?: number;
|
existingMediaRecordId?: number;
|
||||||
};
|
};
|
||||||
export declare const ImageMimeTypes: (keyof sharp.FormatEnum)[];
|
export declare const ImageMimeTypes: (keyof sharp.FormatEnum)[];
|
||||||
export declare const FileMimeTypes: readonly ["pdf", "csv", "json", "sql", "xlsx", "txt", "zip", "tar.xz", "xz", "yaml", "yml", "sh", "jsx", "js", "tsx", "ts", "html", "css"];
|
|
||||||
export declare const VideoMimeTypes: readonly ["mp4", "wav"];
|
export declare const VideoMimeTypes: readonly ["mp4", "wav"];
|
||||||
|
export declare const FileMimeTypes: readonly [...(keyof sharp.FormatEnum)[], "mp4", "wav", "pdf", "csv", "json", "sql", "xlsx", "txt", "zip", "tar.xz", "xz", "yaml", "yml", "sh", "jsx", "js", "tsx", "ts", "html", "css"];
|
||||||
export declare const CurrentlyEditedFieldActions: readonly ["edit-field", "edit-index", "delete-field", "delete-index", "new-field", "new-index", "move-up", "move-down", "complete"];
|
export declare const CurrentlyEditedFieldActions: readonly ["edit-field", "edit-index", "delete-field", "delete-index", "new-field", "new-index", "move-up", "move-down", "complete"];
|
||||||
export type CurrentlyEditedTableSchemaType = {
|
export type CurrentlyEditedTableSchemaType = {
|
||||||
action: (typeof CurrentlyEditedFieldActions)[number];
|
action: (typeof CurrentlyEditedFieldActions)[number];
|
||||||
|
|||||||
6
dist/package-shared/types/index.js
vendored
6
dist/package-shared/types/index.js
vendored
@ -1,6 +1,6 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
exports.AIOptions = exports.OpsActions = exports.TimeParadigms = exports.UserAPIAuthActions = exports.UserAPIParadigms = exports.TargetMediaParadigms = exports.EnvKeys = exports.AppVersions = exports.APIParadigms = exports.UserSQLPermissions = exports.SQLPermissions = exports.InvitedUserSelectFields = exports.DelegatedUserSelectFields = exports.UserSelectFields = exports.IndexTypes = exports.DefaultSQLValuesLiteral = exports.CurrentlyEditedFieldActions = exports.VideoMimeTypes = exports.FileMimeTypes = exports.ImageMimeTypes = exports.MediaTypes = exports.DockerComposeServices = exports.DatasquirelWindowEvents = exports.WebSocketEvents = exports.QueueJobTypes = exports.SignUpParadigms = exports.UserTypes = exports.QueryFields = exports.DsqlCrudActions = exports.DataCrudRequestMethodsLowerCase = exports.DataCrudRequestMethods = exports.ServerQueryEqualities = exports.ServerQueryOperators = exports.TextFieldTypesArray = exports.UsersOmitedFields = void 0;
|
exports.AIOptions = exports.OpsActions = exports.TimeParadigms = exports.UserAPIAuthActions = exports.UserAPIParadigms = exports.TargetMediaParadigms = exports.EnvKeys = exports.AppVersions = exports.APIParadigms = exports.UserSQLPermissions = exports.SQLPermissions = exports.InvitedUserSelectFields = exports.DelegatedUserSelectFields = exports.UserSelectFields = exports.IndexTypes = exports.DefaultSQLValuesLiteral = exports.CurrentlyEditedFieldActions = exports.FileMimeTypes = exports.VideoMimeTypes = exports.ImageMimeTypes = exports.MediaTypes = exports.DockerComposeServices = exports.DatasquirelWindowEvents = exports.WebSocketEvents = exports.QueueJobTypes = exports.SignUpParadigms = exports.UserTypes = exports.QueryFields = exports.DsqlCrudActions = exports.DataCrudRequestMethodsLowerCase = exports.DataCrudRequestMethods = exports.ServerQueryEqualities = exports.ServerQueryOperators = exports.TextFieldTypesArray = exports.UsersOmitedFields = void 0;
|
||||||
exports.UsersOmitedFields = [
|
exports.UsersOmitedFields = [
|
||||||
"password",
|
"password",
|
||||||
"social_id",
|
"social_id",
|
||||||
@ -146,7 +146,10 @@ exports.ImageMimeTypes = [
|
|||||||
"jpeg",
|
"jpeg",
|
||||||
"jpg",
|
"jpg",
|
||||||
];
|
];
|
||||||
|
exports.VideoMimeTypes = ["mp4", "wav"];
|
||||||
exports.FileMimeTypes = [
|
exports.FileMimeTypes = [
|
||||||
|
...exports.ImageMimeTypes,
|
||||||
|
...exports.VideoMimeTypes,
|
||||||
"pdf",
|
"pdf",
|
||||||
"csv",
|
"csv",
|
||||||
"json",
|
"json",
|
||||||
@ -166,7 +169,6 @@ exports.FileMimeTypes = [
|
|||||||
"html",
|
"html",
|
||||||
"css",
|
"css",
|
||||||
];
|
];
|
||||||
exports.VideoMimeTypes = ["mp4", "wav"];
|
|
||||||
exports.CurrentlyEditedFieldActions = [
|
exports.CurrentlyEditedFieldActions = [
|
||||||
"edit-field",
|
"edit-field",
|
||||||
"edit-index",
|
"edit-index",
|
||||||
|
|||||||
@ -13,6 +13,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
exports.default = default_1;
|
exports.default = default_1;
|
||||||
|
const sql_formatter_1 = require("sql-formatter");
|
||||||
const sql_generator_1 = __importDefault(require("../../functions/dsql/sql/sql-generator"));
|
const sql_generator_1 = __importDefault(require("../../functions/dsql/sql/sql-generator"));
|
||||||
const conn_db_handler_1 = __importDefault(require("../db/conn-db-handler"));
|
const conn_db_handler_1 = __importDefault(require("../db/conn-db-handler"));
|
||||||
const check_array_depth_1 = __importDefault(require("../check-array-depth"));
|
const check_array_depth_1 = __importDefault(require("../check-array-depth"));
|
||||||
@ -78,11 +79,11 @@ function default_1(_a) {
|
|||||||
: undefined,
|
: undefined,
|
||||||
errors: res === null || res === void 0 ? void 0 : res.errors,
|
errors: res === null || res === void 0 ? void 0 : res.errors,
|
||||||
queryObject: {
|
queryObject: {
|
||||||
sql: queryObject === null || queryObject === void 0 ? void 0 : queryObject.string,
|
sql: (0, sql_formatter_1.format)((queryObject === null || queryObject === void 0 ? void 0 : queryObject.string) || "") || undefined,
|
||||||
params: queryObject === null || queryObject === void 0 ? void 0 : queryObject.values,
|
params: queryObject === null || queryObject === void 0 ? void 0 : queryObject.values,
|
||||||
},
|
},
|
||||||
countQueryObject: {
|
countQueryObject: {
|
||||||
sql: countQueryObject === null || countQueryObject === void 0 ? void 0 : countQueryObject.string,
|
sql: (0, sql_formatter_1.format)((countQueryObject === null || countQueryObject === void 0 ? void 0 : countQueryObject.string) || "") || undefined,
|
||||||
params: countQueryObject === null || countQueryObject === void 0 ? void 0 : countQueryObject.values,
|
params: countQueryObject === null || countQueryObject === void 0 ? void 0 : countQueryObject.values,
|
||||||
},
|
},
|
||||||
count: isSuccess
|
count: isSuccess
|
||||||
|
|||||||
@ -13,6 +13,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
exports.default = dsqlCrud;
|
exports.default = dsqlCrud;
|
||||||
|
const sql_formatter_1 = require("sql-formatter");
|
||||||
const sql_delete_generator_1 = __importDefault(require("../../functions/dsql/sql/sql-delete-generator"));
|
const sql_delete_generator_1 = __importDefault(require("../../functions/dsql/sql/sql-delete-generator"));
|
||||||
const crud_get_1 = __importDefault(require("./crud-get"));
|
const crud_get_1 = __importDefault(require("./crud-get"));
|
||||||
const conn_db_handler_1 = __importDefault(require("../db/conn-db-handler"));
|
const conn_db_handler_1 = __importDefault(require("../db/conn-db-handler"));
|
||||||
@ -73,7 +74,7 @@ function dsqlCrud(params) {
|
|||||||
success: Boolean(res.affectedRows),
|
success: Boolean(res.affectedRows),
|
||||||
payload: res,
|
payload: res,
|
||||||
queryObject: {
|
queryObject: {
|
||||||
sql: (deleteQuery === null || deleteQuery === void 0 ? void 0 : deleteQuery.query) || "",
|
sql: (0, sql_formatter_1.format)((deleteQuery === null || deleteQuery === void 0 ? void 0 : deleteQuery.query) || ""),
|
||||||
params: (deleteQuery === null || deleteQuery === void 0 ? void 0 : deleteQuery.values) || [],
|
params: (deleteQuery === null || deleteQuery === void 0 ? void 0 : deleteQuery.values) || [],
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
import { format } from "sql-formatter";
|
||||||
import updateDbEntry from "./updateDbEntry";
|
import updateDbEntry from "./updateDbEntry";
|
||||||
import _ from "lodash";
|
import _ from "lodash";
|
||||||
import connDbHandler from "../../../utils/db/conn-db-handler";
|
import connDbHandler from "../../../utils/db/conn-db-handler";
|
||||||
@ -276,7 +277,7 @@ export default async function addDbEntry<
|
|||||||
success: Boolean(newInsert?.insertId),
|
success: Boolean(newInsert?.insertId),
|
||||||
payload: newInsert,
|
payload: newInsert,
|
||||||
queryObject: {
|
queryObject: {
|
||||||
sql: query,
|
sql: format(query),
|
||||||
params: finalQueryValues,
|
params: finalQueryValues,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
import { format } from "sql-formatter";
|
||||||
import checkIfIsMaster from "../../../utils/check-if-is-master";
|
import checkIfIsMaster from "../../../utils/check-if-is-master";
|
||||||
import connDbHandler from "../../../utils/db/conn-db-handler";
|
import connDbHandler from "../../../utils/db/conn-db-handler";
|
||||||
import { DbContextsArray } from "./runQuery";
|
import { DbContextsArray } from "./runQuery";
|
||||||
@ -155,7 +156,7 @@ export default async function updateDbEntry<
|
|||||||
success: Boolean(updatedEntry?.affectedRows),
|
success: Boolean(updatedEntry?.affectedRows),
|
||||||
payload: updatedEntry,
|
payload: updatedEntry,
|
||||||
queryObject: {
|
queryObject: {
|
||||||
sql: query,
|
sql: format(query),
|
||||||
params: updateValues,
|
params: updateValues,
|
||||||
},
|
},
|
||||||
debug: debug ? { data, newData } : undefined,
|
debug: debug ? { data, newData } : undefined,
|
||||||
|
|||||||
@ -110,65 +110,11 @@ export default function sqlGenerator<
|
|||||||
} else if (operatorStrParam.str) {
|
} else if (operatorStrParam.str) {
|
||||||
str = operatorStrParam.str;
|
str = operatorStrParam.str;
|
||||||
}
|
}
|
||||||
|
|
||||||
// if (queryObj.equality == "LIKE") {
|
|
||||||
// str = `LOWER(${finalFieldName}) LIKE LOWER('%${valueParsed}%')`;
|
|
||||||
// } else if (queryObj.equality == "LIKE_RAW") {
|
|
||||||
// str = `LOWER(${finalFieldName}) LIKE LOWER(?)`;
|
|
||||||
// sqlSearhValues.push(valueParsed);
|
|
||||||
// } else if (queryObj.equality == "NOT LIKE") {
|
|
||||||
// str = `LOWER(${finalFieldName}) NOT LIKE LOWER('%${valueParsed}%')`;
|
|
||||||
// } else if (queryObj.equality == "NOT LIKE_RAW") {
|
|
||||||
// str = `LOWER(${finalFieldName}) NOT LIKE LOWER(?)`;
|
|
||||||
// sqlSearhValues.push(valueParsed);
|
|
||||||
// } else if (queryObj.equality == "REGEXP") {
|
|
||||||
// str = `LOWER(${finalFieldName}) REGEXP LOWER(?)`;
|
|
||||||
// sqlSearhValues.push(valueParsed);
|
|
||||||
// } else if (queryObj.equality == "FULLTEXT") {
|
|
||||||
// str = `MATCH(${finalFieldName}) AGAINST(? IN BOOLEAN MODE)`;
|
|
||||||
// sqlSearhValues.push(valueParsed);
|
|
||||||
// } else if (queryObj.equality == "NOT EQUAL") {
|
|
||||||
// str = `${finalFieldName} != ?`;
|
|
||||||
// sqlSearhValues.push(valueParsed);
|
|
||||||
// } else if (queryObj.equality) {
|
|
||||||
// str = `${finalFieldName} ${operator} ?`;
|
|
||||||
// sqlSearhValues.push(valueParsed);
|
|
||||||
// } else {
|
|
||||||
// sqlSearhValues.push(valueParsed);
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
const sqlSearhString = queryKeys?.map((field) => {
|
|
||||||
const queryObj = finalQuery?.[field];
|
|
||||||
if (!queryObj) return;
|
|
||||||
|
|
||||||
if (queryObj.__query) {
|
|
||||||
const subQueryGroup = queryObj.__query;
|
|
||||||
|
|
||||||
const subSearchKeys = Object.keys(subQueryGroup);
|
|
||||||
const subSearchString = subSearchKeys.map((_field) => {
|
|
||||||
const newSubQueryObj = subQueryGroup?.[_field];
|
|
||||||
|
|
||||||
return genSqlSrchStr({
|
|
||||||
queryObj: newSubQueryObj,
|
|
||||||
field: _field,
|
|
||||||
join: genObject?.join,
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
return (
|
|
||||||
"(" +
|
|
||||||
subSearchString.join(` ${queryObj.operator || "AND"} `) +
|
|
||||||
")"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return genSqlSrchStr({ queryObj, field, join: genObject?.join });
|
|
||||||
});
|
|
||||||
|
|
||||||
function generateJoinStr(
|
function generateJoinStr(
|
||||||
mtch: ServerQueryParamsJoinMatchObject,
|
mtch: ServerQueryParamsJoinMatchObject,
|
||||||
join: ServerQueryParamsJoin
|
join: ServerQueryParamsJoin
|
||||||
@ -239,6 +185,38 @@ export default function sqlGenerator<
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (genObject?.countSubQueries) {
|
||||||
|
let countSqls: string[] = [];
|
||||||
|
|
||||||
|
for (let i = 0; i < genObject.countSubQueries.length; i++) {
|
||||||
|
const countSubQuery = genObject.countSubQueries[i];
|
||||||
|
let subQStr = `(SELECT COUNT(*)`;
|
||||||
|
subQStr += ` FROM ${countSubQuery.table}`;
|
||||||
|
subQStr += ` WHERE (`;
|
||||||
|
|
||||||
|
for (let j = 0; j < countSubQuery.srcTrgMap.length; j++) {
|
||||||
|
const csqSrc = countSubQuery.srcTrgMap[j];
|
||||||
|
subQStr += ` ${countSubQuery.table}.${csqSrc.src}`;
|
||||||
|
|
||||||
|
if (typeof csqSrc.trg == "string") {
|
||||||
|
subQStr += ` = ?`;
|
||||||
|
sqlSearhValues.push(csqSrc.trg);
|
||||||
|
} else if (typeof csqSrc.trg == "object") {
|
||||||
|
subQStr += ` = ${csqSrc.trg.table}.${csqSrc.trg.field}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (j < countSubQuery.srcTrgMap.length - 1) {
|
||||||
|
subQStr += ` AND `;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
subQStr += ` )) AS ${countSubQuery.alias}`;
|
||||||
|
countSqls.push(subQStr);
|
||||||
|
}
|
||||||
|
|
||||||
|
str += `, ${countSqls.join(",")}`;
|
||||||
|
}
|
||||||
|
|
||||||
if (genObject?.join && !count) {
|
if (genObject?.join && !count) {
|
||||||
const existingJoinTableNames: string[] = [tableName];
|
const existingJoinTableNames: string[] = [tableName];
|
||||||
|
|
||||||
@ -320,6 +298,34 @@ export default function sqlGenerator<
|
|||||||
return str;
|
return str;
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
const sqlSearhString = queryKeys?.map((field) => {
|
||||||
|
const queryObj = finalQuery?.[field];
|
||||||
|
if (!queryObj) return;
|
||||||
|
|
||||||
|
if (queryObj.__query) {
|
||||||
|
const subQueryGroup = queryObj.__query;
|
||||||
|
|
||||||
|
const subSearchKeys = Object.keys(subQueryGroup);
|
||||||
|
const subSearchString = subSearchKeys.map((_field) => {
|
||||||
|
const newSubQueryObj = subQueryGroup?.[_field];
|
||||||
|
|
||||||
|
return genSqlSrchStr({
|
||||||
|
queryObj: newSubQueryObj,
|
||||||
|
field: _field,
|
||||||
|
join: genObject?.join,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
return (
|
||||||
|
"(" +
|
||||||
|
subSearchString.join(` ${queryObj.operator || "AND"} `) +
|
||||||
|
")"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return genSqlSrchStr({ queryObj, field, join: genObject?.join });
|
||||||
|
});
|
||||||
|
|
||||||
if (sqlSearhString?.[0] && sqlSearhString.find((str) => str)) {
|
if (sqlSearhString?.[0] && sqlSearhString.find((str) => str)) {
|
||||||
const stringOperator = genObject?.searchOperator || "AND";
|
const stringOperator = genObject?.searchOperator || "AND";
|
||||||
queryString += ` WHERE ${sqlSearhString.join(` ${stringOperator} `)}`;
|
queryString += ` WHERE ${sqlSearhString.join(` ${stringOperator} `)}`;
|
||||||
|
|||||||
@ -1012,9 +1012,24 @@ export type ServerQueryParam<
|
|||||||
};
|
};
|
||||||
join?: ServerQueryParamsJoin<K>[];
|
join?: ServerQueryParamsJoin<K>[];
|
||||||
group?: (keyof T)[];
|
group?: (keyof T)[];
|
||||||
|
countSubQueries?: ServerQueryParamsCount[];
|
||||||
[key: string]: any;
|
[key: string]: any;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type ServerQueryParamsCount = {
|
||||||
|
table: string;
|
||||||
|
srcTrgMap: {
|
||||||
|
src: string;
|
||||||
|
trg: string | ServerQueryParamsCountSrcTrgMap;
|
||||||
|
}[];
|
||||||
|
alias: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type ServerQueryParamsCountSrcTrgMap = {
|
||||||
|
table: string;
|
||||||
|
field: string;
|
||||||
|
};
|
||||||
|
|
||||||
export type TableSelectFieldsObject<
|
export type TableSelectFieldsObject<
|
||||||
T extends { [k: string]: any } = { [k: string]: any }
|
T extends { [k: string]: any } = { [k: string]: any }
|
||||||
> = {
|
> = {
|
||||||
@ -1858,7 +1873,11 @@ export const ImageMimeTypes: (keyof sharp.FormatEnum)[] = [
|
|||||||
"jpg",
|
"jpg",
|
||||||
] as const;
|
] as const;
|
||||||
|
|
||||||
|
export const VideoMimeTypes = ["mp4", "wav"] as const;
|
||||||
|
|
||||||
export const FileMimeTypes = [
|
export const FileMimeTypes = [
|
||||||
|
...ImageMimeTypes,
|
||||||
|
...VideoMimeTypes,
|
||||||
"pdf",
|
"pdf",
|
||||||
"csv",
|
"csv",
|
||||||
"json",
|
"json",
|
||||||
@ -1879,8 +1898,6 @@ export const FileMimeTypes = [
|
|||||||
"css",
|
"css",
|
||||||
] as const;
|
] as const;
|
||||||
|
|
||||||
export const VideoMimeTypes = ["mp4", "wav"] as const;
|
|
||||||
|
|
||||||
export const CurrentlyEditedFieldActions = [
|
export const CurrentlyEditedFieldActions = [
|
||||||
"edit-field",
|
"edit-field",
|
||||||
"edit-index",
|
"edit-index",
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
import { format } from "sql-formatter";
|
||||||
import sqlGenerator from "../../functions/dsql/sql/sql-generator";
|
import sqlGenerator from "../../functions/dsql/sql/sql-generator";
|
||||||
import { APIResponseObject, DsqlCrudParam } from "../../types";
|
import { APIResponseObject, DsqlCrudParam } from "../../types";
|
||||||
import connDbHandler, { ConnDBHandlerQueryObject } from "../db/conn-db-handler";
|
import connDbHandler, { ConnDBHandlerQueryObject } from "../db/conn-db-handler";
|
||||||
@ -85,11 +86,11 @@ export default async function <
|
|||||||
: undefined,
|
: undefined,
|
||||||
errors: res?.errors,
|
errors: res?.errors,
|
||||||
queryObject: {
|
queryObject: {
|
||||||
sql: queryObject?.string,
|
sql: format(queryObject?.string || "") || undefined,
|
||||||
params: queryObject?.values,
|
params: queryObject?.values,
|
||||||
},
|
},
|
||||||
countQueryObject: {
|
countQueryObject: {
|
||||||
sql: countQueryObject?.string,
|
sql: format(countQueryObject?.string || "") || undefined,
|
||||||
params: countQueryObject?.values,
|
params: countQueryObject?.values,
|
||||||
},
|
},
|
||||||
count: isSuccess
|
count: isSuccess
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
import { format } from "sql-formatter";
|
||||||
import sqlDeleteGenerator from "../../functions/dsql/sql/sql-delete-generator";
|
import sqlDeleteGenerator from "../../functions/dsql/sql/sql-delete-generator";
|
||||||
import {
|
import {
|
||||||
APIResponseObject,
|
APIResponseObject,
|
||||||
@ -94,7 +95,7 @@ export default async function dsqlCrud<
|
|||||||
success: Boolean(res.affectedRows),
|
success: Boolean(res.affectedRows),
|
||||||
payload: res,
|
payload: res,
|
||||||
queryObject: {
|
queryObject: {
|
||||||
sql: deleteQuery?.query || "",
|
sql: format(deleteQuery?.query || ""),
|
||||||
params: deleteQuery?.values || [],
|
params: deleteQuery?.values || [],
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@moduletrace/datasquirel",
|
"name": "@moduletrace/datasquirel",
|
||||||
"version": "5.4.3",
|
"version": "5.4.4",
|
||||||
"description": "Cloud-based SQL data management tool",
|
"description": "Cloud-based SQL data management tool",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"bin": {
|
"bin": {
|
||||||
@ -46,6 +46,7 @@
|
|||||||
"lodash": "^4.17.21",
|
"lodash": "^4.17.21",
|
||||||
"mariadb": "^3.4.4",
|
"mariadb": "^3.4.4",
|
||||||
"nodemailer": "^6.9.14",
|
"nodemailer": "^6.9.14",
|
||||||
"sanitize-html": "^2.13.1"
|
"sanitize-html": "^2.13.1",
|
||||||
|
"sql-formatter": "^15.6.10"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user