Updates
This commit is contained in:
parent
26a29ed741
commit
29fd6e6203
@ -14,15 +14,20 @@ function sqlGenerator({ tableName, genObject }) {
|
|||||||
|
|
||||||
/** @type {string[]} */
|
/** @type {string[]} */
|
||||||
const sqlSearhValues = [];
|
const sqlSearhValues = [];
|
||||||
const sqlSearhString = queryKeys?.map((field) => {
|
|
||||||
const queryObj = finalQuery?.[field];
|
|
||||||
if (!queryObj) return;
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* # Generate Query
|
||||||
|
* @param {object} param
|
||||||
|
* @param {import("../../../types").ServerQueryQueryObject[string]} param.queryObj
|
||||||
|
* @param {import("../../../types").ServerQueryParamsJoin[]} [param.join]
|
||||||
|
* @param {string} [param.field]
|
||||||
|
*/
|
||||||
|
function genSqlSrchStr({ queryObj, join, field }) {
|
||||||
const finalFieldName = (() => {
|
const finalFieldName = (() => {
|
||||||
if (queryObj?.tableName) {
|
if (queryObj?.tableName) {
|
||||||
return `${queryObj.tableName}.${field}`;
|
return `${queryObj.tableName}.${field}`;
|
||||||
}
|
}
|
||||||
if (genObject.join) {
|
if (join) {
|
||||||
return `${tableName}.${field}`;
|
return `${tableName}.${field}`;
|
||||||
}
|
}
|
||||||
return field;
|
return field;
|
||||||
@ -66,6 +71,41 @@ function sqlGenerator({ tableName, genObject }) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return str;
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
|
const sqlSearhString = queryKeys?.map((field) => {
|
||||||
|
const queryObj =
|
||||||
|
/** @type {import("../../../types").ServerQueryQueryObject} */ (
|
||||||
|
finalQuery?.[field]
|
||||||
|
);
|
||||||
|
if (!queryObj) return;
|
||||||
|
|
||||||
|
if (queryObj.__query) {
|
||||||
|
const subQueryGroup =
|
||||||
|
/** @type {import("../../../types").ServerQueryQueryObject}} */ (
|
||||||
|
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,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
console.log("queryObj.operator", queryObj.operator);
|
||||||
|
|
||||||
|
return (
|
||||||
|
"(" +
|
||||||
|
subSearchString.join(` ${queryObj.operator || "AND"} `) +
|
||||||
|
")"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return genSqlSrchStr({ queryObj, field, join: genObject.join });
|
||||||
});
|
});
|
||||||
|
|
||||||
function generateJoinStr(
|
function generateJoinStr(
|
||||||
|
19
package-shared/types/index.d.ts
vendored
19
package-shared/types/index.d.ts
vendored
@ -923,18 +923,23 @@ export type ServerQueryParam = {
|
|||||||
fieldName: string;
|
fieldName: string;
|
||||||
};
|
};
|
||||||
join?: ServerQueryParamsJoin[];
|
join?: ServerQueryParamsJoin[];
|
||||||
} & {
|
|
||||||
[key: string]: any;
|
[key: string]: any;
|
||||||
};
|
};
|
||||||
|
export type ServerQueryObject<T extends object = {
|
||||||
|
[key: string]: any;
|
||||||
|
}> = {
|
||||||
|
value?: string | string[];
|
||||||
|
operator?: "AND" | "OR";
|
||||||
|
equality?: "EQUAL" | "LIKE" | "NOT EQUAL";
|
||||||
|
tableName?: string;
|
||||||
|
__query?: {
|
||||||
|
[key in keyof T]: Omit<ServerQueryObject<T>, "__query">;
|
||||||
|
};
|
||||||
|
};
|
||||||
export type ServerQueryQueryObject<T extends object = {
|
export type ServerQueryQueryObject<T extends object = {
|
||||||
[key: string]: any;
|
[key: string]: any;
|
||||||
}> = {
|
}> = {
|
||||||
[key in keyof T]: {
|
[key in keyof T]: ServerQueryObject<T>;
|
||||||
value: string | string[];
|
|
||||||
operator?: "AND" | "OR";
|
|
||||||
equality?: "EQUAL" | "LIKE" | "NOT EQUAL";
|
|
||||||
tableName?: string;
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
export type FetchDataParams = {
|
export type FetchDataParams = {
|
||||||
path: string;
|
path: string;
|
||||||
|
@ -1101,18 +1101,22 @@ export type ServerQueryParam = {
|
|||||||
fieldName: string;
|
fieldName: string;
|
||||||
};
|
};
|
||||||
join?: ServerQueryParamsJoin[];
|
join?: ServerQueryParamsJoin[];
|
||||||
} & {
|
|
||||||
[key: string]: any;
|
[key: string]: any;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type ServerQueryObject<T extends object = { [key: string]: any }> = {
|
||||||
|
value?: string | string[];
|
||||||
|
operator?: "AND" | "OR";
|
||||||
|
equality?: "EQUAL" | "LIKE" | "NOT EQUAL";
|
||||||
|
tableName?: string;
|
||||||
|
__query?: {
|
||||||
|
[key in keyof T]: Omit<ServerQueryObject<T>, "__query">;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
export type ServerQueryQueryObject<T extends object = { [key: string]: any }> =
|
export type ServerQueryQueryObject<T extends object = { [key: string]: any }> =
|
||||||
{
|
{
|
||||||
[key in keyof T]: {
|
[key in keyof T]: ServerQueryObject<T>;
|
||||||
value: string | string[];
|
|
||||||
operator?: "AND" | "OR";
|
|
||||||
equality?: "EQUAL" | "LIKE" | "NOT EQUAL";
|
|
||||||
tableName?: string;
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export type FetchDataParams = {
|
export type FetchDataParams = {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@moduletrace/datasquirel",
|
"name": "@moduletrace/datasquirel",
|
||||||
"version": "3.2.5",
|
"version": "3.2.6",
|
||||||
"description": "Cloud-based SQL data management tool",
|
"description": "Cloud-based SQL data management tool",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"bin": {
|
"bin": {
|
||||||
|
Loading…
Reference in New Issue
Block a user