oak-db 2.2.1 → 2.2.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.
@@ -1,4 +1,4 @@
1
- import { EntityDict, DeduceCreateSingleOperation, DeduceRemoveOperation, DeduceUpdateOperation, OperateOption, OperationResult, TxnOption, StorageSchema, DeduceCreateMultipleOperation, SelectOption, AggregationResult } from 'oak-domain/lib/types';
1
+ import { EntityDict, OperateOption, OperationResult, TxnOption, StorageSchema, SelectOption, AggregationResult } from 'oak-domain/lib/types';
2
2
  import { EntityDict as BaseEntityDict } from 'oak-domain/lib/base-app-domain';
3
3
  import { CascadeStore } from 'oak-domain/lib/store/CascadeStore';
4
4
  import { MySQLConfiguration } from './types/Configuration';
@@ -19,7 +19,7 @@ export declare class MysqlStore<ED extends EntityDict & BaseEntityDict, Cxt exte
19
19
  protected supportMultipleCreate(): boolean;
20
20
  private formResult;
21
21
  protected selectAbjointRowAsync<T extends keyof ED>(entity: T, selection: ED[T]['Selection'], context: AsyncContext<ED>, option?: MySqlSelectOption): Promise<Partial<ED[T]['Schema']>[]>;
22
- protected updateAbjointRowAsync<T extends keyof ED>(entity: T, operation: DeduceCreateMultipleOperation<ED[T]['Schema']> | DeduceCreateSingleOperation<ED[T]['Schema']> | DeduceUpdateOperation<ED[T]['Schema']> | DeduceRemoveOperation<ED[T]['Schema']>, context: AsyncContext<ED>, option?: MysqlOperateOption): Promise<number>;
22
+ protected updateAbjointRowAsync<T extends keyof ED>(entity: T, operation: ED[T]['Operation'], context: AsyncContext<ED>, option?: MysqlOperateOption): Promise<number>;
23
23
  operate<T extends keyof ED>(entity: T, operation: ED[T]['Operation'], context: Cxt, option: OperateOption): Promise<OperationResult<ED>>;
24
24
  select<T extends keyof ED>(entity: T, selection: ED[T]['Selection'], context: Cxt, option: SelectOption): Promise<Partial<ED[T]['Schema']>[]>;
25
25
  count<T extends keyof ED>(entity: T, selection: Pick<ED[T]['Selection'], 'filter' | 'count'>, context: Cxt, option: SelectOption): Promise<number>;
@@ -83,7 +83,7 @@ var MySqlTranslator = /** @class */ (function (_super) {
83
83
  if (option === null || option === void 0 ? void 0 : option.includedDeleted) {
84
84
  return '';
85
85
  }
86
- return " `".concat(alias, "`.`$$deleteAt$$` is null");
86
+ return " (`".concat(alias, "`.`$$deleteAt$$` is null)");
87
87
  };
88
88
  MySqlTranslator.prototype.makeUpSchema = function () {
89
89
  for (var entity in this.schema) {
@@ -495,6 +495,14 @@ var MySqlTranslator = /** @class */ (function (_super) {
495
495
  (0, assert_1.default)(argumentNumber === 2);
496
496
  return 'ST_DISTANCE(%s, %s)';
497
497
  }
498
+ case '$concat': {
499
+ var result = ' concat(%s';
500
+ while (--argumentNumber > 0) {
501
+ result += ', %s';
502
+ }
503
+ result += ')';
504
+ return result;
505
+ }
498
506
  default: {
499
507
  throw new Error("unrecoganized function ".concat(fnName));
500
508
  }
@@ -513,7 +521,7 @@ var MySqlTranslator = /** @class */ (function (_super) {
513
521
  var _this = this;
514
522
  var translateConstant = function (constant) {
515
523
  if (constant instanceof Date) {
516
- return " ".concat(constant.valueOf());
524
+ return " from_unixtime(".concat(constant.valueOf(), "/1000)");
517
525
  }
518
526
  else if (typeof constant === 'string') {
519
527
  return " '".concat(constant, "'");
@@ -535,7 +543,7 @@ var MySqlTranslator = /** @class */ (function (_super) {
535
543
  var refAttr = (expr)['#refAttr'];
536
544
  (0, assert_1.default)(refDict[refId]);
537
545
  var attrText = "`".concat(refDict[refId][0], "`.`").concat(refAttr, "`");
538
- result = _this.translateAttrInExpression(entity, (expr)['#attr'], attrText);
546
+ result = _this.translateAttrInExpression(entity, (expr)['#refAttr'], attrText);
539
547
  }
540
548
  else {
541
549
  (0, assert_1.default)(k.length === 1);
@@ -1,4 +1,4 @@
1
- import { DeduceCreateOperationData, EntityDict, OperateOption, Q_FullTextValue, Ref, RefOrExpression, SelectOption, StorageSchema } from "oak-domain/lib/types";
1
+ import { EntityDict, OperateOption, Q_FullTextValue, Ref, RefOrExpression, SelectOption, StorageSchema } from "oak-domain/lib/types";
2
2
  import { DataType } from "oak-domain/lib/types/schema/DataTypes";
3
3
  export interface SqlSelectOption extends SelectOption {
4
4
  }
@@ -20,7 +20,7 @@ export declare abstract class SqlTranslator<ED extends EntityDict> {
20
20
  protected abstract populateRemoveStmt<OP extends SqlOperateOption>(removeText: string, fromText: string, aliasDict: Record<string, string>, filterText: string, sorterText?: string, indexFrom?: number, count?: number, option?: OP): string;
21
21
  protected abstract translateExpression<T extends keyof ED>(entity: T, alias: string, expression: RefOrExpression<keyof ED[T]['OpSchema']>, refDict: Record<string, [string, keyof ED]>): string;
22
22
  private getStorageName;
23
- translateInsert<T extends keyof ED>(entity: T, data: DeduceCreateOperationData<ED[T]['OpSchema']>[]): string;
23
+ translateInsert<T extends keyof ED>(entity: T, data: ED[T]['CreateMulti']['data']): string;
24
24
  /**
25
25
  * analyze the join relations in projection/query/sort
26
26
  * 所有的层次关系都当成left join处理,如果有内表为空的情况,请手动处理
@@ -516,9 +516,9 @@ var SqlTranslator = /** @class */ (function () {
516
516
  if (whereText) {
517
517
  whereText += ' and ';
518
518
  }
519
- whereText + '(';
520
519
  if (['$and', '$or', '$xor', '$not'].includes(attr)) {
521
520
  var result = '';
521
+ whereText += '(';
522
522
  switch (attr) {
523
523
  case '$and':
524
524
  case '$or':
@@ -545,6 +545,7 @@ var SqlTranslator = /** @class */ (function () {
545
545
  }
546
546
  }
547
547
  }
548
+ whereText += ')';
548
549
  }
549
550
  else if (attr.toLowerCase().startsWith(types_1.EXPRESSION_PREFIX)) {
550
551
  // expression
@@ -564,24 +565,23 @@ var SqlTranslator = /** @class */ (function () {
564
565
  else {
565
566
  var rel = (0, relation_1.judgeRelation)(_this.schema, entity2, attr);
566
567
  if (rel === 2) {
567
- whereText += " ".concat(translateInner(attr, "".concat(path).concat(attr, "/"), filter2[attr]));
568
+ whereText += " (".concat(translateInner(attr, "".concat(path).concat(attr, "/"), filter2[attr]), ")");
568
569
  }
569
570
  else if (typeof rel === 'string') {
570
- whereText += " ".concat(translateInner(rel, "".concat(path).concat(attr, "/"), filter2[attr]));
571
+ whereText += " (".concat(translateInner(rel, "".concat(path).concat(attr, "/"), filter2[attr]), ")");
571
572
  }
572
573
  else {
573
574
  (0, assert_1.default)(attributes.hasOwnProperty(attr), "\u975E\u6CD5\u7684\u5C5E\u6027".concat(attr));
574
575
  var type2 = attributes[attr].type;
575
576
  // assert (type2 !== 'ref');
576
577
  if (typeof filter2[attr] === 'object' && Object.keys(filter2[attr])[0] && Object.keys(filter2[attr])[0].startsWith('$')) {
577
- whereText += " `".concat(alias, "`.`").concat(attr, "` ").concat(translateInner(entity2, path, filter2[attr], type2));
578
+ whereText += " (`".concat(alias, "`.`").concat(attr, "` ").concat(translateInner(entity2, path, filter2[attr], type2), ")");
578
579
  }
579
580
  else {
580
- whereText += " `".concat(alias, "`.`").concat(attr, "` = ").concat(_this.translateAttrValue(type2, filter2[attr]));
581
+ whereText += " (`".concat(alias, "`.`").concat(attr, "` = ").concat(_this.translateAttrValue(type2, filter2[attr]), ")");
581
582
  }
582
583
  }
583
584
  }
584
- whereText + ')';
585
585
  });
586
586
  }
587
587
  if (!whereText) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oak-db",
3
- "version": "2.2.1",
3
+ "version": "2.2.2",
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.3.2",
21
+ "oak-domain": "^2.4.0",
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.3.1",
32
+ "oak-general-business": "^2.3.2",
33
33
  "ts-node": "~10.9.1",
34
34
  "tslib": "^2.4.0",
35
35
  "typescript": "~4.7.4"