@rdyl/node-mysql 0.3.6 → 0.3.8

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.5 (2025-12-31)
1
+ ## 0.3.8 (2025-12-31)
2
2
 
3
3
 
4
4
 
package/dist/helper.js CHANGED
@@ -97,16 +97,17 @@ var BaseHelper = /** @class */ (function () {
97
97
  /* 单个角色对象 */
98
98
  relatedFields.forEach(function (n) {
99
99
  var item = _this.related[n];
100
- // @ts-ignore
101
- var _a = (global.$MysqlTable[item.table] || {}).fields, fields = _a === void 0 ? [] : _a;
100
+ var model = item.model;
101
+ var fields = model.$mapFields;
102
+ var rTable = model.$table;
102
103
  var fieldsSql = "\n".concat(fields
103
- .map(function (e) { return " '".concat(e, "', ").concat(item.table, ".").concat(utils_1.Parser.toDbName(e)); })
104
+ .map(function (e) { return " '".concat(e, "', ").concat(rTable, ".").concat(utils_1.Parser.toDbName(e)); })
104
105
  .join(",\n"), "\n");
105
106
  if (item.isArray) {
106
- 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(n, "\n"));
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"));
107
108
  }
108
109
  else {
109
- 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 ").concat(n, "\n"));
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 JSON_OBJECT()\n) AS ").concat(n, "\n"));
110
111
  }
111
112
  });
112
113
  }
package/dist/meta.js CHANGED
@@ -71,22 +71,29 @@ var MysqlDbSchema = /** @class */ (function () {
71
71
  enumerable: false,
72
72
  configurable: true
73
73
  });
74
- Object.defineProperty(MysqlDbSchema.prototype, "$toMap", {
74
+ Object.defineProperty(MysqlDbSchema.prototype, "$fields", {
75
+ get: function () {
76
+ return Object.keys(this.$toJson);
77
+ },
78
+ enumerable: false,
79
+ configurable: true
80
+ });
81
+ Object.defineProperty(MysqlDbSchema.prototype, "$mapFields", {
75
82
  get: function () {
76
83
  var _this = this;
77
- var target = this.$toJson;
78
- return Object.fromEntries(Object.keys(target)
79
- .filter(function (k) { return !_this.$mapExFields.includes(k); })
80
- .map(function (k) {
81
- return [k, target[k]];
82
- }));
84
+ var list = this.$fields.filter(function (k) { return !_this.$mapExFields.includes(k); });
85
+ list.push.apply(list, Object.keys(this.$related));
86
+ return list;
83
87
  },
84
88
  enumerable: false,
85
89
  configurable: true
86
90
  });
87
- Object.defineProperty(MysqlDbSchema.prototype, "$fields", {
91
+ Object.defineProperty(MysqlDbSchema.prototype, "$toMap", {
88
92
  get: function () {
89
- return Object.keys(this.$toJson);
93
+ var target = this.$toJson;
94
+ return Object.fromEntries(this.$mapFields.map(function (k) {
95
+ return [k, target[k]];
96
+ }));
90
97
  },
91
98
  enumerable: false,
92
99
  configurable: true
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rdyl/node-mysql",
3
- "version": "0.3.6",
3
+ "version": "0.3.8",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "types": "types/index.d.ts",
package/types/meta.d.ts CHANGED
@@ -14,8 +14,9 @@ export declare class MysqlDbSchema implements MysqlDbBaseType {
14
14
  related?: Record<string, MysqlRelatedField>;
15
15
  });
16
16
  get $toJson(): any;
17
- get $toMap(): any;
18
17
  get $fields(): string[];
18
+ get $mapFields(): string[];
19
+ get $toMap(): any;
19
20
  $formJson(json: Record<string, unknown>): void;
20
21
  $get(): Promise<this | null>;
21
22
  $insert(uniqueKey?: string): Promise<MysqlDbResultStat>;
package/types/type.d.ts CHANGED
@@ -9,7 +9,7 @@ interface MysqlDbBaseType {
9
9
  type MysqlDbResultStat = "exist" | "ok" | "fail";
10
10
 
11
11
  type MysqlRelatedField = {
12
- table: string;
13
- relatedTable: string;
12
+ model: import("./meta").MysqlDbSchema;
13
+ related: string;
14
14
  isArray?: boolean;
15
15
  };