pgsql-deparser 16.1.1 → 16.2.1

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/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # pgsql-deparser
2
2
 
3
3
  <p align="center" width="100%">
4
- <img height="120" src="https://github.com/constructive-io/pgsql-parser/assets/545047/6440fa7d-918b-4a3b-8d1b-755d85de8bea" />
4
+ <img height="250" src="https://raw.githubusercontent.com/constructive-io/constructive/refs/heads/main/assets/outline-logo.svg" />
5
5
  </p>
6
6
 
7
7
  <p align="center" width="100%">
@@ -69,27 +69,29 @@ console.log(deparse(stmt));
69
69
  // Output: SELECT * FROM another_table
70
70
  ```
71
71
 
72
- ### Latest Version (PostgreSQL 17)
72
+ ### Latest Version (PostgreSQL 18)
73
73
 
74
74
  ```sh
75
75
  npm install pgsql-deparser
76
76
  ```
77
77
 
78
- ### Version-Specific Packages (PostgreSQL 13-16)
78
+ ### Version-Specific Packages (PostgreSQL 13-17)
79
79
 
80
- While we highly recommend using PG17, for PostgreSQL versions 13-16, use the version-specific packages:
80
+ We recommend PG18. PG17 remains fully supported; for PostgreSQL versions 13-17, use the version-specific packages:
81
81
 
82
82
  ```sh
83
83
  npm install pgsql-deparser@pg13 # PostgreSQL 13
84
84
  npm install pgsql-deparser@pg14 # PostgreSQL 14
85
85
  npm install pgsql-deparser@pg15 # PostgreSQL 15
86
86
  npm install pgsql-deparser@pg16 # PostgreSQL 16
87
+ npm install pgsql-deparser@pg17 # PostgreSQL 17
87
88
  ```
88
89
 
89
90
  **Version Status:**
90
- - **PG17**: 🚀 Recommended (stable + modern AST)
91
- - **PG14-16**: ⚠️ Experimental (modern AST, hardening in progress)
92
- - **PG13**: Stable (legacy AST format)
91
+ - **PG18**: 🚀 Recommended (stable + modern AST)
92
+ - **PG17**: Stable (modern AST)
93
+ - **PG14-16**: Legacy (modern AST, not actively developed)
94
+ - **PG13**: Legacy (legacy AST format)
93
95
 
94
96
  ## Options
95
97
 
@@ -151,6 +153,9 @@ Built on the excellent work of several contributors:
151
153
 
152
154
  ## Related
153
155
 
156
+ * [pgpm](https://pgpm.dev): A Postgres Package Manager that brings modular development to PostgreSQL with reusable packages, deterministic migrations, recursive dependency resolution, and tag-aware versioning.
157
+ * [pgsql-test](https://www.npmjs.com/package/pgsql-test): Instant, isolated PostgreSQL databases for each test with automatic transaction rollbacks, context switching, and clean seeding for fast, reliable database testing.
158
+ * [pgsql-seed](https://www.npmjs.com/package/pgsql-seed): PostgreSQL seeding utilities for CSV, JSON, SQL data loading, and pgpm deployment.
154
159
  * [pgsql-parser](https://www.npmjs.com/package/pgsql-parser): The real PostgreSQL parser for Node.js, providing symmetric parsing and deparsing of SQL statements with actual PostgreSQL parser integration.
155
160
  * [pgsql-deparser](https://www.npmjs.com/package/pgsql-deparser): A streamlined tool designed for converting PostgreSQL ASTs back into SQL queries, focusing solely on deparser functionality to complement `pgsql-parser`.
156
161
  * [@pgsql/parser](https://www.npmjs.com/package/@pgsql/parser): Multi-version PostgreSQL parser with dynamic version selection at runtime, supporting PostgreSQL 15, 16, and 17 in a single package.
@@ -10,31 +10,6 @@ export interface DeparserOptions {
10
10
  functionDelimiterFallback?: string;
11
11
  pretty?: boolean;
12
12
  }
13
- /**
14
- * Deparser - Converts PostgreSQL AST nodes back to SQL strings
15
- *
16
- * Entry Points:
17
- * 1. ParseResult (from libpg-query) - The complete parse result
18
- * Structure: { version: number, stmts: RawStmt[] }
19
- * Note: stmts is "repeated RawStmt" in protobuf, so array contains RawStmt
20
- * objects inline (not wrapped as { RawStmt: ... } nodes)
21
- * Example: { version: 170004, stmts: [{ stmt: {...}, stmt_len: 32 }] }
22
- *
23
- * 2. Wrapped ParseResult - When explicitly wrapped as a Node
24
- * Structure: { ParseResult: { version: number, stmts: RawStmt[] } }
25
- *
26
- * 3. Wrapped RawStmt - When explicitly wrapped as a Node
27
- * Structure: { RawStmt: { stmt: Node, stmt_len?: number } }
28
- *
29
- * 4. Array of Nodes - Multiple statements to deparse
30
- * Can be: Node[] (e.g., SelectStmt, InsertStmt, etc.)
31
- *
32
- * 5. Single Node - Individual statement node
33
- * Example: { SelectStmt: {...} }, { InsertStmt: {...} }, etc.
34
- *
35
- * The deparser automatically detects bare ParseResult objects for backward
36
- * compatibility and wraps them internally for consistent processing.
37
- */
38
13
  export declare class Deparser implements DeparserVisitor {
39
14
  private tree;
40
15
  private options;
@@ -79,12 +54,18 @@ export declare class Deparser implements DeparserVisitor {
79
54
  visitBetweenRange(rexpr: any, context: DeparserContext): string;
80
55
  InsertStmt(node: any, context: DeparserContext): string;
81
56
  UpdateStmt(node: any, context: DeparserContext): string;
57
+ formatUpdateAssignments(targets: any[], context: DeparserContext): string;
82
58
  DeleteStmt(node: any, context: DeparserContext): string;
83
59
  WithClause(node: any, context: DeparserContext): string;
84
60
  ResTarget(node: any, context: DeparserContext): string;
61
+ ATAlterConstraint(node: any, context: DeparserContext): string;
62
+ deparseKeyAttrs(attrs: any, withPeriod: boolean | undefined, context: DeparserContext): string;
63
+ ReturningClause(node: any, context: DeparserContext): string;
64
+ ReturningOption(node: any, context: DeparserContext): string;
85
65
  deparseReturningList(list: any, context: DeparserContext): string;
86
66
  BoolExpr(node: any, context: DeparserContext): string;
87
67
  FuncCall(node: any, context: DeparserContext): string;
68
+ formatOverClause(over: any, context: DeparserContext): string;
88
69
  FuncExpr(node: any, context: DeparserContext): string;
89
70
  A_Const(node: any, context: DeparserContext): string;
90
71
  ColumnRef(node: any, context: DeparserContext): string;
@@ -106,8 +87,6 @@ export declare class Deparser implements DeparserVisitor {
106
87
  CollateClause(node: any, context: DeparserContext): string;
107
88
  BooleanTest(node: any, context: DeparserContext): string;
108
89
  NullTest(node: any, context: DeparserContext): string;
109
- private static readonly RESERVED_WORDS;
110
- private static needsQuotes;
111
90
  quoteIfNeeded(value: string): string;
112
91
  preserveOperatorDefElemCase(defName: string): string;
113
92
  String(node: any, context: DeparserContext): string;
@@ -123,10 +102,13 @@ export declare class Deparser implements DeparserVisitor {
123
102
  SubLink(node: any, context: DeparserContext): string;
124
103
  CaseWhen(node: any, context: DeparserContext): string;
125
104
  WindowDef(node: any, context: DeparserContext): string;
105
+ formatIdentityColumnOptions(def: any, context: DeparserContext): string;
106
+ needsBExprParens(node: any): boolean;
126
107
  formatWindowFrame(node: any, context: DeparserContext): string | null;
127
108
  SortBy(node: any, context: DeparserContext): string;
128
109
  GroupingSet(node: any, context: DeparserContext): string;
129
110
  CommonTableExpr(node: any, context: DeparserContext): string;
111
+ formatAexprConst(node: any, context: DeparserContext): string;
130
112
  ParamRef(node: any, context: DeparserContext): string;
131
113
  LockingClause(node: any, context: DeparserContext): string;
132
114
  MinMaxExpr(node: any, context: DeparserContext): string;
@@ -192,6 +174,8 @@ export declare class Deparser implements DeparserVisitor {
192
174
  CheckPointStmt(node: any, context: DeparserContext): string;
193
175
  LoadStmt(node: any, context: DeparserContext): string;
194
176
  DiscardStmt(node: any, context: DeparserContext): string;
177
+ /** `schema.op` for an operator name list: schema parts quoted, the operator symbol as is. */
178
+ private qualifiedOperatorName;
195
179
  CommentStmt(node: any, context: DeparserContext): string;
196
180
  LockStmt(node: any, context: DeparserContext): string;
197
181
  CreatePolicyStmt(node: any, context: DeparserContext): string;
@@ -251,6 +235,8 @@ export declare class Deparser implements DeparserVisitor {
251
235
  CreateOpFamilyStmt(node: any, context: DeparserContext): string;
252
236
  AlterOpFamilyStmt(node: any, context: DeparserContext): string;
253
237
  MergeStmt(node: any, context: DeparserContext): string;
238
+ MergeSupportFunc(node: any, context: DeparserContext): string;
239
+ MergeWhenClause(node: any, context: DeparserContext): string;
254
240
  AlterTableMoveAllStmt(node: any, context: DeparserContext): string;
255
241
  CreateSeqStmt(node: any, context: DeparserContext): string;
256
242
  AlterSeqStmt(node: any, context: DeparserContext): string;
@@ -278,11 +264,29 @@ export declare class Deparser implements DeparserVisitor {
278
264
  OnConflictExpr(node: any, context: DeparserContext): string;
279
265
  ScanToken(node: any, context: DeparserContext): string;
280
266
  CreateOpClassItem(node: any, context: DeparserContext): string;
267
+ private quoteDefElemArg;
268
+ private formatOptionValue;
281
269
  Var(node: any, context: DeparserContext): string;
282
270
  TableFunc(node: any, context: DeparserContext): string;
283
271
  RangeTableFunc(node: any, context: DeparserContext): string;
272
+ private formatXmlTableExpr;
284
273
  RangeTableFuncCol(node: any, context: DeparserContext): string;
274
+ formatJsonFormat(format: any): string | null;
275
+ formatJsonOutput(output: any, context: DeparserContext): string | null;
276
+ formatJsonNullClause(absentOnNull: boolean | undefined): string;
277
+ formatJsonUniqueClause(unique: boolean | undefined): string | null;
278
+ JsonValueExpr(node: any, context: DeparserContext): string;
279
+ JsonKeyValue(node: any, context: DeparserContext): string;
280
+ JsonObjectConstructor(node: any, context: DeparserContext): string;
281
+ JsonArrayConstructor(node: any, context: DeparserContext): string;
285
282
  JsonArrayQueryConstructor(node: any, context: DeparserContext): string;
283
+ formatJsonAggSuffix(ctor: any, context: DeparserContext): string;
284
+ JsonObjectAgg(node: any, context: DeparserContext): string;
285
+ JsonArrayAgg(node: any, context: DeparserContext): string;
286
+ JsonParseExpr(node: any, context: DeparserContext): string;
287
+ JsonScalarExpr(node: any, context: DeparserContext): string;
288
+ JsonSerializeExpr(node: any, context: DeparserContext): string;
289
+ JsonIsPredicate(node: any, context: DeparserContext): string;
286
290
  RangeFunction(node: any, context: DeparserContext): string;
287
291
  XmlExpr(node: any, context: DeparserContext): string;
288
292
  schemaname(node: any, context: DeparserContext): string;
@@ -304,5 +308,4 @@ export declare class Deparser implements DeparserVisitor {
304
308
  AlterObjectSchemaStmt(node: any, context: DeparserContext): string;
305
309
  AlterRoleSetStmt(node: any, context: DeparserContext): string;
306
310
  CreateForeignTableStmt(node: any, context: DeparserContext): string;
307
- private containsMultilineStringLiteral;
308
311
  }