pgsql-deparser 17.18.3 → 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
@@ -5008,7 +5008,8 @@ class Deparser {
5008
5008
  }
5009
5009
  output.push('SET EXPRESSION');
5010
5010
  if (node.def) {
5011
- output.push(this.visit(node.def, context));
5011
+ output.push('AS');
5012
+ output.push(context.parens(this.visit(node.def, context)));
5012
5013
  }
5013
5014
  break;
5014
5015
  case 'AT_DropExpression':
@@ -5017,6 +5018,9 @@ class Deparser {
5017
5018
  output.push(quotes_1.QuoteUtils.quoteIdentifier(node.name));
5018
5019
  }
5019
5020
  output.push('DROP EXPRESSION');
5021
+ if (node.missing_ok) {
5022
+ output.push('IF EXISTS');
5023
+ }
5020
5024
  break;
5021
5025
  case 'AT_CheckNotNull':
5022
5026
  output.push('ALTER COLUMN');
@@ -8052,7 +8056,17 @@ class Deparser {
8052
8056
  }
8053
8057
  }
8054
8058
  if (node.object) {
8055
- 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
+ }
8056
8070
  }
8057
8071
  output.push('IS');
8058
8072
  if (node.label) {
@@ -8558,6 +8572,76 @@ class Deparser {
8558
8572
  .join(' ');
8559
8573
  output.push(whenClauses);
8560
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
+ }
8561
8645
  return output.join(' ');
8562
8646
  }
8563
8647
  AlterTableMoveAllStmt(node, context) {
package/esm/deparser.js CHANGED
@@ -5005,7 +5005,8 @@ export class Deparser {
5005
5005
  }
5006
5006
  output.push('SET EXPRESSION');
5007
5007
  if (node.def) {
5008
- output.push(this.visit(node.def, context));
5008
+ output.push('AS');
5009
+ output.push(context.parens(this.visit(node.def, context)));
5009
5010
  }
5010
5011
  break;
5011
5012
  case 'AT_DropExpression':
@@ -5014,6 +5015,9 @@ export class Deparser {
5014
5015
  output.push(QuoteUtils.quoteIdentifier(node.name));
5015
5016
  }
5016
5017
  output.push('DROP EXPRESSION');
5018
+ if (node.missing_ok) {
5019
+ output.push('IF EXISTS');
5020
+ }
5017
5021
  break;
5018
5022
  case 'AT_CheckNotNull':
5019
5023
  output.push('ALTER COLUMN');
@@ -8049,7 +8053,17 @@ export class Deparser {
8049
8053
  }
8050
8054
  }
8051
8055
  if (node.object) {
8052
- 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
+ }
8053
8067
  }
8054
8068
  output.push('IS');
8055
8069
  if (node.label) {
@@ -8555,6 +8569,76 @@ export class Deparser {
8555
8569
  .join(' ');
8556
8570
  output.push(whenClauses);
8557
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
+ }
8558
8642
  return output.join(' ');
8559
8643
  }
8560
8644
  AlterTableMoveAllStmt(node, context) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pgsql-deparser",
3
- "version": "17.18.3",
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": "16d4dced1144372f2debc270ea07e9d842cc50c9"
63
+ "gitHead": "4213e2c9da8ccb8d21c4ec02f35e34aef65b8ced"
64
64
  }