Skip to content

Commit 6428b87

Browse files
committed
feat(pgsql-deparser): add pretty-printing for INSERT VALUES and ON CONFLICT SET
- VALUES tuple items: put each value on its own line when isPretty() - ON CONFLICT DO UPDATE SET: put each assignment on its own line when isPretty() This enables proper multi-line formatting for INSERT statements with VALUES lists and ON CONFLICT clauses when pretty mode is enabled.
1 parent 1278b39 commit 6428b87

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

packages/deparser/src/deparser.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,9 @@ export class Deparser implements DeparserVisitor {
563563
output.push('VALUES');
564564
const lists = ListUtils.unwrapList(node.valuesLists).map(list => {
565565
const values = ListUtils.unwrapList(list).map(val => this.visit(val as Node, context));
566-
return context.parens(values.join(', '));
566+
// Put each value on its own line for pretty printing
567+
const indentedValues = values.map(val => context.indent(val));
568+
return '(\n' + indentedValues.join(',\n') + '\n)';
567569
});
568570
const indentedTuples = lists.map(tuple => {
569571
if (this.containsMultilineStringLiteral(tuple)) {
@@ -1116,7 +1118,13 @@ export class Deparser implements DeparserVisitor {
11161118
} else {
11171119
const updateContext = context.spawn('UpdateStmt', { update: true });
11181120
const targets = targetList.map(target => this.visit(target as Node, updateContext));
1119-
output.push(targets.join(', '));
1121+
if (context.isPretty()) {
1122+
// Put each assignment on its own line for pretty printing
1123+
const indentedTargets = targets.map(target => context.indent(target));
1124+
output.push('\n' + indentedTargets.join(',\n'));
1125+
} else {
1126+
output.push(targets.join(', '));
1127+
}
11201128
}
11211129
}
11221130

0 commit comments

Comments
 (0)