@ts-safeql/generate
Advanced tools
Comparing version 3.0.0-next.4 to 3.0.0
@@ -31,3 +31,6 @@ "use strict"; | ||
} | ||
return resolveColumn(columnSource.column); | ||
const resolved = columnSource.source.kind === "table" && columnSource.source.alias !== undefined | ||
? resolveColumn(Object.assign(Object.assign({}, columnSource.column), { tableName: columnSource.source.alias })) | ||
: resolveColumn(columnSource.column); | ||
return resolved; | ||
} | ||
@@ -54,3 +57,3 @@ function getColumnsByTargetField(field) { | ||
function checkIsNullableDueToRelation(column) { | ||
const findByJoin = relations.find((x) => x.joinRelName === column.tableName); | ||
const findByJoin = relations.find((x) => { var _a; return ((_a = x.alias) !== null && _a !== void 0 ? _a : x.joinRelName) === column.tableName; }); | ||
if (findByJoin !== undefined) { | ||
@@ -57,0 +60,0 @@ switch (findByJoin.joinType) { |
@@ -989,2 +989,26 @@ "use strict"; | ||
}); | ||
(0, mocha_1.test)("select tbl with left join of self tbl", async () => { | ||
await testQuery({ | ||
query: ` | ||
SELECT | ||
caregiver.id as caregiver_id, | ||
self.id as self_id | ||
FROM caregiver | ||
LEFT JOIN caregiver self ON caregiver.id = self.id | ||
`, | ||
expected: [ | ||
["caregiver_id", { kind: "type", value: "number" }], | ||
[ | ||
"self_id", | ||
{ | ||
kind: "union", | ||
value: [ | ||
{ kind: "type", value: "number" }, | ||
{ kind: "type", value: "null" }, | ||
], | ||
}, | ||
], | ||
], | ||
}); | ||
}); | ||
//# sourceMappingURL=generate.test.js.map |
@@ -21,15 +21,16 @@ "use strict"; | ||
function recursiveTraverseJoins(joins, joinExpr) { | ||
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q; | ||
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t; | ||
const joinName = (_c = (_b = (_a = joinExpr.rarg) === null || _a === void 0 ? void 0 : _a.RangeVar) === null || _b === void 0 ? void 0 : _b.relname) !== null && _c !== void 0 ? _c : (_f = (_e = (_d = joinExpr.rarg) === null || _d === void 0 ? void 0 : _d.RangeSubselect) === null || _e === void 0 ? void 0 : _e.alias) === null || _f === void 0 ? void 0 : _f.aliasname; | ||
const aliasName = (_j = (_h = (_g = joinExpr.rarg) === null || _g === void 0 ? void 0 : _g.RangeVar) === null || _h === void 0 ? void 0 : _h.alias) === null || _j === void 0 ? void 0 : _j.aliasname; | ||
if (joinName === undefined) { | ||
throw new Error("joinName is undefined"); | ||
} | ||
const join = { type: joinExpr.jointype, name: joinName }; | ||
if (((_g = joinExpr.larg) === null || _g === void 0 ? void 0 : _g.JoinExpr) !== undefined) { | ||
return recursiveTraverseJoins([join, ...joins], (_h = joinExpr.larg) === null || _h === void 0 ? void 0 : _h.JoinExpr); | ||
const join = { type: joinExpr.jointype, name: joinName, alias: aliasName }; | ||
if (((_k = joinExpr.larg) === null || _k === void 0 ? void 0 : _k.JoinExpr) !== undefined) { | ||
return recursiveTraverseJoins([join, ...joins], (_l = joinExpr.larg) === null || _l === void 0 ? void 0 : _l.JoinExpr); | ||
} | ||
if (((_j = joinExpr.rarg) === null || _j === void 0 ? void 0 : _j.JoinExpr) !== undefined) { | ||
return recursiveTraverseJoins([join, ...joins], (_k = joinExpr.rarg) === null || _k === void 0 ? void 0 : _k.JoinExpr); | ||
if (((_m = joinExpr.rarg) === null || _m === void 0 ? void 0 : _m.JoinExpr) !== undefined) { | ||
return recursiveTraverseJoins([join, ...joins], (_o = joinExpr.rarg) === null || _o === void 0 ? void 0 : _o.JoinExpr); | ||
} | ||
const relName = (_o = (_m = (_l = joinExpr.larg) === null || _l === void 0 ? void 0 : _l.RangeVar) === null || _m === void 0 ? void 0 : _m.relname) !== null && _o !== void 0 ? _o : (_q = (_p = joinExpr.rarg) === null || _p === void 0 ? void 0 : _p.RangeVar) === null || _q === void 0 ? void 0 : _q.relname; | ||
const relName = (_r = (_q = (_p = joinExpr.larg) === null || _p === void 0 ? void 0 : _p.RangeVar) === null || _q === void 0 ? void 0 : _q.relname) !== null && _r !== void 0 ? _r : (_t = (_s = joinExpr.rarg) === null || _s === void 0 ? void 0 : _s.RangeVar) === null || _t === void 0 ? void 0 : _t.relname; | ||
if (relName === undefined) { | ||
@@ -44,3 +45,3 @@ throw new Error("relName is undefined"); | ||
joins.forEach((join) => { | ||
result.push({ relName, joinType: join.type, joinRelName: join.name }); | ||
result.push({ relName, joinType: join.type, joinRelName: join.name, alias: join.alias }); | ||
}); | ||
@@ -47,0 +48,0 @@ }); |
@@ -29,3 +29,5 @@ "use strict"; | ||
`, | ||
expected: [["caregiver", [{ name: "agency", type: shared_1.LibPgQueryAST.JoinType.JOIN_LEFT }]]], | ||
expected: [ | ||
["caregiver", [{ alias: undefined, name: "agency", type: shared_1.LibPgQueryAST.JoinType.JOIN_LEFT }]], | ||
], | ||
}, | ||
@@ -45,4 +47,4 @@ { | ||
[ | ||
{ name: "caregiver_agency", type: shared_1.LibPgQueryAST.JoinType.JOIN_LEFT }, | ||
{ name: "agency", type: shared_1.LibPgQueryAST.JoinType.JOIN_LEFT }, | ||
{ alias: undefined, name: "caregiver_agency", type: shared_1.LibPgQueryAST.JoinType.JOIN_LEFT }, | ||
{ alias: undefined, name: "agency", type: shared_1.LibPgQueryAST.JoinType.JOIN_LEFT }, | ||
], | ||
@@ -73,6 +75,6 @@ ], | ||
[ | ||
{ name: "w", type: shared_1.LibPgQueryAST.JoinType.JOIN_FULL }, | ||
{ name: "x", type: shared_1.LibPgQueryAST.JoinType.JOIN_INNER }, | ||
{ name: "y", type: shared_1.LibPgQueryAST.JoinType.JOIN_LEFT }, | ||
{ name: "z", type: shared_1.LibPgQueryAST.JoinType.JOIN_RIGHT }, | ||
{ alias: undefined, name: "w", type: shared_1.LibPgQueryAST.JoinType.JOIN_FULL }, | ||
{ alias: undefined, name: "x", type: shared_1.LibPgQueryAST.JoinType.JOIN_INNER }, | ||
{ alias: undefined, name: "y", type: shared_1.LibPgQueryAST.JoinType.JOIN_LEFT }, | ||
{ alias: undefined, name: "z", type: shared_1.LibPgQueryAST.JoinType.JOIN_RIGHT }, | ||
], | ||
@@ -83,6 +85,6 @@ ], | ||
[ | ||
{ name: "w", type: shared_1.LibPgQueryAST.JoinType.JOIN_FULL }, | ||
{ name: "x", type: shared_1.LibPgQueryAST.JoinType.JOIN_INNER }, | ||
{ name: "y", type: shared_1.LibPgQueryAST.JoinType.JOIN_LEFT }, | ||
{ name: "z", type: shared_1.LibPgQueryAST.JoinType.JOIN_RIGHT }, | ||
{ alias: undefined, name: "w", type: shared_1.LibPgQueryAST.JoinType.JOIN_FULL }, | ||
{ alias: undefined, name: "x", type: shared_1.LibPgQueryAST.JoinType.JOIN_INNER }, | ||
{ alias: undefined, name: "y", type: shared_1.LibPgQueryAST.JoinType.JOIN_LEFT }, | ||
{ alias: undefined, name: "z", type: shared_1.LibPgQueryAST.JoinType.JOIN_RIGHT }, | ||
], | ||
@@ -104,5 +106,5 @@ ], | ||
[ | ||
{ name: "subselect1", type: shared_1.LibPgQueryAST.JoinType.JOIN_LEFT }, | ||
{ name: "subselect2", type: shared_1.LibPgQueryAST.JoinType.JOIN_LEFT }, | ||
{ name: "subselect3", type: shared_1.LibPgQueryAST.JoinType.JOIN_LEFT }, | ||
{ alias: undefined, name: "subselect1", type: shared_1.LibPgQueryAST.JoinType.JOIN_LEFT }, | ||
{ alias: undefined, name: "subselect2", type: shared_1.LibPgQueryAST.JoinType.JOIN_LEFT }, | ||
{ alias: undefined, name: "subselect3", type: shared_1.LibPgQueryAST.JoinType.JOIN_LEFT }, | ||
], | ||
@@ -109,0 +111,0 @@ ], |
{ | ||
"name": "@ts-safeql/generate", | ||
"version": "3.0.0-next.4", | ||
"version": "3.0.0", | ||
"description": "", | ||
@@ -25,4 +25,4 @@ "main": "lib/index.js", | ||
"dependencies": { | ||
"@ts-safeql/shared": "3.0.0-next.4", | ||
"@ts-safeql/test-utils": "0.0.13-next.4", | ||
"@ts-safeql/shared": "3.0.0", | ||
"@ts-safeql/test-utils": "0.0.13", | ||
"fp-ts": "^2.13.1", | ||
@@ -29,0 +29,0 @@ "pg-connection-string": "^2.5.0", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
35
1
190995
2779
+ Added@ts-safeql/shared@3.0.0(transitive)
+ Added@ts-safeql/test-utils@0.0.13(transitive)
- Removed@ts-safeql/shared@3.0.0-next.4(transitive)
- Removed@ts-safeql/test-utils@0.0.13-next.4(transitive)
Updated@ts-safeql/shared@3.0.0
Updated@ts-safeql/test-utils@0.0.13