Updates
This commit is contained in:
parent
26a29ed741
commit
29fd6e6203
@ -14,15 +14,20 @@ function sqlGenerator({ tableName, genObject }) {
|
||||
|
||||
/** @type {string[]} */
|
||||
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 = (() => {
|
||||
if (queryObj?.tableName) {
|
||||
return `${queryObj.tableName}.${field}`;
|
||||
}
|
||||
if (genObject.join) {
|
||||
if (join) {
|
||||
return `${tableName}.${field}`;
|
||||
}
|
||||
return field;
|
||||
@ -66,6 +71,41 @@ function sqlGenerator({ tableName, genObject }) {
|
||||
}
|
||||
|
||||
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(
|
||||
|
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;
|
||||
};
|
||||
join?: ServerQueryParamsJoin[];
|
||||
} & {
|
||||
[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;
|
||||
}> = {
|
||||
[key in keyof T]: {
|
||||
value: string | string[];
|
||||
operator?: "AND" | "OR";
|
||||
equality?: "EQUAL" | "LIKE" | "NOT EQUAL";
|
||||
tableName?: string;
|
||||
};
|
||||
[key in keyof T]: ServerQueryObject<T>;
|
||||
};
|
||||
export type FetchDataParams = {
|
||||
path: string;
|
||||
|
@ -1101,18 +1101,22 @@ export type ServerQueryParam = {
|
||||
fieldName: string;
|
||||
};
|
||||
join?: ServerQueryParamsJoin[];
|
||||
} & {
|
||||
[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 }> =
|
||||
{
|
||||
[key in keyof T]: {
|
||||
value: string | string[];
|
||||
operator?: "AND" | "OR";
|
||||
equality?: "EQUAL" | "LIKE" | "NOT EQUAL";
|
||||
tableName?: string;
|
||||
};
|
||||
[key in keyof T]: ServerQueryObject<T>;
|
||||
};
|
||||
|
||||
export type FetchDataParams = {
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@moduletrace/datasquirel",
|
||||
"version": "3.2.5",
|
||||
"version": "3.2.6",
|
||||
"description": "Cloud-based SQL data management tool",
|
||||
"main": "index.js",
|
||||
"bin": {
|
||||
|
Loading…
Reference in New Issue
Block a user