Updates
This commit is contained in:
@@ -74,6 +74,8 @@ function sqlGenerator({ tableName, genObject }) {
|
||||
return `'${mtch.targetLiteral}'`;
|
||||
}
|
||||
|
||||
if (join.alias) return `${join.alias}.${mtch.target}`;
|
||||
|
||||
return `${
|
||||
typeof mtch.target == "object"
|
||||
? mtch.target.tableName
|
||||
@@ -112,17 +114,21 @@ function sqlGenerator({ tableName, genObject }) {
|
||||
"," +
|
||||
genObject.join
|
||||
.map((joinObj) => {
|
||||
if (existingJoinTableNames.includes(joinObj.tableName))
|
||||
const joinTableName = joinObj.alias
|
||||
? joinObj.alias
|
||||
: joinObj.tableName;
|
||||
|
||||
if (existingJoinTableNames.includes(joinTableName))
|
||||
return null;
|
||||
existingJoinTableNames.push(joinObj.tableName);
|
||||
existingJoinTableNames.push(joinTableName);
|
||||
|
||||
if (joinObj.selectFields) {
|
||||
return joinObj.selectFields
|
||||
.map((slFld) => {
|
||||
if (typeof slFld == "string") {
|
||||
return `${joinObj.tableName}.${slFld}`;
|
||||
return `${joinTableName}.${slFld}`;
|
||||
} else if (typeof slFld == "object") {
|
||||
let aliasSlctFld = `${joinObj.tableName}.${slFld.field}`;
|
||||
let aliasSlctFld = `${joinTableName}.${slFld.field}`;
|
||||
if (slFld.alias)
|
||||
aliasSlctFld += ` as ${slFld.alias}`;
|
||||
return aliasSlctFld;
|
||||
@@ -130,7 +136,7 @@ function sqlGenerator({ tableName, genObject }) {
|
||||
})
|
||||
.join(",");
|
||||
} else {
|
||||
return `${joinObj.tableName}.*`;
|
||||
return `${joinTableName}.*`;
|
||||
}
|
||||
})
|
||||
.filter((_) => Boolean(_))
|
||||
@@ -147,7 +153,9 @@ function sqlGenerator({ tableName, genObject }) {
|
||||
return (
|
||||
join.joinType +
|
||||
" " +
|
||||
join.tableName +
|
||||
(join.alias
|
||||
? join.tableName + " AS " + join.alias
|
||||
: join.tableName) +
|
||||
" ON " +
|
||||
(() => {
|
||||
if (Array.isArray(join.match)) {
|
||||
|
||||
Vendored
+1
@@ -949,6 +949,7 @@ export type ServerQueryParamsJoin<Table extends string = string, Field extends o
|
||||
[key: string]: any;
|
||||
}> = {
|
||||
joinType: "INNER JOIN" | "JOIN" | "LEFT JOIN" | "RIGHT JOIN";
|
||||
alias?: string;
|
||||
tableName: Table;
|
||||
match?: ServerQueryParamsJoinMatchObject<Field> | ServerQueryParamsJoinMatchObject<Field>[];
|
||||
selectFields?: (keyof Field | {
|
||||
|
||||
@@ -1131,6 +1131,7 @@ export type ServerQueryParamsJoin<
|
||||
Field extends object = { [key: string]: any }
|
||||
> = {
|
||||
joinType: "INNER JOIN" | "JOIN" | "LEFT JOIN" | "RIGHT JOIN";
|
||||
alias?: string;
|
||||
tableName: Table;
|
||||
match?:
|
||||
| ServerQueryParamsJoinMatchObject<Field>
|
||||
|
||||
Reference in New Issue
Block a user