Updates
This commit is contained in:
parent
7959014721
commit
672e011cd8
@ -99,6 +99,17 @@ function sqlGenerator({ tableName, genObject, dbFullName, count }) {
|
||||
: mtch.target}`;
|
||||
})()}`;
|
||||
}
|
||||
let fullTextMatchStr = (genObject === null || genObject === void 0 ? void 0 : genObject.fullTextSearch)
|
||||
? ` MATCH(${genObject.fullTextSearch.fields
|
||||
.map((f) => (genObject.join ? `${tableName}.${f}` : `${f}`))
|
||||
.join(",")}) AGAINST (?)`
|
||||
: undefined;
|
||||
const fullTextSearchStr = (genObject === null || genObject === void 0 ? void 0 : genObject.fullTextSearch)
|
||||
? genObject.fullTextSearch.searchTerm
|
||||
.split(` `)
|
||||
.map((t) => `${t}`)
|
||||
.join(" ")
|
||||
: undefined;
|
||||
let queryString = (() => {
|
||||
var _a, _b, _c;
|
||||
let str = "SELECT";
|
||||
@ -189,6 +200,12 @@ function sqlGenerator({ tableName, genObject, dbFullName, count }) {
|
||||
.filter((_) => Boolean(_))
|
||||
.join(",");
|
||||
}
|
||||
if ((genObject === null || genObject === void 0 ? void 0 : genObject.fullTextSearch) &&
|
||||
fullTextMatchStr &&
|
||||
fullTextSearchStr) {
|
||||
str += `, ${fullTextMatchStr} AS ${genObject.fullTextSearch.scoreAlias}`;
|
||||
sqlSearhValues.push(fullTextSearchStr);
|
||||
}
|
||||
str += ` FROM ${finalDbName}${tableName}`;
|
||||
if (genObject === null || genObject === void 0 ? void 0 : genObject.join) {
|
||||
str +=
|
||||
@ -247,15 +264,24 @@ function sqlGenerator({ tableName, genObject, dbFullName, count }) {
|
||||
const stringOperator = (genObject === null || genObject === void 0 ? void 0 : genObject.searchOperator) || "AND";
|
||||
queryString += ` WHERE ${sqlSearhString.join(` ${stringOperator} `)}`;
|
||||
}
|
||||
else if ((genObject === null || genObject === void 0 ? void 0 : genObject.fullTextSearch) &&
|
||||
fullTextSearchStr &&
|
||||
fullTextMatchStr) {
|
||||
queryString += ` WHERE ${fullTextMatchStr}`;
|
||||
sqlSearhValues.push(fullTextSearchStr);
|
||||
}
|
||||
if ((_a = genObject === null || genObject === void 0 ? void 0 : genObject.group) === null || _a === void 0 ? void 0 : _a[0]) {
|
||||
queryString += ` GROUP BY ${genObject.group
|
||||
.map((g) => `\`${g.toString()}\``)
|
||||
.join(",")}`;
|
||||
}
|
||||
if ((genObject === null || genObject === void 0 ? void 0 : genObject.order) && !count) {
|
||||
queryString += ` ORDER BY ${genObject.join
|
||||
? `${finalDbName}${tableName}.${String(genObject.order.field)}`
|
||||
: String(genObject.order.field)} ${genObject.order.strategy}`;
|
||||
queryString += ` ORDER BY ${(genObject === null || genObject === void 0 ? void 0 : genObject.fullTextSearch) &&
|
||||
genObject.fullTextSearch.scoreAlias == genObject.order.field
|
||||
? `${genObject.fullTextSearch.scoreAlias}`
|
||||
: genObject.join
|
||||
? `${finalDbName}${tableName}.${String(genObject.order.field)}`
|
||||
: String(genObject.order.field)} ${genObject.order.strategy}`;
|
||||
}
|
||||
if ((genObject === null || genObject === void 0 ? void 0 : genObject.limit) && !count)
|
||||
queryString += ` LIMIT ${genObject.limit}`;
|
||||
|
||||
7
dist/package-shared/types/index.d.ts
vendored
7
dist/package-shared/types/index.d.ts
vendored
@ -828,8 +828,15 @@ export type ServerQueryParam<T extends {
|
||||
join?: ServerQueryParamsJoin<K>[];
|
||||
group?: (keyof T)[];
|
||||
countSubQueries?: ServerQueryParamsCount[];
|
||||
fullTextSearch?: ServerQueryParamFullTextSearch;
|
||||
[key: string]: any;
|
||||
};
|
||||
export type ServerQueryParamFullTextSearch = {
|
||||
fields: string[];
|
||||
searchTerm: string;
|
||||
/** Field Name to user to Rank the Score of Search Results */
|
||||
scoreAlias: string;
|
||||
};
|
||||
export type ServerQueryParamsCount = {
|
||||
table: string;
|
||||
srcTrgMap: {
|
||||
|
||||
@ -152,6 +152,19 @@ export default function sqlGenerator<
|
||||
})()}`;
|
||||
}
|
||||
|
||||
let fullTextMatchStr = genObject?.fullTextSearch
|
||||
? ` MATCH(${genObject.fullTextSearch.fields
|
||||
.map((f) => (genObject.join ? `${tableName}.${f}` : `${f}`))
|
||||
.join(",")}) AGAINST (?)`
|
||||
: undefined;
|
||||
|
||||
const fullTextSearchStr = genObject?.fullTextSearch
|
||||
? genObject.fullTextSearch.searchTerm
|
||||
.split(` `)
|
||||
.map((t) => `${t}`)
|
||||
.join(" ")
|
||||
: undefined;
|
||||
|
||||
let queryString = (() => {
|
||||
let str = "SELECT";
|
||||
|
||||
@ -255,6 +268,15 @@ export default function sqlGenerator<
|
||||
.join(",");
|
||||
}
|
||||
|
||||
if (
|
||||
genObject?.fullTextSearch &&
|
||||
fullTextMatchStr &&
|
||||
fullTextSearchStr
|
||||
) {
|
||||
str += `, ${fullTextMatchStr} AS ${genObject.fullTextSearch.scoreAlias}`;
|
||||
sqlSearhValues.push(fullTextSearchStr);
|
||||
}
|
||||
|
||||
str += ` FROM ${finalDbName}${tableName}`;
|
||||
|
||||
if (genObject?.join) {
|
||||
@ -329,6 +351,13 @@ export default function sqlGenerator<
|
||||
if (sqlSearhString?.[0] && sqlSearhString.find((str) => str)) {
|
||||
const stringOperator = genObject?.searchOperator || "AND";
|
||||
queryString += ` WHERE ${sqlSearhString.join(` ${stringOperator} `)}`;
|
||||
} else if (
|
||||
genObject?.fullTextSearch &&
|
||||
fullTextSearchStr &&
|
||||
fullTextMatchStr
|
||||
) {
|
||||
queryString += ` WHERE ${fullTextMatchStr}`;
|
||||
sqlSearhValues.push(fullTextSearchStr);
|
||||
}
|
||||
|
||||
if (genObject?.group?.[0]) {
|
||||
@ -339,7 +368,10 @@ export default function sqlGenerator<
|
||||
|
||||
if (genObject?.order && !count) {
|
||||
queryString += ` ORDER BY ${
|
||||
genObject.join
|
||||
genObject?.fullTextSearch &&
|
||||
genObject.fullTextSearch.scoreAlias == genObject.order.field
|
||||
? `${genObject.fullTextSearch.scoreAlias}`
|
||||
: genObject.join
|
||||
? `${finalDbName}${tableName}.${String(genObject.order.field)}`
|
||||
: String(genObject.order.field)
|
||||
} ${genObject.order.strategy}`;
|
||||
|
||||
@ -1013,9 +1013,17 @@ export type ServerQueryParam<
|
||||
join?: ServerQueryParamsJoin<K>[];
|
||||
group?: (keyof T)[];
|
||||
countSubQueries?: ServerQueryParamsCount[];
|
||||
fullTextSearch?: ServerQueryParamFullTextSearch;
|
||||
[key: string]: any;
|
||||
};
|
||||
|
||||
export type ServerQueryParamFullTextSearch = {
|
||||
fields: string[];
|
||||
searchTerm: string;
|
||||
/** Field Name to user to Rank the Score of Search Results */
|
||||
scoreAlias: string;
|
||||
};
|
||||
|
||||
export type ServerQueryParamsCount = {
|
||||
table: string;
|
||||
srcTrgMap: {
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@moduletrace/datasquirel",
|
||||
"version": "5.4.4",
|
||||
"version": "5.4.5",
|
||||
"description": "Cloud-based SQL data management tool",
|
||||
"main": "dist/index.js",
|
||||
"bin": {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user