@rdyl/node-mysql 0.4.0 → 0.4.1

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 CHANGED
@@ -1,4 +1,4 @@
1
- ## 0.3.9 (2025-12-31)
1
+ # 0.4.0 (2026-01-04)
2
2
 
3
3
 
4
4
 
package/dist/helper.js CHANGED
@@ -74,6 +74,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
74
74
  exports.MysqlUpdater = exports.MysqlDeleter = exports.MysqlInserter = exports.MysqlSelector = void 0;
75
75
  var interface_1 = require("./interface");
76
76
  var utils_1 = require("./utils");
77
+ var toDbName = utils_1.Parser.toDbName;
77
78
  var BaseHelper = /** @class */ (function () {
78
79
  function BaseHelper(table, related) {
79
80
  if (related === void 0) { related = {}; }
@@ -97,17 +98,18 @@ var BaseHelper = /** @class */ (function () {
97
98
  /* 单个角色对象 */
98
99
  relatedFields.forEach(function (n) {
99
100
  var item = _this.related[n];
100
- var model = item.model;
101
- var fields = model.$mapFields;
102
- var rTable = model.$table;
101
+ var related = item.related, ownerId = item.ownerId, instance = item.instance, isArray = item.isArray;
102
+ var relatedId = "".concat(n, "Id");
103
+ var fields = instance.$mapFields;
104
+ var iTable = instance.$table;
103
105
  var fieldsSql = "\n".concat(fields
104
- .map(function (e) { return " '".concat(e, "', ").concat(rTable, ".").concat(utils_1.Parser.toDbName(e)); })
106
+ .map(function (e) { return " '".concat(e, "', ").concat(iTable, ".").concat(toDbName(e)); })
105
107
  .join(",\n"), "\n");
106
- if (item.isArray) {
107
- sqlList.push("COALESCE(\n (\n SELECT JSON_ARRAYAGG(\n JSON_OBJECT(".concat(fieldsSql, " )\n )\n FROM ").concat(item.related, "\n JOIN ").concat(rTable, " ON ").concat(rTable, ".id = ").concat(item.related, ".").concat(rTable, "_id\n WHERE ").concat(item.related, ".").concat(_this.table, "_id = ").concat(_this.table, ".id\n ),\n JSON_ARRAY()\n) AS ").concat(n, "\n"));
108
+ if (isArray) {
109
+ sqlList.push("COALESCE(\n (\n SELECT JSON_ARRAYAGG(\n JSON_OBJECT(".concat(fieldsSql, " )\n )\n FROM ").concat(related, "\n JOIN ").concat(iTable, " ON ").concat(iTable, ".id = ").concat(related, ".").concat(toDbName(relatedId), "\n WHERE ").concat(related, ".").concat(toDbName(ownerId), " = ").concat(_this.table, ".id\n ),\n JSON_ARRAY()\n) AS ").concat(n, "\n"));
108
110
  }
109
111
  else {
110
- sqlList.push("COALESCE(\n (\n SELECT JSON_OBJECT(".concat(fieldsSql, " )\n FROM ").concat(item.related, "\n JOIN ").concat(rTable, " ON ").concat(rTable, ".id = ").concat(item.related, ".").concat(rTable, "_id\n WHERE ").concat(item.related, ".").concat(_this.table, "_id = ").concat(_this.table, ".id\n LIMIT 1\n )\n) AS ").concat(n, "\n"));
112
+ sqlList.push("COALESCE(\n (\n SELECT JSON_OBJECT(".concat(fieldsSql, " )\n FROM ").concat(related, "\n JOIN ").concat(iTable, " ON ").concat(iTable, ".id = ").concat(related, ".").concat(toDbName(relatedId), "\n WHERE ").concat(related, ".").concat(toDbName(ownerId), " = ").concat(_this.table, ".id\n LIMIT 1\n )\n) AS ").concat(n, "\n"));
111
113
  }
112
114
  });
113
115
  }
@@ -127,7 +129,7 @@ var BaseHelper = /** @class */ (function () {
127
129
  sql += " WHERE ";
128
130
  selects.forEach(function (ele, i) {
129
131
  var field = ele.field, value = ele.value, _a = ele.condition, condition = _a === void 0 ? "eq" : _a, _b = ele.relation, relation = _b === void 0 ? "and" : _b;
130
- var res = "".concat(utils_1.Parser.toDbName(field), " ").concat(interface_1.ConditionMaps[condition], " ");
132
+ var res = "".concat(toDbName(field), " ").concat(interface_1.ConditionMaps[condition], " ");
131
133
  if (condition === "include") {
132
134
  res += "(?)";
133
135
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rdyl/node-mysql",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "types": "types/index.d.ts",
package/types/type.d.ts CHANGED
@@ -9,7 +9,8 @@ interface MysqlDbBaseType {
9
9
  type MysqlDbResultStat = "exist" | "ok" | "fail";
10
10
 
11
11
  type MysqlRelatedField = {
12
- model: import("./meta").MysqlDbSchema;
13
- related: string;
12
+ instance: import("./meta").MysqlDbSchema;
13
+ related:string
14
+ ownerId: string
14
15
  isArray?: boolean;
15
16
  };