removePhysically
This commit is contained in:
parent
0672a6413e
commit
9a4f53bca4
|
|
@ -625,6 +625,20 @@ var MySqlTranslator = /** @class */ (function (_super) {
|
||||||
MySqlTranslator.prototype.populateRemoveStmt = function (removeText, fromText, aliasDict, filterText, sorterText, indexFrom, count, option) {
|
MySqlTranslator.prototype.populateRemoveStmt = function (removeText, fromText, aliasDict, filterText, sorterText, indexFrom, count, option) {
|
||||||
// todo using index
|
// todo using index
|
||||||
var alias = aliasDict['./'];
|
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 now = Date.now();
|
||||||
var sql = "update ".concat(fromText, " set `").concat(alias, "`.`$$deleteAt$$` = '").concat(now, "'");
|
var sql = "update ".concat(fromText, " set `").concat(alias, "`.`$$deleteAt$$` = '").concat(now, "'");
|
||||||
if (filterText) {
|
if (filterText) {
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,7 @@ export declare abstract class SqlTranslator<ED extends EntityDict> {
|
||||||
private translateProjection;
|
private translateProjection;
|
||||||
private translateSelectInner;
|
private translateSelectInner;
|
||||||
translateSelect<T extends keyof ED, OP extends SqlSelectOption>(entity: T, selection: ED[T]['Selection'], option?: OP): string;
|
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;
|
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;
|
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;
|
translateRemove<T extends keyof ED, OP extends SqlOperateOption>(entity: T, operation: ED[T]['Remove'], option?: OP): string;
|
||||||
|
|
|
||||||
|
|
@ -776,12 +776,17 @@ var SqlTranslator = /** @class */ (function () {
|
||||||
return {
|
return {
|
||||||
stmt: this.populateSelectStmt(projText, fromText, aliasDict, filterText, sorterText, undefined, indexFrom, count, option, selection),
|
stmt: this.populateSelectStmt(projText, fromText, aliasDict, filterText, sorterText, undefined, indexFrom, count, option, selection),
|
||||||
currentNumber: currentNumber2,
|
currentNumber: currentNumber2,
|
||||||
|
filterStmt: filterText,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
SqlTranslator.prototype.translateSelect = function (entity, selection, option) {
|
SqlTranslator.prototype.translateSelect = function (entity, selection, option) {
|
||||||
var stmt = this.translateSelectInner(entity, selection, 1, {}, option).stmt;
|
var stmt = this.translateSelectInner(entity, selection, 1, {}, option).stmt;
|
||||||
return 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) {
|
SqlTranslator.prototype.translateAggregate = function (entity, aggregation, option) {
|
||||||
var data = aggregation.data, filter = aggregation.filter, sorter = aggregation.sorter, indexFrom = aggregation.indexFrom, count = aggregation.count;
|
var data = aggregation.data, filter = aggregation.filter, sorter = aggregation.sorter, indexFrom = aggregation.indexFrom, count = aggregation.count;
|
||||||
var _a = this.analyzeJoin(entity, {
|
var _a = this.analyzeJoin(entity, {
|
||||||
|
|
|
||||||
|
|
@ -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 {
|
protected populateRemoveStmt(removeText: string, fromText: string, aliasDict: Record<string, string>, filterText: string, sorterText?: string, indexFrom?: number, count?: number, option?: MysqlOperateOption): string {
|
||||||
// todo using index
|
// todo using index
|
||||||
const alias = aliasDict['./'];
|
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();
|
const now = Date.now();
|
||||||
let sql = `update ${fromText} set \`${alias}\`.\`$$deleteAt$$\` = '${now}'`;
|
let sql = `update ${fromText} set \`${alias}\`.\`$$deleteAt$$\` = '${now}'`;
|
||||||
if (filterText) {
|
if (filterText) {
|
||||||
|
|
|
||||||
|
|
@ -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): {
|
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;
|
stmt: string;
|
||||||
currentNumber: number;
|
currentNumber: number;
|
||||||
} {
|
} {
|
||||||
|
|
@ -955,6 +956,7 @@ export abstract class SqlTranslator<ED extends EntityDict> {
|
||||||
return {
|
return {
|
||||||
stmt: this.populateSelectStmt(projText, fromText, aliasDict, filterText, sorterText, undefined, indexFrom, count, option, selection),
|
stmt: this.populateSelectStmt(projText, fromText, aliasDict, filterText, sorterText, undefined, indexFrom, count, option, selection),
|
||||||
currentNumber: currentNumber2,
|
currentNumber: currentNumber2,
|
||||||
|
filterStmt: filterText,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -963,6 +965,10 @@ export abstract class SqlTranslator<ED extends EntityDict> {
|
||||||
return stmt;
|
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 {
|
translateAggregate<T extends keyof ED, OP extends SqlSelectOption>(entity: T, aggregation: ED[T]['Aggregation'], option?: OP): string {
|
||||||
const { data, filter, sorter, indexFrom, count } = aggregation;
|
const { data, filter, sorter, indexFrom, count } = aggregation;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue