@rdyl/node-mysql 0.3.0 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1 -1
- package/dist/helper.js +4 -7
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/dist/helper.js
CHANGED
|
@@ -99,20 +99,17 @@ var BaseHelper = /** @class */ (function () {
|
|
|
99
99
|
var item = _this.related[n];
|
|
100
100
|
// @ts-ignore
|
|
101
101
|
var _a = (global.$MysqlTable[item.table] || {}).fields, fields = _a === void 0 ? [] : _a;
|
|
102
|
+
var fieldsSql = "\n".concat(fields.map(function (e) { return "".concat(e, ", ").concat(item.table, ".").concat(e); }).join(",\n"), "\n");
|
|
102
103
|
if (item.isArray) {
|
|
103
|
-
sqlList.push("COALESCE(\n (\n SELECT JSON_ARRAYAGG(\n JSON_OBJECT(".concat(
|
|
104
|
-
.map(function (e) { return "".concat(e, ": ").concat(item.table, ".").concat(e); })
|
|
105
|
-
.join(","), ")\n )\n FROM ").concat(item.relatedTable, "\n JOIN ").concat(item.table, " ON ").concat(item.table, ".id = ").concat(item.relatedTable, ".").concat(item.table, "_id\n WHERE ").concat(item.relatedTable, ".").concat(_this.table, "_id = ").concat(_this.table, ".id\n LIMIT 1\n ),\n JSON_ARRAY()\n) AS ").concat(item.table));
|
|
104
|
+
sqlList.push("COALESCE(\n (\n SELECT JSON_ARRAYAGG(\n JSON_OBJECT(".concat(fieldsSql, ")\n )\n FROM ").concat(item.relatedTable, "\n JOIN ").concat(item.table, " ON ").concat(item.table, ".id = ").concat(item.relatedTable, ".").concat(item.table, "_id\n WHERE ").concat(item.relatedTable, ".").concat(_this.table, "_id = ").concat(_this.table, ".id\n ),\n JSON_ARRAY()\n) AS ").concat(item.table));
|
|
106
105
|
}
|
|
107
106
|
else {
|
|
108
|
-
sqlList.push("COALESCE(\n (\n SELECT JSON_OBJECT(".concat(
|
|
109
|
-
.map(function (e) { return "".concat(e, ": ").concat(item.table, ".").concat(e); })
|
|
110
|
-
.join(","), ")\n FROM ").concat(item.relatedTable, "\n JOIN ").concat(item.table, " ON ").concat(item.table, ".id = ").concat(item.relatedTable, ".").concat(item.table, "_id\n WHERE ").concat(item.relatedTable, ".").concat(_this.table, "_id = ").concat(_this.table, ".id\n LIMIT 1\n ),\n JSON_OBJECT()\n) AS role,\n"));
|
|
107
|
+
sqlList.push("COALESCE(\n (\n SELECT JSON_OBJECT(".concat(fieldsSql, ")\n FROM ").concat(item.relatedTable, "\n JOIN ").concat(item.table, " ON ").concat(item.table, ".id = ").concat(item.relatedTable, ".").concat(item.table, "_id\n WHERE ").concat(item.relatedTable, ".").concat(_this.table, "_id = ").concat(_this.table, ".id\n LIMIT 1\n ),\n JSON_OBJECT()\n) AS role,\n"));
|
|
111
108
|
}
|
|
112
109
|
});
|
|
113
110
|
}
|
|
114
111
|
return {
|
|
115
|
-
sql: sqlList.length > 0 ? "\n" : "" + sqlList.join("\n"),
|
|
112
|
+
sql: (sqlList.length > 0 ? "\n" : "") + sqlList.join("\n"),
|
|
116
113
|
};
|
|
117
114
|
},
|
|
118
115
|
enumerable: false,
|