update和remove不支持orderBy,对外键空行返回结果的处理,以及发布前更新依赖
This commit is contained in:
parent
499e9b396f
commit
81de1e972f
|
|
@ -56,10 +56,12 @@ var MysqlStore = /** @class */ (function (_super) {
|
|||
}
|
||||
else {
|
||||
(0, assert_1.default)(typeof rel === 'string');
|
||||
if (!r[attrHead]) {
|
||||
r[attrHead] = {};
|
||||
if (typeof r["".concat(attrHead, "Id")] === 'string') {
|
||||
if (!r[attrHead]) {
|
||||
r[attrHead] = {};
|
||||
}
|
||||
resolveAttribute(rel, r[attrHead], attrTail, value);
|
||||
}
|
||||
resolveAttribute(rel, r[attrHead], attrTail, value);
|
||||
}
|
||||
}
|
||||
else if (attributes[attr]) {
|
||||
|
|
|
|||
|
|
@ -704,15 +704,17 @@ var SqlTranslator = /** @class */ (function () {
|
|||
};
|
||||
SqlTranslator.prototype.translateRemove = function (entity, operation, option) {
|
||||
var filter = operation.filter, sorter = operation.sorter, indexFrom = operation.indexFrom, count = operation.count;
|
||||
(0, assert_1.default)(!sorter, '当前remove不支持sorter行为');
|
||||
var _a = this.analyzeJoin(entity, { filter: filter, sorter: sorter }), aliasDict = _a.aliasDict, filterRefAlias = _a.filterRefAlias, extraWhere = _a.extraWhere, fromText = _a.from, currentNumber = _a.currentNumber;
|
||||
var alias = aliasDict['./'];
|
||||
var filterText = this.translateFilter(entity, operation, aliasDict, filterRefAlias, currentNumber, extraWhere).stmt;
|
||||
var sorterText = sorter && sorter.length > 0 ? this.translateSorter(entity, sorter, aliasDict) : undefined;
|
||||
return this.populateRemoveStmt(alias, fromText, aliasDict, filterText, sorterText, indexFrom, count, option);
|
||||
// const sorterText = sorter && sorter.length > 0 ? this.translateSorter(entity, sorter, aliasDict) : undefined;
|
||||
return this.populateRemoveStmt(alias, fromText, aliasDict, filterText, /* sorterText */ undefined, indexFrom, count, option);
|
||||
};
|
||||
SqlTranslator.prototype.translateUpdate = function (entity, operation, option) {
|
||||
var attributes = this.schema[entity].attributes;
|
||||
var filter = operation.filter, sorter = operation.sorter, indexFrom = operation.indexFrom, count = operation.count, data = operation.data;
|
||||
(0, assert_1.default)(!sorter, '当前update不支持sorter行为');
|
||||
var _a = this.analyzeJoin(entity, { filter: filter, sorter: sorter }), aliasDict = _a.aliasDict, filterRefAlias = _a.filterRefAlias, extraWhere = _a.extraWhere, fromText = _a.from, currentNumber = _a.currentNumber;
|
||||
var alias = aliasDict['./'];
|
||||
var updateText = '';
|
||||
|
|
@ -725,8 +727,8 @@ var SqlTranslator = /** @class */ (function () {
|
|||
updateText += "`".concat(alias, "`.`").concat(attr, "` = ").concat(value);
|
||||
}
|
||||
var filterText = this.translateFilter(entity, operation, aliasDict, filterRefAlias, currentNumber, extraWhere).stmt;
|
||||
var sorterText = sorter && this.translateSorter(entity, sorter, aliasDict);
|
||||
return this.populateUpdateStmt(updateText, fromText, aliasDict, filterText, sorterText, indexFrom, count, option);
|
||||
// const sorterText = sorter && this.translateSorter(entity, sorter, aliasDict);
|
||||
return this.populateUpdateStmt(updateText, fromText, aliasDict, filterText, /* sorterText */ undefined, indexFrom, count, option);
|
||||
};
|
||||
SqlTranslator.prototype.translateDestroyEntity = function (entity, truncate) {
|
||||
var schema = this.schema;
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
"name": "oak-db",
|
||||
"version": "1.0.6",
|
||||
"description": "oak-db",
|
||||
"main": "src/index",
|
||||
"main": "lib/index",
|
||||
"author": {
|
||||
"name": "XuChang"
|
||||
},
|
||||
|
|
@ -19,7 +19,7 @@
|
|||
"luxon": "^2.4.0",
|
||||
"mysql": "^2.18.1",
|
||||
"mysql2": "^2.3.3",
|
||||
"oak-domain": "file:../oak-domain",
|
||||
"oak-domain": "^1.1.13",
|
||||
"uuid": "^8.3.2"
|
||||
},
|
||||
"license": "ISC",
|
||||
|
|
@ -30,7 +30,7 @@
|
|||
"@types/node": "^17.0.42",
|
||||
"@types/uuid": "^8.3.4",
|
||||
"mocha": "^10.0.0",
|
||||
"oak-general-business": "file:../oak-general-business",
|
||||
"oak-general-business": "^1.0.14",
|
||||
"ts-node": "~10.9.1",
|
||||
"tslib": "^2.4.0",
|
||||
"typescript": "~4.7.4"
|
||||
|
|
|
|||
|
|
@ -60,10 +60,12 @@ export class MysqlStore<ED extends EntityDict & BaseEntityDict, Cxt extends Cont
|
|||
}
|
||||
else {
|
||||
assert(typeof rel === 'string');
|
||||
if (!r[attrHead]) {
|
||||
r[attrHead] = {};
|
||||
if (typeof r[`${attrHead}Id`] === 'string') {
|
||||
if (!r[attrHead]) {
|
||||
r[attrHead] = {};
|
||||
}
|
||||
resolveAttribute(rel, r[attrHead], attrTail, value);
|
||||
}
|
||||
resolveAttribute(rel, r[attrHead], attrTail, value);
|
||||
}
|
||||
}
|
||||
else if (attributes[attr]) {
|
||||
|
|
|
|||
|
|
@ -873,20 +873,22 @@ export abstract class SqlTranslator<ED extends EntityDict> {
|
|||
|
||||
translateRemove<T extends keyof ED, OP extends SqlOperateOption>(entity: T, operation: ED[T]['Remove'], option?: OP): string {
|
||||
const { filter, sorter, indexFrom, count } = operation;
|
||||
assert(!sorter, '当前remove不支持sorter行为');
|
||||
const { aliasDict, filterRefAlias, extraWhere, from: fromText, currentNumber } = this.analyzeJoin(entity, { filter, sorter });
|
||||
|
||||
const alias = aliasDict['./'];
|
||||
|
||||
const { stmt: filterText } = this.translateFilter(entity, operation, aliasDict, filterRefAlias, currentNumber, extraWhere);
|
||||
|
||||
const sorterText = sorter && sorter.length > 0 ? this.translateSorter(entity, sorter, aliasDict) : undefined;
|
||||
// const sorterText = sorter && sorter.length > 0 ? this.translateSorter(entity, sorter, aliasDict) : undefined;
|
||||
|
||||
return this.populateRemoveStmt(alias, fromText, aliasDict, filterText, sorterText, indexFrom, count, option);
|
||||
return this.populateRemoveStmt(alias, fromText, aliasDict, filterText, /* sorterText */ undefined, indexFrom, count, option);
|
||||
}
|
||||
|
||||
translateUpdate<T extends keyof ED, OP extends SqlOperateOption>(entity: T, operation: ED[T]['Update'], option?: OP): string {
|
||||
const { attributes } = this.schema[entity];
|
||||
const { filter, sorter, indexFrom, count, data } = operation;
|
||||
assert(!sorter, '当前update不支持sorter行为');
|
||||
const { aliasDict, filterRefAlias, extraWhere, from: fromText, currentNumber } = this.analyzeJoin(entity, { filter, sorter });
|
||||
|
||||
const alias = aliasDict['./'];
|
||||
|
|
@ -902,9 +904,9 @@ export abstract class SqlTranslator<ED extends EntityDict> {
|
|||
}
|
||||
|
||||
const { stmt: filterText } = this.translateFilter(entity, operation, aliasDict, filterRefAlias, currentNumber, extraWhere);
|
||||
const sorterText = sorter && this.translateSorter(entity, sorter, aliasDict);
|
||||
// const sorterText = sorter && this.translateSorter(entity, sorter, aliasDict);
|
||||
|
||||
return this.populateUpdateStmt(updateText, fromText, aliasDict, filterText, sorterText, indexFrom, count, option);
|
||||
return this.populateUpdateStmt(updateText, fromText, aliasDict, filterText, /* sorterText */ undefined, indexFrom, count, option);
|
||||
}
|
||||
|
||||
translateDestroyEntity(entity: string, truncate?: boolean): string {
|
||||
|
|
|
|||
Loading…
Reference in New Issue