ddl-manager
Version:
store postgres procedures and triggers in files
49 lines • 1.7 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.buildSelfUpdateByOtherTablesBody = void 0;
const ast_1 = require("../../../ast");
const exitIf_1 = require("./util/exitIf");
function buildSelfUpdateByOtherTablesBody(noChanges, selectNewValues, notMatchedFilterOnUpdate) {
const body = new ast_1.Body({
declares: [
new ast_1.Declare({
name: "new_totals",
type: "record"
})
],
statements: [
new ast_1.BlankLine(),
new ast_1.If({
if: noChanges,
then: [
new ast_1.HardCode({
sql: `return new;`
})
]
}),
...exitIf_1.exitIf({
if: notMatchedFilterOnUpdate,
blanksBefore: [new ast_1.BlankLine()]
}),
new ast_1.BlankLine(),
new ast_1.BlankLine(),
selectNewValues.clone({
intoRow: "new_totals"
}),
new ast_1.BlankLine(),
new ast_1.BlankLine(),
...selectNewValues.columns.map(column => new ast_1.AssignVariable({
variable: `new.${column.name}`,
value: new ast_1.HardCode({ sql: `new_totals.${column.name}` })
})),
new ast_1.BlankLine(),
new ast_1.BlankLine(),
new ast_1.HardCode({
sql: `return new;`
})
]
});
return body;
}
exports.buildSelfUpdateByOtherTablesBody = buildSelfUpdateByOtherTablesBody;
//# sourceMappingURL=buildSelfUpdateByOtherTablesBody.js.map