ddl-manager
Version:
store postgres procedures and triggers in files
61 lines • 2.13 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.OrderBy = void 0;
const lodash_1 = require("lodash");
const AbstractAstElement_1 = require("./AbstractAstElement");
const expression_1 = require("./expression");
const OrderByItem_1 = require("./OrderByItem");
class OrderBy extends AbstractAstElement_1.AbstractAstElement {
constructor(items) {
super();
this.items = items;
}
clone(newItems = this.items.map(item => item.clone())) {
return new OrderBy(newItems);
}
replaceTable(replaceTable, toTable) {
const newItems = this.items.map(item => item.replaceTable(replaceTable, toTable));
return new OrderBy(newItems);
}
equal(orderBy) {
return (this.items.length === orderBy.items.length &&
this.items.every((item, i) => item.equal(orderBy.items[i])));
}
getColumnReferences() {
return lodash_1.flatMap(this.items, item => item.getColumnReferences());
}
template(spaces) {
return [
spaces + "order by",
...this.items.map((item, i) => item.toSQL(spaces.plusOneLevel()) + (i === this.items.length - 1 ? "" : ","))
];
}
hasIdSort() {
return this.items.some(item => item.isIdSort());
}
addIdSort(from) {
return this.clone([
...this.items,
new OrderByItem_1.OrderByItem({
expression: new expression_1.Expression([
new expression_1.ColumnReference(from, "id")
]),
type: "desc"
})
]);
}
isOnlyId() {
const orderByColumns = this.getColumnReferences();
const byId = (orderByColumns.length === 1 &&
orderByColumns[0].name === "id");
return byId;
}
getFirstColumnRef() {
return this.getColumnReferences()[0];
}
compareRowsByOrder(leftRow, vector, rightRow, orPreConditions = []) {
return this.items[0].compareRowsByOrder(leftRow, vector, rightRow, orPreConditions);
}
}
exports.OrderBy = OrderBy;
//# sourceMappingURL=OrderBy.js.map