oak-db 1.0.4 → 1.0.6

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.
@@ -44,12 +44,25 @@ var MysqlStore = /** @class */ (function (_super) {
44
44
  if (i !== -1) {
45
45
  var attrHead = attr.slice(0, i);
46
46
  var attrTail = attr.slice(i + 1);
47
- if (!r[attrHead]) {
48
- r[attrHead] = {};
49
- }
50
47
  var rel = (0, relation_1.judgeRelation)(schema, entity2, attrHead);
51
48
  (0, assert_1.default)(rel === 2 || typeof rel === 'string');
52
- resolveAttribute(typeof rel === 'string' ? rel : attrHead, r[attrHead], attrTail, value);
49
+ if (rel === 2) {
50
+ if (r.entity === attrHead) {
51
+ if (!r[attrHead]) {
52
+ r[attrHead] = {};
53
+ }
54
+ resolveAttribute(attrHead, r[attrHead], attrTail, value);
55
+ }
56
+ }
57
+ else {
58
+ (0, assert_1.default)(typeof rel === 'string');
59
+ if (typeof r["".concat(attrHead, "Id")] === 'string') {
60
+ if (!r[attrHead]) {
61
+ r[attrHead] = {};
62
+ }
63
+ resolveAttribute(rel, r[attrHead], attrTail, value);
64
+ }
65
+ }
53
66
  }
54
67
  else if (attributes[attr]) {
55
68
  var type = attributes[attr].type;
@@ -221,8 +221,7 @@ var SqlTranslator = /** @class */ (function () {
221
221
  (0, lodash_1.assign)(aliasDict, (_b = {},
222
222
  _b[pathAttr] = alias2,
223
223
  _b));
224
- from += " left join `".concat(_this.getStorageName(op), "` `").concat(alias2, "` on `").concat(alias, "`.`entityId` = `").concat(alias2, "`.`id`");
225
- extraWhere += "`".concat(alias, "`.`entity` = '").concat(op, "'");
224
+ from += " left join `".concat(_this.getStorageName(op), "` `").concat(alias2, "` on `").concat(alias, "`.`entityId` = `").concat(alias2, "`.`id` and `").concat(alias, "`.`entity` = '").concat(op, "'");
226
225
  }
227
226
  else {
228
227
  alias2 = aliasDict[pathAttr];
@@ -288,8 +287,7 @@ var SqlTranslator = /** @class */ (function () {
288
287
  (0, lodash_1.assign)(aliasDict, (_c = {},
289
288
  _c[pathAttr] = alias2,
290
289
  _c));
291
- from += " left join `".concat(_this.getStorageName(attr), "` `").concat(alias2, "` on `").concat(alias, "`.`entityId` = `").concat(alias2, "`.`id`");
292
- extraWhere += "`".concat(alias, "`.`entity` = '").concat(attr, "'");
290
+ from += " left join `".concat(_this.getStorageName(attr), "` `").concat(alias2, "` on `").concat(alias, "`.`entityId` = `").concat(alias2, "`.`id` and `").concat(alias, "`.`entity` = '").concat(attr, "'");
293
291
  }
294
292
  else {
295
293
  alias2 = aliasDict[pathAttr];
@@ -350,7 +348,7 @@ var SqlTranslator = /** @class */ (function () {
350
348
  (0, lodash_1.assign)(aliasDict, (_b = {},
351
349
  _b[pathAttr] = alias2,
352
350
  _b));
353
- from += " left join `".concat(_this.getStorageName(attr), "` `").concat(alias2, "` on `").concat(alias, "`.`entityId` = `").concat(alias2, "`.`id`");
351
+ from += " left join `".concat(_this.getStorageName(attr), "` `").concat(alias2, "` on `").concat(alias, "`.`entityId` = `").concat(alias2, "`.`id` and `").concat(alias, "`.`entity` = '").concat(attr, "'");
354
352
  }
355
353
  else {
356
354
  alias2 = aliasDict[pathAttr];
@@ -361,7 +359,6 @@ var SqlTranslator = /** @class */ (function () {
361
359
  entityName: attr,
362
360
  alias: alias2,
363
361
  });
364
- extraWhere += "`".concat(alias, "`.`entity` = '").concat(attr, "'");
365
362
  }
366
363
  });
367
364
  if (node['#id']) {
@@ -707,15 +704,17 @@ var SqlTranslator = /** @class */ (function () {
707
704
  };
708
705
  SqlTranslator.prototype.translateRemove = function (entity, operation, option) {
709
706
  var filter = operation.filter, sorter = operation.sorter, indexFrom = operation.indexFrom, count = operation.count;
707
+ (0, assert_1.default)(!sorter, '当前remove不支持sorter行为');
710
708
  var _a = this.analyzeJoin(entity, { filter: filter, sorter: sorter }), aliasDict = _a.aliasDict, filterRefAlias = _a.filterRefAlias, extraWhere = _a.extraWhere, fromText = _a.from, currentNumber = _a.currentNumber;
711
709
  var alias = aliasDict['./'];
712
710
  var filterText = this.translateFilter(entity, operation, aliasDict, filterRefAlias, currentNumber, extraWhere).stmt;
713
- var sorterText = sorter && sorter.length > 0 ? this.translateSorter(entity, sorter, aliasDict) : undefined;
714
- return this.populateRemoveStmt(alias, fromText, aliasDict, filterText, sorterText, indexFrom, count, option);
711
+ // const sorterText = sorter && sorter.length > 0 ? this.translateSorter(entity, sorter, aliasDict) : undefined;
712
+ return this.populateRemoveStmt(alias, fromText, aliasDict, filterText, /* sorterText */ undefined, indexFrom, count, option);
715
713
  };
716
714
  SqlTranslator.prototype.translateUpdate = function (entity, operation, option) {
717
715
  var attributes = this.schema[entity].attributes;
718
716
  var filter = operation.filter, sorter = operation.sorter, indexFrom = operation.indexFrom, count = operation.count, data = operation.data;
717
+ (0, assert_1.default)(!sorter, '当前update不支持sorter行为');
719
718
  var _a = this.analyzeJoin(entity, { filter: filter, sorter: sorter }), aliasDict = _a.aliasDict, filterRefAlias = _a.filterRefAlias, extraWhere = _a.extraWhere, fromText = _a.from, currentNumber = _a.currentNumber;
720
719
  var alias = aliasDict['./'];
721
720
  var updateText = '';
@@ -728,8 +727,8 @@ var SqlTranslator = /** @class */ (function () {
728
727
  updateText += "`".concat(alias, "`.`").concat(attr, "` = ").concat(value);
729
728
  }
730
729
  var filterText = this.translateFilter(entity, operation, aliasDict, filterRefAlias, currentNumber, extraWhere).stmt;
731
- var sorterText = sorter && this.translateSorter(entity, sorter, aliasDict);
732
- return this.populateUpdateStmt(updateText, fromText, aliasDict, filterText, sorterText, indexFrom, count, option);
730
+ // const sorterText = sorter && this.translateSorter(entity, sorter, aliasDict);
731
+ return this.populateUpdateStmt(updateText, fromText, aliasDict, filterText, /* sorterText */ undefined, indexFrom, count, option);
733
732
  };
734
733
  SqlTranslator.prototype.translateDestroyEntity = function (entity, truncate) {
735
734
  var schema = this.schema;
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "oak-db",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
4
4
  "description": "oak-db",
5
- "main": "lib/index.js",
5
+ "main": "lib/index",
6
6
  "author": {
7
7
  "name": "XuChang"
8
8
  },
@@ -19,7 +19,7 @@
19
19
  "luxon": "^2.4.0",
20
20
  "mysql": "^2.18.1",
21
21
  "mysql2": "^2.3.3",
22
- "oak-domain": "1.1.11",
22
+ "oak-domain": "^1.1.13",
23
23
  "uuid": "^8.3.2"
24
24
  },
25
25
  "license": "ISC",
@@ -30,7 +30,7 @@
30
30
  "@types/node": "^17.0.42",
31
31
  "@types/uuid": "^8.3.4",
32
32
  "mocha": "^10.0.0",
33
- "oak-general-business": "1.0.13",
33
+ "oak-general-business": "^1.0.14",
34
34
  "ts-node": "~10.9.1",
35
35
  "tslib": "^2.4.0",
36
36
  "typescript": "~4.7.4"