Updates
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { format } from "sql-formatter";
|
||||
import updateDbEntry from "./updateDbEntry";
|
||||
import _ from "lodash";
|
||||
import connDbHandler from "../../../utils/db/conn-db-handler";
|
||||
@@ -276,7 +277,7 @@ export default async function addDbEntry<
|
||||
success: Boolean(newInsert?.insertId),
|
||||
payload: newInsert,
|
||||
queryObject: {
|
||||
sql: query,
|
||||
sql: format(query),
|
||||
params: finalQueryValues,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { format } from "sql-formatter";
|
||||
import checkIfIsMaster from "../../../utils/check-if-is-master";
|
||||
import connDbHandler from "../../../utils/db/conn-db-handler";
|
||||
import { DbContextsArray } from "./runQuery";
|
||||
@@ -155,7 +156,7 @@ export default async function updateDbEntry<
|
||||
success: Boolean(updatedEntry?.affectedRows),
|
||||
payload: updatedEntry,
|
||||
queryObject: {
|
||||
sql: query,
|
||||
sql: format(query),
|
||||
params: updateValues,
|
||||
},
|
||||
debug: debug ? { data, newData } : undefined,
|
||||
|
||||
@@ -110,65 +110,11 @@ export default function sqlGenerator<
|
||||
} else if (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;
|
||||
}
|
||||
|
||||
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(
|
||||
mtch: ServerQueryParamsJoinMatchObject,
|
||||
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) {
|
||||
const existingJoinTableNames: string[] = [tableName];
|
||||
|
||||
@@ -320,6 +298,34 @@ export default function sqlGenerator<
|
||||
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)) {
|
||||
const stringOperator = genObject?.searchOperator || "AND";
|
||||
queryString += ` WHERE ${sqlSearhString.join(` ${stringOperator} `)}`;
|
||||
|
||||
@@ -1012,9 +1012,24 @@ export type ServerQueryParam<
|
||||
};
|
||||
join?: ServerQueryParamsJoin<K>[];
|
||||
group?: (keyof T)[];
|
||||
countSubQueries?: ServerQueryParamsCount[];
|
||||
[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 { [k: string]: any } = { [k: string]: any }
|
||||
> = {
|
||||
@@ -1858,7 +1873,11 @@ export const ImageMimeTypes: (keyof sharp.FormatEnum)[] = [
|
||||
"jpg",
|
||||
] as const;
|
||||
|
||||
export const VideoMimeTypes = ["mp4", "wav"] as const;
|
||||
|
||||
export const FileMimeTypes = [
|
||||
...ImageMimeTypes,
|
||||
...VideoMimeTypes,
|
||||
"pdf",
|
||||
"csv",
|
||||
"json",
|
||||
@@ -1879,8 +1898,6 @@ export const FileMimeTypes = [
|
||||
"css",
|
||||
] as const;
|
||||
|
||||
export const VideoMimeTypes = ["mp4", "wav"] as const;
|
||||
|
||||
export const CurrentlyEditedFieldActions = [
|
||||
"edit-field",
|
||||
"edit-index",
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { format } from "sql-formatter";
|
||||
import sqlGenerator from "../../functions/dsql/sql/sql-generator";
|
||||
import { APIResponseObject, DsqlCrudParam } from "../../types";
|
||||
import connDbHandler, { ConnDBHandlerQueryObject } from "../db/conn-db-handler";
|
||||
@@ -85,11 +86,11 @@ export default async function <
|
||||
: undefined,
|
||||
errors: res?.errors,
|
||||
queryObject: {
|
||||
sql: queryObject?.string,
|
||||
sql: format(queryObject?.string || "") || undefined,
|
||||
params: queryObject?.values,
|
||||
},
|
||||
countQueryObject: {
|
||||
sql: countQueryObject?.string,
|
||||
sql: format(countQueryObject?.string || "") || undefined,
|
||||
params: countQueryObject?.values,
|
||||
},
|
||||
count: isSuccess
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { format } from "sql-formatter";
|
||||
import sqlDeleteGenerator from "../../functions/dsql/sql/sql-delete-generator";
|
||||
import {
|
||||
APIResponseObject,
|
||||
@@ -94,7 +95,7 @@ export default async function dsqlCrud<
|
||||
success: Boolean(res.affectedRows),
|
||||
payload: res,
|
||||
queryObject: {
|
||||
sql: deleteQuery?.query || "",
|
||||
sql: format(deleteQuery?.query || ""),
|
||||
params: deleteQuery?.values || [],
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user