Updates
This commit is contained in:
@@ -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: {
|
||||
|
||||
Reference in New Issue
Block a user