pgsql-deparser 17.18.4 → 17.18.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/deparser.d.ts CHANGED
@@ -247,6 +247,7 @@ export declare class Deparser implements DeparserVisitor {
247
247
  CreateOpFamilyStmt(node: t.CreateOpFamilyStmt, context: DeparserContext): string;
248
248
  AlterOpFamilyStmt(node: t.AlterOpFamilyStmt, context: DeparserContext): string;
249
249
  MergeStmt(node: t.MergeStmt, context: DeparserContext): string;
250
+ MergeWhenClause(node: t.MergeWhenClause, context: DeparserContext): string;
250
251
  AlterTableMoveAllStmt(node: t.AlterTableMoveAllStmt, context: DeparserContext): string;
251
252
  CreateSeqStmt(node: t.CreateSeqStmt, context: DeparserContext): string;
252
253
  AlterSeqStmt(node: t.AlterSeqStmt, context: DeparserContext): string;
package/deparser.js CHANGED
@@ -8056,7 +8056,17 @@ class Deparser {
8056
8056
  }
8057
8057
  }
8058
8058
  if (node.object) {
8059
- output.push(this.visit(node.object, context));
8059
+ // Qualified names arrive as a List of String nodes and must be
8060
+ // dot-joined (visiting the List directly would comma-join them).
8061
+ if (typeof node.object === 'object' && 'List' in node.object) {
8062
+ const list = node.object.List;
8063
+ const objectParts = list_utils_1.ListUtils.unwrapList(list.items)
8064
+ .map(item => this.visit(item, context));
8065
+ output.push(objectParts.join('.'));
8066
+ }
8067
+ else {
8068
+ output.push(this.visit(node.object, context));
8069
+ }
8060
8070
  }
8061
8071
  output.push('IS');
8062
8072
  if (node.label) {
@@ -8562,6 +8572,76 @@ class Deparser {
8562
8572
  .join(' ');
8563
8573
  output.push(whenClauses);
8564
8574
  }
8575
+ if (node.returningList && node.returningList.length > 0) {
8576
+ output.push('RETURNING');
8577
+ const returningList = list_utils_1.ListUtils.unwrapList(node.returningList)
8578
+ .map(target => this.visit(target, context))
8579
+ .join(', ');
8580
+ output.push(returningList);
8581
+ }
8582
+ return output.join(' ');
8583
+ }
8584
+ MergeWhenClause(node, context) {
8585
+ const output = ['WHEN'];
8586
+ switch (node.matchKind) {
8587
+ case 'MERGE_WHEN_MATCHED':
8588
+ output.push('MATCHED');
8589
+ break;
8590
+ case 'MERGE_WHEN_NOT_MATCHED_BY_SOURCE':
8591
+ output.push('NOT MATCHED BY SOURCE');
8592
+ break;
8593
+ case 'MERGE_WHEN_NOT_MATCHED_BY_TARGET':
8594
+ output.push('NOT MATCHED');
8595
+ break;
8596
+ }
8597
+ if (node.condition) {
8598
+ output.push('AND');
8599
+ output.push(this.visit(node.condition, context));
8600
+ }
8601
+ output.push('THEN');
8602
+ switch (node.commandType) {
8603
+ case 'CMD_UPDATE': {
8604
+ output.push('UPDATE SET');
8605
+ const assignments = list_utils_1.ListUtils.unwrapList(node.targetList)
8606
+ .map(target => this.visit(target, context.spawn('UpdateStmt', { update: true })))
8607
+ .join(', ');
8608
+ output.push(assignments);
8609
+ break;
8610
+ }
8611
+ case 'CMD_INSERT': {
8612
+ output.push('INSERT');
8613
+ const targetList = list_utils_1.ListUtils.unwrapList(node.targetList);
8614
+ if (targetList.length > 0) {
8615
+ const columns = targetList
8616
+ .map(target => quotes_1.QuoteUtils.quoteIdentifier(target.ResTarget?.name))
8617
+ .join(', ');
8618
+ output.push(`(${columns})`);
8619
+ }
8620
+ if (node.override === 'OVERRIDING_USER_VALUE') {
8621
+ output.push('OVERRIDING USER VALUE');
8622
+ }
8623
+ else if (node.override === 'OVERRIDING_SYSTEM_VALUE') {
8624
+ output.push('OVERRIDING SYSTEM VALUE');
8625
+ }
8626
+ const values = list_utils_1.ListUtils.unwrapList(node.values);
8627
+ if (values.length > 0) {
8628
+ const valueItems = values
8629
+ .map(value => this.visit(value, context))
8630
+ .join(', ');
8631
+ output.push(`VALUES (${valueItems})`);
8632
+ }
8633
+ else {
8634
+ output.push('DEFAULT VALUES');
8635
+ }
8636
+ break;
8637
+ }
8638
+ case 'CMD_DELETE':
8639
+ output.push('DELETE');
8640
+ break;
8641
+ case 'CMD_NOTHING':
8642
+ output.push('DO NOTHING');
8643
+ break;
8644
+ }
8565
8645
  return output.join(' ');
8566
8646
  }
8567
8647
  AlterTableMoveAllStmt(node, context) {
package/esm/deparser.js CHANGED
@@ -8053,7 +8053,17 @@ export class Deparser {
8053
8053
  }
8054
8054
  }
8055
8055
  if (node.object) {
8056
- output.push(this.visit(node.object, context));
8056
+ // Qualified names arrive as a List of String nodes and must be
8057
+ // dot-joined (visiting the List directly would comma-join them).
8058
+ if (typeof node.object === 'object' && 'List' in node.object) {
8059
+ const list = node.object.List;
8060
+ const objectParts = ListUtils.unwrapList(list.items)
8061
+ .map(item => this.visit(item, context));
8062
+ output.push(objectParts.join('.'));
8063
+ }
8064
+ else {
8065
+ output.push(this.visit(node.object, context));
8066
+ }
8057
8067
  }
8058
8068
  output.push('IS');
8059
8069
  if (node.label) {
@@ -8559,6 +8569,76 @@ export class Deparser {
8559
8569
  .join(' ');
8560
8570
  output.push(whenClauses);
8561
8571
  }
8572
+ if (node.returningList && node.returningList.length > 0) {
8573
+ output.push('RETURNING');
8574
+ const returningList = ListUtils.unwrapList(node.returningList)
8575
+ .map(target => this.visit(target, context))
8576
+ .join(', ');
8577
+ output.push(returningList);
8578
+ }
8579
+ return output.join(' ');
8580
+ }
8581
+ MergeWhenClause(node, context) {
8582
+ const output = ['WHEN'];
8583
+ switch (node.matchKind) {
8584
+ case 'MERGE_WHEN_MATCHED':
8585
+ output.push('MATCHED');
8586
+ break;
8587
+ case 'MERGE_WHEN_NOT_MATCHED_BY_SOURCE':
8588
+ output.push('NOT MATCHED BY SOURCE');
8589
+ break;
8590
+ case 'MERGE_WHEN_NOT_MATCHED_BY_TARGET':
8591
+ output.push('NOT MATCHED');
8592
+ break;
8593
+ }
8594
+ if (node.condition) {
8595
+ output.push('AND');
8596
+ output.push(this.visit(node.condition, context));
8597
+ }
8598
+ output.push('THEN');
8599
+ switch (node.commandType) {
8600
+ case 'CMD_UPDATE': {
8601
+ output.push('UPDATE SET');
8602
+ const assignments = ListUtils.unwrapList(node.targetList)
8603
+ .map(target => this.visit(target, context.spawn('UpdateStmt', { update: true })))
8604
+ .join(', ');
8605
+ output.push(assignments);
8606
+ break;
8607
+ }
8608
+ case 'CMD_INSERT': {
8609
+ output.push('INSERT');
8610
+ const targetList = ListUtils.unwrapList(node.targetList);
8611
+ if (targetList.length > 0) {
8612
+ const columns = targetList
8613
+ .map(target => QuoteUtils.quoteIdentifier(target.ResTarget?.name))
8614
+ .join(', ');
8615
+ output.push(`(${columns})`);
8616
+ }
8617
+ if (node.override === 'OVERRIDING_USER_VALUE') {
8618
+ output.push('OVERRIDING USER VALUE');
8619
+ }
8620
+ else if (node.override === 'OVERRIDING_SYSTEM_VALUE') {
8621
+ output.push('OVERRIDING SYSTEM VALUE');
8622
+ }
8623
+ const values = ListUtils.unwrapList(node.values);
8624
+ if (values.length > 0) {
8625
+ const valueItems = values
8626
+ .map(value => this.visit(value, context))
8627
+ .join(', ');
8628
+ output.push(`VALUES (${valueItems})`);
8629
+ }
8630
+ else {
8631
+ output.push('DEFAULT VALUES');
8632
+ }
8633
+ break;
8634
+ }
8635
+ case 'CMD_DELETE':
8636
+ output.push('DELETE');
8637
+ break;
8638
+ case 'CMD_NOTHING':
8639
+ output.push('DO NOTHING');
8640
+ break;
8641
+ }
8562
8642
  return output.join(' ');
8563
8643
  }
8564
8644
  AlterTableMoveAllStmt(node, context) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pgsql-deparser",
3
- "version": "17.18.4",
3
+ "version": "17.18.5",
4
4
  "author": "Constructive <developers@constructive.io>",
5
5
  "description": "PostgreSQL AST Deparser",
6
6
  "main": "index.js",
@@ -60,5 +60,5 @@
60
60
  "@pgsql/quotes": "17.1.0",
61
61
  "@pgsql/types": "^17.6.2"
62
62
  },
63
- "gitHead": "987c0c66fee20025b193cb497d1ceb8832dc4ed2"
63
+ "gitHead": "4213e2c9da8ccb8d21c4ec02f35e34aef65b8ced"
64
64
  }