oak-db 2.0.2 → 2.0.3
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/lib/MySQL/store.js +27 -26
- package/package.json +3 -3
package/lib/MySQL/store.js
CHANGED
|
@@ -50,24 +50,16 @@ var MysqlStore = /** @class */ (function (_super) {
|
|
|
50
50
|
if (i !== -1) {
|
|
51
51
|
var attrHead = attr.slice(0, i);
|
|
52
52
|
var attrTail = attr.slice(i + 1);
|
|
53
|
+
if (!r[attrHead]) {
|
|
54
|
+
r[attrHead] = {};
|
|
55
|
+
}
|
|
53
56
|
var rel = (0, relation_1.judgeRelation)(schema, entity2, attrHead);
|
|
54
|
-
(0, assert_1.default)(rel === 2 || typeof rel === 'string');
|
|
55
57
|
if (rel === 2) {
|
|
56
|
-
|
|
57
|
-
if (!r[attrHead]) {
|
|
58
|
-
r[attrHead] = {};
|
|
59
|
-
}
|
|
60
|
-
resolveAttribute(attrHead, r[attrHead], attrTail, value);
|
|
61
|
-
}
|
|
58
|
+
resolveAttribute(attrHead, r[attrHead], attrTail, value);
|
|
62
59
|
}
|
|
63
60
|
else {
|
|
64
61
|
(0, assert_1.default)(typeof rel === 'string');
|
|
65
|
-
|
|
66
|
-
if (!r[attrHead]) {
|
|
67
|
-
r[attrHead] = {};
|
|
68
|
-
}
|
|
69
|
-
resolveAttribute(rel, r[attrHead], attrTail, value);
|
|
70
|
-
}
|
|
62
|
+
resolveAttribute(rel, r[attrHead], attrTail, value);
|
|
71
63
|
}
|
|
72
64
|
}
|
|
73
65
|
else if (attributes[attr]) {
|
|
@@ -140,23 +132,32 @@ var MysqlStore = /** @class */ (function (_super) {
|
|
|
140
132
|
_a));
|
|
141
133
|
}
|
|
142
134
|
}
|
|
143
|
-
function
|
|
144
|
-
|
|
145
|
-
var allowFormalize = true;
|
|
135
|
+
function removeNullObjects(r, e) {
|
|
136
|
+
(0, assert_1.default)(r.id && typeof r.id === 'string', "\u5BF9\u8C61".concat(e, "\u53D6\u6570\u636E\u65F6\u53D1\u73B0id\u4E3A\u975E\u6CD5\u503C").concat(r.id, ",rowId\u662F").concat(r.id));
|
|
146
137
|
for (var attr in r) {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
138
|
+
var rel = (0, relation_1.judgeRelation)(schema, e, attr);
|
|
139
|
+
if (rel === 2) {
|
|
140
|
+
// 边界,如果是toModi的对象,这里的外键确实有可能为空
|
|
141
|
+
(0, assert_1.default)(schema[e].toModi || r.entityId === r[attr].id, "\u5BF9\u8C61".concat(e, "\u53D6\u6570\u636E\u65F6\uFF0C\u53D1\u73B0entityId\u4E0E\u8FDE\u63A5\u7684\u5BF9\u8C61\u7684\u4E3B\u952E\u4E0D\u4E00\u81F4\uFF0CrowId\u662F").concat(r.id, "\uFF0C\u5176entityId\u503C\u4E3A").concat(r.entityId, "\uFF0C\u8FDE\u63A5\u7684\u5BF9\u8C61\u7684\u4E3B\u952E\u4E3A").concat(r[attr].id));
|
|
142
|
+
if (r[attr].id === null) {
|
|
143
|
+
(0, assert_1.default)(schema[e].toModi);
|
|
144
|
+
delete r[attr];
|
|
145
|
+
continue;
|
|
153
146
|
}
|
|
147
|
+
(0, assert_1.default)(r.entity === attr, "\u5BF9\u8C61".concat(e, "\u53D6\u6570\u636E\u65F6\uFF0C\u53D1\u73B0entity\u503C\u4E0E\u8FDE\u63A5\u7684\u5916\u952E\u5BF9\u8C61\u4E0D\u4E00\u81F4\uFF0CrowId\u662F").concat(r.id, "\uFF0C\u5176entity\u503C\u4E3A").concat(r.entity, "\uFF0C\u8FDE\u63A5\u7684\u5BF9\u8C61\u4E3A").concat(attr));
|
|
148
|
+
removeNullObjects(r[attr], attr);
|
|
154
149
|
}
|
|
155
|
-
else if (
|
|
156
|
-
|
|
150
|
+
else if (typeof rel === 'string') {
|
|
151
|
+
// 边界,如果是toModi的对象,这里的外键确实有可能为空
|
|
152
|
+
(0, assert_1.default)(schema[e].toModi || r["".concat(attr, "Id")] === r[attr].id, "\u5BF9\u8C61".concat(e, "\u53D6\u6570\u636E\u65F6\uFF0C\u53D1\u73B0\u5176\u5916\u952E\u4E0E\u8FDE\u63A5\u7684\u5BF9\u8C61\u7684\u4E3B\u952E\u4E0D\u4E00\u81F4\uFF0CrowId\u662F").concat(r.id, "\uFF0C\u5176").concat(attr, "Id\u503C\u4E3A").concat(r["".concat(attr, "Id")], "\uFF0C\u8FDE\u63A5\u7684\u5BF9\u8C61\u7684\u4E3B\u952E\u4E3A").concat(r[attr].id));
|
|
153
|
+
if (r[attr].id === null) {
|
|
154
|
+
(0, assert_1.default)(schema[e].toModi);
|
|
155
|
+
delete r[attr];
|
|
156
|
+
continue;
|
|
157
|
+
}
|
|
158
|
+
removeNullObjects(r[attr], rel);
|
|
157
159
|
}
|
|
158
160
|
}
|
|
159
|
-
return allowFormalize;
|
|
160
161
|
}
|
|
161
162
|
function formSingleRow(r) {
|
|
162
163
|
var result2 = {};
|
|
@@ -164,7 +165,7 @@ var MysqlStore = /** @class */ (function (_super) {
|
|
|
164
165
|
var value = r[attr];
|
|
165
166
|
resolveAttribute(entity, result2, attr, value);
|
|
166
167
|
}
|
|
167
|
-
|
|
168
|
+
removeNullObjects(result2, entity);
|
|
168
169
|
return result2;
|
|
169
170
|
}
|
|
170
171
|
if (result instanceof Array) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "oak-db",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.3",
|
|
4
4
|
"description": "oak-db",
|
|
5
5
|
"main": "lib/index",
|
|
6
6
|
"author": {
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"lodash": "^4.17.21",
|
|
19
19
|
"mysql": "^2.18.1",
|
|
20
20
|
"mysql2": "^2.3.3",
|
|
21
|
-
"oak-domain": "^2.0.
|
|
21
|
+
"oak-domain": "^2.0.2",
|
|
22
22
|
"uuid": "^8.3.2"
|
|
23
23
|
},
|
|
24
24
|
"license": "ISC",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"@types/node": "^17.0.42",
|
|
30
30
|
"@types/uuid": "^8.3.4",
|
|
31
31
|
"mocha": "^10.0.0",
|
|
32
|
-
"oak-general-business": "^2.0.
|
|
32
|
+
"oak-general-business": "^2.0.2",
|
|
33
33
|
"ts-node": "~10.9.1",
|
|
34
34
|
"tslib": "^2.4.0",
|
|
35
35
|
"typescript": "~4.7.4"
|