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