removePhysically

This commit is contained in:
Xu Chang 2023-03-30 20:29:58 +08:00
parent 0672a6413e
commit 9a4f53bca4
5 changed files with 59 additions and 18 deletions

View File

@ -625,6 +625,20 @@ var MySqlTranslator = /** @class */ (function (_super) {
MySqlTranslator.prototype.populateRemoveStmt = function (removeText, fromText, aliasDict, filterText, sorterText, indexFrom, count, option) {
// todo using index
var alias = aliasDict['./'];
if (option === null || option === void 0 ? void 0 : option.deletePhysically) {
var sql_1 = "delete from ".concat(fromText, " ");
if (filterText) {
sql_1 += " where ".concat(filterText);
}
if (sorterText) {
sql_1 += " order by ".concat(sorterText);
}
if (typeof indexFrom === 'number') {
(0, assert_1.default)(typeof count === 'number');
sql_1 += " limit ".concat(indexFrom, ", ").concat(count);
}
return sql_1;
}
var now = Date.now();
var sql = "update ".concat(fromText, " set `").concat(alias, "`.`$$deleteAt$$` = '").concat(now, "'");
if (filterText) {

View File

@ -43,6 +43,7 @@ export declare abstract class SqlTranslator<ED extends EntityDict> {
private translateProjection;
private translateSelectInner;
translateSelect<T extends keyof ED, OP extends SqlSelectOption>(entity: T, selection: ED[T]['Selection'], option?: OP): string;
translateWhere<T extends keyof ED, OP extends SqlSelectOption>(entity: T, selection: ED[T]['Selection'], option?: OP): string;
translateAggregate<T extends keyof ED, OP extends SqlSelectOption>(entity: T, aggregation: ED[T]['Aggregation'], option?: OP): string;
translateCount<T extends keyof ED, OP extends SqlSelectOption>(entity: T, selection: Pick<ED[T]['Selection'], 'filter' | 'count'>, option?: OP): string;
translateRemove<T extends keyof ED, OP extends SqlOperateOption>(entity: T, operation: ED[T]['Remove'], option?: OP): string;

View File

@ -776,12 +776,17 @@ var SqlTranslator = /** @class */ (function () {
return {
stmt: this.populateSelectStmt(projText, fromText, aliasDict, filterText, sorterText, undefined, indexFrom, count, option, selection),
currentNumber: currentNumber2,
filterStmt: filterText,
};
};
SqlTranslator.prototype.translateSelect = function (entity, selection, option) {
var stmt = this.translateSelectInner(entity, selection, 1, {}, option).stmt;
return stmt;
};
SqlTranslator.prototype.translateWhere = function (entity, selection, option) {
var filterStmt = this.translateSelectInner(entity, selection, 1, {}, option).filterStmt;
return filterStmt;
};
SqlTranslator.prototype.translateAggregate = function (entity, aggregation, option) {
var data = aggregation.data, filter = aggregation.filter, sorter = aggregation.sorter, indexFrom = aggregation.indexFrom, count = aggregation.count;
var _a = this.analyzeJoin(entity, {

View File

@ -845,6 +845,21 @@ export class MySqlTranslator<ED extends EntityDict> extends SqlTranslator<ED> {
protected populateRemoveStmt(removeText: string, fromText: string, aliasDict: Record<string, string>, filterText: string, sorterText?: string, indexFrom?: number, count?: number, option?: MysqlOperateOption): string {
// todo using index
const alias = aliasDict['./'];
if (option?.deletePhysically) {
let sql = `delete from ${fromText} `;
if (filterText) {
sql += ` where ${filterText}`;
}
if (sorterText) {
sql += ` order by ${sorterText}`;
}
if (typeof indexFrom === 'number') {
assert(typeof count === 'number');
sql += ` limit ${indexFrom}, ${count}`;
}
return sql;
}
const now = Date.now();
let sql = `update ${fromText} set \`${alias}\`.\`$$deleteAt$$\` = '${now}'`;
if (filterText) {

View File

@ -934,6 +934,7 @@ export abstract class SqlTranslator<ED extends EntityDict> {
}
private translateSelectInner<T extends keyof ED, OP extends SqlSelectOption>(entity: T, selection: ED[T]['Selection'], initialNumber: number, refAlias: Record<string, [string, keyof ED]>, option?: OP): {
filterStmt: string;
stmt: string;
currentNumber: number;
} {
@ -955,6 +956,7 @@ export abstract class SqlTranslator<ED extends EntityDict> {
return {
stmt: this.populateSelectStmt(projText, fromText, aliasDict, filterText, sorterText, undefined, indexFrom, count, option, selection),
currentNumber: currentNumber2,
filterStmt: filterText,
};
}
@ -963,6 +965,10 @@ export abstract class SqlTranslator<ED extends EntityDict> {
return stmt;
}
translateWhere<T extends keyof ED, OP extends SqlSelectOption>(entity: T, selection: ED[T]['Selection'], option?: OP): string {
const { filterStmt } = this.translateSelectInner(entity, selection, 1, {}, option);
return filterStmt;
}
translateAggregate<T extends keyof ED, OP extends SqlSelectOption>(entity: T, aggregation: ED[T]['Aggregation'], option?: OP): string {
const { data, filter, sorter, indexFrom, count } = aggregation;