Updates
This commit is contained in:
parent
a2ba913340
commit
d627655422
@ -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)) {
|
||||
|
1
package-shared/types/index.d.ts
vendored
1
package-shared/types/index.d.ts
vendored
@ -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>
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@moduletrace/datasquirel",
|
||||
"version": "3.1.7",
|
||||
"version": "3.1.8",
|
||||
"description": "Cloud-based SQL data management tool",
|
||||
"main": "index.js",
|
||||
"bin": {
|
||||
|
Loading…
Reference in New Issue
Block a user