pgsql-deparser 15.0.0 → 17.1.0

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.
Files changed (38) hide show
  1. package/README.md +45 -88
  2. package/deparser.d.ts +253 -0
  3. package/{deparser/deparser.js → deparser.js} +180 -579
  4. package/esm/{deparser/deparser.js → deparser.js} +180 -579
  5. package/esm/index.js +3 -15
  6. package/esm/utils/index.js +90 -0
  7. package/esm/{deparser/utils → utils}/list-utils.js +0 -4
  8. package/esm/{deparser/utils → utils}/quote-utils.js +0 -34
  9. package/esm/utils/sql-formatter.js +23 -0
  10. package/esm/{deparser/visitors → visitors}/base.js +0 -4
  11. package/index.d.ts +3 -9
  12. package/index.js +4 -16
  13. package/package.json +27 -14
  14. package/utils/index.d.ts +4 -0
  15. package/utils/index.js +97 -0
  16. package/{deparser/utils → utils}/list-utils.d.ts +0 -4
  17. package/{deparser/utils → utils}/list-utils.js +0 -4
  18. package/utils/quote-utils.d.ts +5 -0
  19. package/{deparser/utils → utils}/quote-utils.js +0 -34
  20. package/{deparser/utils → utils}/sql-formatter.d.ts +1 -7
  21. package/{deparser/utils → utils}/sql-formatter.js +2 -15
  22. package/{deparser/visitors → visitors}/base.d.ts +5 -8
  23. package/{deparser/visitors → visitors}/base.js +0 -4
  24. package/deparser/deparser.d.ts +0 -301
  25. package/deparser/index.d.ts +0 -9
  26. package/deparser/index.js +0 -17
  27. package/deparser/utils/quote-utils.d.ts +0 -24
  28. package/esm/deparser/index.js +0 -13
  29. package/esm/deparser/utils/sql-formatter.js +0 -36
  30. package/esm/v15-to-v16.js +0 -2881
  31. package/esm/v15-to-v17-direct.js +0 -57
  32. package/esm/v16-to-v17.js +0 -1488
  33. package/v15-to-v16.d.ts +0 -627
  34. package/v15-to-v16.js +0 -2885
  35. package/v15-to-v17-direct.d.ts +0 -22
  36. package/v15-to-v17-direct.js +0 -61
  37. package/v16-to-v17.d.ts +0 -638
  38. package/v16-to-v17.js +0 -1492
package/v16-to-v17.js DELETED
@@ -1,1492 +0,0 @@
1
- "use strict";
2
- /**
3
- * Auto-generated file with types stripped for better tree-shaking
4
- * DO NOT EDIT - Generated by strip-transformer-types.ts
5
- */
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.V16ToV17Transformer = void 0;
8
- // @ts-nocheck
9
- /**
10
- * V16 to V17 AST Transformer
11
- * Transforms PostgreSQL v16 AST nodes to v17 format
12
- */
13
- class V16ToV17Transformer {
14
- transform(node, context = { parentNodeTypes: [] }) {
15
- if (node == null) {
16
- return null;
17
- }
18
- if (typeof node === 'number' || node instanceof Number) {
19
- return node;
20
- }
21
- if (typeof node === 'string') {
22
- return node;
23
- }
24
- try {
25
- return this.visit(node, context);
26
- }
27
- catch (error) {
28
- const nodeType = Object.keys(node)[0];
29
- throw new Error(`Error transforming ${nodeType}: ${error.message}`);
30
- }
31
- }
32
- visit(node, context = { parentNodeTypes: [] }) {
33
- const nodeType = this.getNodeType(node);
34
- // Handle empty objects
35
- if (!nodeType) {
36
- return {};
37
- }
38
- const nodeData = this.getNodeData(node);
39
- const methodName = nodeType;
40
- if (typeof this[methodName] === 'function') {
41
- const childContext = {
42
- ...context,
43
- parentNodeTypes: [...context.parentNodeTypes, nodeType]
44
- };
45
- const result = this[methodName](nodeData, childContext);
46
- return result;
47
- }
48
- // If no specific method, return the node as-is
49
- return node;
50
- }
51
- getNodeType(node) {
52
- return Object.keys(node)[0];
53
- }
54
- getNodeData(node) {
55
- const keys = Object.keys(node);
56
- if (keys.length === 1 && typeof node[keys[0]] === 'object') {
57
- return node[keys[0]];
58
- }
59
- return node;
60
- }
61
- ParseResult(node, context) {
62
- if (node && typeof node === 'object' && 'version' in node && 'stmts' in node) {
63
- return {
64
- version: 170004, // PG17 version
65
- stmts: node.stmts.map((stmt) => {
66
- if (stmt && typeof stmt === 'object' && 'stmt' in stmt) {
67
- return {
68
- ...stmt,
69
- stmt: this.transform(stmt.stmt, context)
70
- };
71
- }
72
- return this.transform(stmt, context);
73
- })
74
- };
75
- }
76
- return node;
77
- }
78
- RawStmt(node, context) {
79
- const result = {};
80
- if (node.stmt !== undefined) {
81
- result.stmt = this.transform(node.stmt, context);
82
- }
83
- if (node.stmt_location !== undefined) {
84
- result.stmt_location = node.stmt_location;
85
- }
86
- if (node.stmt_len !== undefined) {
87
- result.stmt_len = node.stmt_len;
88
- }
89
- return { RawStmt: result };
90
- }
91
- SelectStmt(node, context) {
92
- const result = {};
93
- if (node.distinctClause !== undefined) {
94
- result.distinctClause = Array.isArray(node.distinctClause)
95
- ? node.distinctClause.map(item => this.transform(item, context))
96
- : this.transform(node.distinctClause, context);
97
- }
98
- if (node.intoClause !== undefined) {
99
- result.intoClause = this.transform(node.intoClause, context);
100
- }
101
- if (node.targetList !== undefined) {
102
- result.targetList = Array.isArray(node.targetList)
103
- ? node.targetList.map(item => this.transform(item, context))
104
- : this.transform(node.targetList, context);
105
- }
106
- if (node.fromClause !== undefined) {
107
- result.fromClause = Array.isArray(node.fromClause)
108
- ? node.fromClause.map(item => this.transform(item, context))
109
- : this.transform(node.fromClause, context);
110
- }
111
- if (node.whereClause !== undefined) {
112
- result.whereClause = this.transform(node.whereClause, context);
113
- }
114
- if (node.groupClause !== undefined) {
115
- result.groupClause = Array.isArray(node.groupClause)
116
- ? node.groupClause.map(item => this.transform(item, context))
117
- : this.transform(node.groupClause, context);
118
- }
119
- if (node.groupDistinct !== undefined) {
120
- result.groupDistinct = node.groupDistinct;
121
- }
122
- if (node.havingClause !== undefined) {
123
- result.havingClause = this.transform(node.havingClause, context);
124
- }
125
- if (node.windowClause !== undefined) {
126
- result.windowClause = Array.isArray(node.windowClause)
127
- ? node.windowClause.map(item => this.transform(item, context))
128
- : this.transform(node.windowClause, context);
129
- }
130
- if (node.valuesLists !== undefined) {
131
- const valuesContext = {
132
- ...context,
133
- inValuesClause: true
134
- };
135
- result.valuesLists = Array.isArray(node.valuesLists)
136
- ? node.valuesLists.map(item => Array.isArray(item)
137
- ? item.map(subItem => this.transform(subItem, valuesContext))
138
- : this.transform(item, valuesContext))
139
- : this.transform(node.valuesLists, valuesContext);
140
- }
141
- if (node.sortClause !== undefined) {
142
- result.sortClause = Array.isArray(node.sortClause)
143
- ? node.sortClause.map(item => this.transform(item, context))
144
- : this.transform(node.sortClause, context);
145
- }
146
- if (node.limitOffset !== undefined) {
147
- result.limitOffset = this.transform(node.limitOffset, context);
148
- }
149
- if (node.limitCount !== undefined) {
150
- result.limitCount = this.transform(node.limitCount, context);
151
- }
152
- if (node.limitOption !== undefined) {
153
- result.limitOption = node.limitOption;
154
- }
155
- if (node.lockingClause !== undefined) {
156
- result.lockingClause = Array.isArray(node.lockingClause)
157
- ? node.lockingClause.map(item => this.transform(item, context))
158
- : this.transform(node.lockingClause, context);
159
- }
160
- if (node.withClause !== undefined) {
161
- result.withClause = this.transform(node.withClause, context);
162
- }
163
- if (node.op !== undefined) {
164
- result.op = node.op;
165
- }
166
- if (node.all !== undefined) {
167
- result.all = node.all;
168
- }
169
- if (node.larg !== undefined) {
170
- result.larg = this.transform(node.larg, context);
171
- }
172
- if (node.rarg !== undefined) {
173
- result.rarg = this.transform(node.rarg, context);
174
- }
175
- return { SelectStmt: result };
176
- }
177
- A_Expr(node, context) {
178
- const result = {};
179
- if (node.kind !== undefined) {
180
- result.kind = node.kind;
181
- }
182
- if (node.name !== undefined) {
183
- result.name = Array.isArray(node.name)
184
- ? node.name.map(item => this.transform(item, context))
185
- : this.transform(node.name, context);
186
- }
187
- if (node.lexpr !== undefined) {
188
- result.lexpr = this.transform(node.lexpr, context);
189
- }
190
- if (node.rexpr !== undefined) {
191
- result.rexpr = this.transform(node.rexpr, context);
192
- }
193
- if (node.location !== undefined) {
194
- result.location = node.location;
195
- }
196
- return { A_Expr: result };
197
- }
198
- InsertStmt(node, context) {
199
- const result = {};
200
- if (node.relation !== undefined) {
201
- result.relation = this.transform(node.relation, context);
202
- }
203
- if (node.cols !== undefined) {
204
- result.cols = Array.isArray(node.cols)
205
- ? node.cols.map(item => this.transform(item, context))
206
- : this.transform(node.cols, context);
207
- }
208
- if (node.selectStmt !== undefined) {
209
- result.selectStmt = this.transform(node.selectStmt, context);
210
- }
211
- if (node.onConflictClause !== undefined) {
212
- result.onConflictClause = this.transform(node.onConflictClause, context);
213
- }
214
- if (node.returningList !== undefined) {
215
- result.returningList = Array.isArray(node.returningList)
216
- ? node.returningList.map(item => this.transform(item, context))
217
- : this.transform(node.returningList, context);
218
- }
219
- if (node.withClause !== undefined) {
220
- result.withClause = this.transform(node.withClause, context);
221
- }
222
- if (node.override !== undefined) {
223
- result.override = node.override;
224
- }
225
- return { InsertStmt: result };
226
- }
227
- UpdateStmt(node, context) {
228
- const result = {};
229
- if (node.relation !== undefined) {
230
- result.relation = this.transform(node.relation, context);
231
- }
232
- if (node.targetList !== undefined) {
233
- result.targetList = Array.isArray(node.targetList)
234
- ? node.targetList.map(item => this.transform(item, context))
235
- : this.transform(node.targetList, context);
236
- }
237
- if (node.whereClause !== undefined) {
238
- result.whereClause = this.transform(node.whereClause, context);
239
- }
240
- if (node.fromClause !== undefined) {
241
- result.fromClause = Array.isArray(node.fromClause)
242
- ? node.fromClause.map(item => this.transform(item, context))
243
- : this.transform(node.fromClause, context);
244
- }
245
- if (node.returningList !== undefined) {
246
- result.returningList = Array.isArray(node.returningList)
247
- ? node.returningList.map(item => this.transform(item, context))
248
- : this.transform(node.returningList, context);
249
- }
250
- if (node.withClause !== undefined) {
251
- result.withClause = this.transform(node.withClause, context);
252
- }
253
- return { UpdateStmt: result };
254
- }
255
- DeleteStmt(node, context) {
256
- const result = {};
257
- if (node.relation !== undefined) {
258
- result.relation = this.transform(node.relation, context);
259
- }
260
- if (node.usingClause !== undefined) {
261
- result.usingClause = Array.isArray(node.usingClause)
262
- ? node.usingClause.map(item => this.transform(item, context))
263
- : this.transform(node.usingClause, context);
264
- }
265
- if (node.whereClause !== undefined) {
266
- result.whereClause = this.transform(node.whereClause, context);
267
- }
268
- if (node.returningList !== undefined) {
269
- result.returningList = Array.isArray(node.returningList)
270
- ? node.returningList.map(item => this.transform(item, context))
271
- : this.transform(node.returningList, context);
272
- }
273
- if (node.withClause !== undefined) {
274
- result.withClause = this.transform(node.withClause, context);
275
- }
276
- return { DeleteStmt: result };
277
- }
278
- WithClause(node, context) {
279
- const result = {};
280
- if (node.ctes !== undefined) {
281
- const cteContext = { ...context, inCTE: true };
282
- result.ctes = Array.isArray(node.ctes)
283
- ? node.ctes.map(item => this.transform(item, cteContext))
284
- : this.transform(node.ctes, cteContext);
285
- }
286
- if (node.recursive !== undefined) {
287
- result.recursive = node.recursive;
288
- }
289
- if (node.location !== undefined) {
290
- result.location = node.location;
291
- }
292
- return { WithClause: result };
293
- }
294
- ResTarget(node, context) {
295
- const result = {};
296
- if (node.name !== undefined) {
297
- result.name = node.name;
298
- }
299
- if (node.indirection !== undefined) {
300
- result.indirection = Array.isArray(node.indirection)
301
- ? node.indirection.map(item => this.transform(item, context))
302
- : this.transform(node.indirection, context);
303
- }
304
- if (node.val !== undefined) {
305
- result.val = this.transform(node.val, context);
306
- }
307
- if (node.location !== undefined) {
308
- result.location = node.location;
309
- }
310
- return { ResTarget: result };
311
- }
312
- BoolExpr(node, context) {
313
- const result = {};
314
- if (node.boolop !== undefined) {
315
- result.boolop = node.boolop;
316
- }
317
- if (node.args !== undefined) {
318
- result.args = Array.isArray(node.args)
319
- ? node.args.map(item => this.transform(item, context))
320
- : this.transform(node.args, context);
321
- }
322
- if (node.location !== undefined) {
323
- result.location = node.location;
324
- }
325
- return { BoolExpr: result };
326
- }
327
- FuncCall(node, context) {
328
- const result = {};
329
- if (node.funcname !== undefined) {
330
- result.funcname = Array.isArray(node.funcname)
331
- ? node.funcname.map(item => this.transform(item, context))
332
- : this.transform(node.funcname, context);
333
- }
334
- if (node.args !== undefined) {
335
- result.args = Array.isArray(node.args)
336
- ? node.args.map(item => this.transform(item, context))
337
- : this.transform(node.args, context);
338
- }
339
- if (node.agg_order !== undefined) {
340
- result.agg_order = Array.isArray(node.agg_order)
341
- ? node.agg_order.map(item => this.transform(item, context))
342
- : this.transform(node.agg_order, context);
343
- }
344
- if (node.agg_filter !== undefined) {
345
- result.agg_filter = this.transform(node.agg_filter, context);
346
- }
347
- if (node.agg_within_group !== undefined) {
348
- result.agg_within_group = node.agg_within_group;
349
- }
350
- if (node.agg_star !== undefined) {
351
- result.agg_star = node.agg_star;
352
- }
353
- if (node.agg_distinct !== undefined) {
354
- result.agg_distinct = node.agg_distinct;
355
- }
356
- if (node.func_variadic !== undefined) {
357
- result.func_variadic = node.func_variadic;
358
- }
359
- if (node.over !== undefined) {
360
- result.over = this.transform(node.over, context);
361
- }
362
- if (node.location !== undefined) {
363
- result.location = node.location;
364
- }
365
- const funcformatValue = this.getFuncformatValue(node, result.funcname, context);
366
- result.funcformat = funcformatValue;
367
- return { FuncCall: result };
368
- }
369
- FuncExpr(node, context) {
370
- return { FuncExpr: node };
371
- }
372
- A_Const(node, context) {
373
- return { A_Const: node };
374
- }
375
- ColumnRef(node, context) {
376
- return { ColumnRef: node };
377
- }
378
- isInCreateDomainContext(context) {
379
- return context.parentNodeTypes.includes('CreateDomainStmt');
380
- }
381
- isInTypeCastContext(context) {
382
- return context.parentNodeTypes.includes('TypeCast');
383
- }
384
- isInCreateTableContext(context) {
385
- return context.parentNodeTypes.includes('ColumnDef');
386
- }
387
- isInValuesContext(context) {
388
- return context.inValuesClause === true;
389
- }
390
- isInSimpleSelectTypeCastContext(context) {
391
- return context.parentNodeTypes.includes('TypeCast') &&
392
- context.parentNodeTypes.includes('ResTarget') &&
393
- !this.isInValuesContext(context);
394
- }
395
- shouldAddPgCatalogPrefix(context) {
396
- const hasSelectStmt = context.parentNodeTypes.includes('SelectStmt');
397
- const hasWithClause = context.parentNodeTypes.includes('WithClause');
398
- const hasCommonTableExpr = context.parentNodeTypes.includes('CommonTableExpr');
399
- return hasSelectStmt && !hasWithClause && !hasCommonTableExpr;
400
- }
401
- TypeName(node, context) {
402
- const result = {};
403
- if (node.names !== undefined) {
404
- let names = Array.isArray(node.names)
405
- ? node.names.map(item => this.transform(item, context))
406
- : this.transform(node.names, context);
407
- // Add pg_catalog prefix for JSON types in CREATE TABLE contexts
408
- if (Array.isArray(names) && names.length === 1) {
409
- const firstElement = names[0];
410
- if (firstElement && typeof firstElement === 'object' && 'String' in firstElement) {
411
- const typeNameStr = firstElement.String.str || firstElement.String.sval;
412
- if (typeNameStr === 'json') {
413
- const hasCreateStmt = context.parentNodeTypes.includes('CreateStmt');
414
- const hasCompositeTypeStmt = context.parentNodeTypes.includes('CompositeTypeStmt');
415
- const hasRangeFunction = context.parentNodeTypes.includes('RangeFunction');
416
- const hasCreateDomainStmt = context.parentNodeTypes.includes('CreateDomainStmt');
417
- const hasColumnDef = context.parentNodeTypes.includes('ColumnDef');
418
- if ((hasCreateStmt || hasCompositeTypeStmt || hasRangeFunction) && hasColumnDef) {
419
- const pgCatalogElement = {
420
- String: {
421
- sval: 'pg_catalog'
422
- }
423
- };
424
- names = [pgCatalogElement, firstElement];
425
- }
426
- else if (hasCreateDomainStmt) {
427
- const pgCatalogElement = {
428
- String: {
429
- sval: 'pg_catalog'
430
- }
431
- };
432
- names = [pgCatalogElement, firstElement];
433
- }
434
- }
435
- }
436
- }
437
- result.names = names;
438
- }
439
- if (node.typeOid !== undefined) {
440
- result.typeOid = node.typeOid;
441
- }
442
- if (node.setof !== undefined) {
443
- result.setof = node.setof;
444
- }
445
- if (node.pct_type !== undefined) {
446
- result.pct_type = node.pct_type;
447
- }
448
- if (node.typmods !== undefined) {
449
- result.typmods = Array.isArray(node.typmods)
450
- ? node.typmods.map(item => this.transform(item, context))
451
- : this.transform(node.typmods, context);
452
- }
453
- if (node.typemod !== undefined) {
454
- result.typemod = node.typemod;
455
- }
456
- if (node.arrayBounds !== undefined) {
457
- result.arrayBounds = Array.isArray(node.arrayBounds)
458
- ? node.arrayBounds.map(item => this.transform(item, context))
459
- : this.transform(node.arrayBounds, context);
460
- }
461
- if (node.location !== undefined) {
462
- result.location = node.location;
463
- }
464
- return { TypeName: result };
465
- }
466
- Alias(node, context) {
467
- return { Alias: node };
468
- }
469
- RangeVar(node, context) {
470
- const result = {};
471
- if (node.catalogname !== undefined) {
472
- result.catalogname = node.catalogname;
473
- }
474
- if (node.schemaname !== undefined) {
475
- result.schemaname = node.schemaname;
476
- }
477
- if (node.relname !== undefined) {
478
- result.relname = node.relname;
479
- }
480
- if (node.inh !== undefined) {
481
- result.inh = node.inh;
482
- }
483
- if (node.relpersistence !== undefined) {
484
- result.relpersistence = node.relpersistence;
485
- }
486
- if (node.alias !== undefined) {
487
- result.alias = this.transform(node.alias, context);
488
- }
489
- if (node.location !== undefined) {
490
- result.location = node.location;
491
- }
492
- return { RangeVar: result };
493
- }
494
- A_ArrayExpr(node, context) {
495
- return { A_ArrayExpr: node };
496
- }
497
- A_Indices(node, context) {
498
- return { A_Indices: node };
499
- }
500
- A_Indirection(node, context) {
501
- return { A_Indirection: node };
502
- }
503
- A_Star(node, context) {
504
- return { A_Star: node };
505
- }
506
- CaseExpr(node, context) {
507
- return { CaseExpr: node };
508
- }
509
- CoalesceExpr(node, context) {
510
- return { CoalesceExpr: node };
511
- }
512
- TypeCast(node, context) {
513
- const result = {};
514
- if (node.arg !== undefined) {
515
- result.arg = this.transform(node.arg, context);
516
- }
517
- if (node.typeName !== undefined) {
518
- let typeName = this.transform(node.typeName, context);
519
- // Add pg_catalog prefix for JSON types in simple SELECT contexts, but NOT in WITH clauses
520
- if (typeName && typeName.names && Array.isArray(typeName.names) && typeName.names.length === 1) {
521
- const firstElement = typeName.names[0];
522
- if (firstElement && typeof firstElement === 'object' && 'String' in firstElement) {
523
- const typeNameStr = firstElement.String.str || firstElement.String.sval;
524
- if (typeNameStr === 'json') {
525
- const hasSelectStmt = context.parentNodeTypes.includes('SelectStmt');
526
- const hasResTarget = context.parentNodeTypes.includes('ResTarget');
527
- const hasList = context.parentNodeTypes.includes('List');
528
- const hasA_Expr = context.parentNodeTypes.includes('A_Expr');
529
- const hasWithClause = context.parentNodeTypes.includes('WithClause');
530
- const hasCommonTableExpr = context.parentNodeTypes.includes('CommonTableExpr');
531
- if (((hasSelectStmt && hasResTarget) || (hasSelectStmt && hasList) || hasA_Expr) && !hasWithClause && !hasCommonTableExpr) {
532
- const pgCatalogElement = {
533
- String: {
534
- sval: 'pg_catalog'
535
- }
536
- };
537
- typeName.names = [pgCatalogElement, firstElement];
538
- }
539
- }
540
- }
541
- }
542
- result.typeName = typeName;
543
- }
544
- if (node.location !== undefined) {
545
- result.location = node.location;
546
- }
547
- return { TypeCast: result };
548
- }
549
- CollateClause(node, context) {
550
- return { CollateClause: node };
551
- }
552
- BooleanTest(node, context) {
553
- return { BooleanTest: node };
554
- }
555
- NullTest(node, context) {
556
- return { NullTest: node };
557
- }
558
- String(node, context) {
559
- return { String: node };
560
- }
561
- Integer(node, context) {
562
- return { Integer: node };
563
- }
564
- Float(node, context) {
565
- return { Float: node };
566
- }
567
- Boolean(node, context) {
568
- return { Boolean: node };
569
- }
570
- BitString(node, context) {
571
- return { BitString: node };
572
- }
573
- // NOTE: there is no Null type in PG17
574
- Null(node, context) {
575
- return { Null: node };
576
- }
577
- List(node, context) {
578
- const result = {};
579
- if (node.items !== undefined) {
580
- result.items = Array.isArray(node.items)
581
- ? node.items.map(item => this.transform(item, context))
582
- : this.transform(node.items, context);
583
- }
584
- return { List: result };
585
- }
586
- CreateStmt(node, context) {
587
- const result = {};
588
- if (node.relation !== undefined) {
589
- result.relation = this.transform(node.relation, context);
590
- }
591
- if (node.tableElts !== undefined) {
592
- result.tableElts = Array.isArray(node.tableElts)
593
- ? node.tableElts.map(item => this.transform(item, context))
594
- : this.transform(node.tableElts, context);
595
- }
596
- if (node.inhRelations !== undefined) {
597
- result.inhRelations = Array.isArray(node.inhRelations)
598
- ? node.inhRelations.map(item => this.transform(item, context))
599
- : this.transform(node.inhRelations, context);
600
- }
601
- if (node.partbound !== undefined) {
602
- result.partbound = this.transform(node.partbound, context);
603
- }
604
- if (node.partspec !== undefined) {
605
- result.partspec = this.transform(node.partspec, context);
606
- }
607
- if (node.ofTypename !== undefined) {
608
- result.ofTypename = this.transform(node.ofTypename, context);
609
- }
610
- if (node.constraints !== undefined) {
611
- result.constraints = Array.isArray(node.constraints)
612
- ? node.constraints.map(item => this.transform(item, context))
613
- : this.transform(node.constraints, context);
614
- }
615
- if (node.options !== undefined) {
616
- result.options = Array.isArray(node.options)
617
- ? node.options.map(item => this.transform(item, context))
618
- : this.transform(node.options, context);
619
- }
620
- if (node.oncommit !== undefined) {
621
- result.oncommit = node.oncommit;
622
- }
623
- if (node.tablespacename !== undefined) {
624
- result.tablespacename = node.tablespacename;
625
- }
626
- if (node.accessMethod !== undefined) {
627
- result.accessMethod = node.accessMethod;
628
- }
629
- if (node.if_not_exists !== undefined) {
630
- result.if_not_exists = node.if_not_exists;
631
- }
632
- return { CreateStmt: result };
633
- }
634
- ColumnDef(node, context) {
635
- const result = {};
636
- if (node.colname !== undefined) {
637
- result.colname = node.colname;
638
- }
639
- if (node.typeName !== undefined) {
640
- const transformedTypeName = this.TypeName(node.typeName, context);
641
- result.typeName = transformedTypeName.TypeName;
642
- }
643
- if (node.inhcount !== undefined) {
644
- result.inhcount = node.inhcount;
645
- }
646
- if (node.is_local !== undefined) {
647
- result.is_local = node.is_local;
648
- }
649
- if (node.is_not_null !== undefined) {
650
- result.is_not_null = node.is_not_null;
651
- }
652
- if (node.is_from_type !== undefined) {
653
- result.is_from_type = node.is_from_type;
654
- }
655
- if (node.storage !== undefined) {
656
- result.storage = node.storage;
657
- }
658
- if (node.raw_default !== undefined) {
659
- result.raw_default = this.transform(node.raw_default, context);
660
- }
661
- if (node.cooked_default !== undefined) {
662
- result.cooked_default = this.transform(node.cooked_default, context);
663
- }
664
- if (node.identity !== undefined) {
665
- result.identity = node.identity;
666
- }
667
- if (node.identitySequence !== undefined) {
668
- result.identitySequence = this.transform(node.identitySequence, context);
669
- }
670
- if (node.generated !== undefined) {
671
- result.generated = node.generated;
672
- }
673
- if (node.collClause !== undefined) {
674
- result.collClause = this.transform(node.collClause, context);
675
- }
676
- if (node.collOid !== undefined) {
677
- result.collOid = node.collOid;
678
- }
679
- if (node.constraints !== undefined) {
680
- result.constraints = Array.isArray(node.constraints)
681
- ? node.constraints.map(item => this.transform(item, context))
682
- : this.transform(node.constraints, context);
683
- }
684
- if (node.fdwoptions !== undefined) {
685
- result.fdwoptions = Array.isArray(node.fdwoptions)
686
- ? node.fdwoptions.map(item => this.transform(item, context))
687
- : this.transform(node.fdwoptions, context);
688
- }
689
- if (node.location !== undefined) {
690
- result.location = node.location;
691
- }
692
- return { ColumnDef: result };
693
- }
694
- Constraint(node, context) {
695
- return { Constraint: node };
696
- }
697
- SubLink(node, context) {
698
- return { SubLink: node };
699
- }
700
- CaseWhen(node, context) {
701
- return { CaseWhen: node };
702
- }
703
- WindowDef(node, context) {
704
- return { WindowDef: node };
705
- }
706
- SortBy(node, context) {
707
- return { SortBy: node };
708
- }
709
- GroupingSet(node, context) {
710
- return { GroupingSet: node };
711
- }
712
- CommonTableExpr(node, context) {
713
- const result = {};
714
- if (node.ctename !== undefined) {
715
- result.ctename = node.ctename;
716
- }
717
- if (node.aliascolnames !== undefined) {
718
- result.aliascolnames = Array.isArray(node.aliascolnames)
719
- ? node.aliascolnames.map(item => this.transform(item, context))
720
- : this.transform(node.aliascolnames, context);
721
- }
722
- if (node.ctematerialized !== undefined) {
723
- result.ctematerialized = node.ctematerialized;
724
- }
725
- if (node.ctequery !== undefined) {
726
- result.ctequery = this.transform(node.ctequery, context);
727
- }
728
- if (node.search_clause !== undefined) {
729
- result.search_clause = this.transform(node.search_clause, context);
730
- }
731
- if (node.cycle_clause !== undefined) {
732
- result.cycle_clause = this.transform(node.cycle_clause, context);
733
- }
734
- if (node.location !== undefined) {
735
- result.location = node.location;
736
- }
737
- return { CommonTableExpr: result };
738
- }
739
- ParamRef(node, context) {
740
- return { ParamRef: node };
741
- }
742
- LockingClause(node, context) {
743
- return { LockingClause: node };
744
- }
745
- MinMaxExpr(node, context) {
746
- return { MinMaxExpr: node };
747
- }
748
- RowExpr(node, context) {
749
- return { RowExpr: node };
750
- }
751
- OpExpr(node, context) {
752
- return { OpExpr: node };
753
- }
754
- DistinctExpr(node, context) {
755
- return { DistinctExpr: node };
756
- }
757
- NullIfExpr(node, context) {
758
- return { NullIfExpr: node };
759
- }
760
- ScalarArrayOpExpr(node, context) {
761
- return { ScalarArrayOpExpr: node };
762
- }
763
- Aggref(node, context) {
764
- return { Aggref: node };
765
- }
766
- WindowFunc(node, context) {
767
- return { WindowFunc: node };
768
- }
769
- FieldSelect(node, context) {
770
- return { FieldSelect: node };
771
- }
772
- RelabelType(node, context) {
773
- return { RelabelType: node };
774
- }
775
- CoerceViaIO(node, context) {
776
- return { CoerceViaIO: node };
777
- }
778
- ArrayCoerceExpr(node, context) {
779
- return { ArrayCoerceExpr: node };
780
- }
781
- ConvertRowtypeExpr(node, context) {
782
- return { ConvertRowtypeExpr: node };
783
- }
784
- NamedArgExpr(node, context) {
785
- return { NamedArgExpr: node };
786
- }
787
- ViewStmt(node, context) {
788
- return { ViewStmt: node };
789
- }
790
- IndexStmt(node, context) {
791
- return { IndexStmt: node };
792
- }
793
- IndexElem(node, context) {
794
- return { IndexElem: node };
795
- }
796
- PartitionElem(node, context) {
797
- return { PartitionElem: node };
798
- }
799
- PartitionCmd(node, context) {
800
- return { PartitionCmd: node };
801
- }
802
- JoinExpr(node, context) {
803
- return { JoinExpr: node };
804
- }
805
- FromExpr(node, context) {
806
- return { FromExpr: node };
807
- }
808
- TransactionStmt(node, context) {
809
- return { TransactionStmt: node };
810
- }
811
- VariableSetStmt(node, context) {
812
- return { VariableSetStmt: node };
813
- }
814
- VariableShowStmt(node, context) {
815
- return { VariableShowStmt: node };
816
- }
817
- CreateSchemaStmt(node, context) {
818
- return { CreateSchemaStmt: node };
819
- }
820
- RoleSpec(node, context) {
821
- return { RoleSpec: node };
822
- }
823
- DropStmt(node, context) {
824
- return { DropStmt: node };
825
- }
826
- TruncateStmt(node, context) {
827
- return { TruncateStmt: node };
828
- }
829
- ReturnStmt(node, context) {
830
- return { ReturnStmt: node };
831
- }
832
- PLAssignStmt(node, context) {
833
- return { PLAssignStmt: node };
834
- }
835
- CopyStmt(node, context) {
836
- return { CopyStmt: node };
837
- }
838
- AlterTableStmt(node, context) {
839
- return { AlterTableStmt: node };
840
- }
841
- AlterTableCmd(node, context) {
842
- return { AlterTableCmd: node };
843
- }
844
- CreateFunctionStmt(node, context) {
845
- return { CreateFunctionStmt: node };
846
- }
847
- FunctionParameter(node, context) {
848
- return { FunctionParameter: node };
849
- }
850
- CreateEnumStmt(node, context) {
851
- return { CreateEnumStmt: node };
852
- }
853
- CreateDomainStmt(node, context) {
854
- const result = {};
855
- if (node.domainname !== undefined) {
856
- result.domainname = Array.isArray(node.domainname)
857
- ? node.domainname.map(item => this.transform(item, context))
858
- : this.transform(node.domainname, context);
859
- }
860
- if (node.typeName !== undefined) {
861
- const transformedTypeName = this.TypeName(node.typeName, context);
862
- result.typeName = transformedTypeName.TypeName;
863
- }
864
- if (node.collClause !== undefined) {
865
- result.collClause = this.transform(node.collClause, context);
866
- }
867
- if (node.constraints !== undefined) {
868
- result.constraints = Array.isArray(node.constraints)
869
- ? node.constraints.map(item => this.transform(item, context))
870
- : this.transform(node.constraints, context);
871
- }
872
- return { CreateDomainStmt: result };
873
- }
874
- CreateRoleStmt(node, context) {
875
- return { CreateRoleStmt: node };
876
- }
877
- DefElem(node, context) {
878
- return { DefElem: node };
879
- }
880
- CreateTableSpaceStmt(node, context) {
881
- return { CreateTableSpaceStmt: node };
882
- }
883
- DropTableSpaceStmt(node, context) {
884
- return { DropTableSpaceStmt: node };
885
- }
886
- AlterTableSpaceOptionsStmt(node, context) {
887
- return { AlterTableSpaceOptionsStmt: node };
888
- }
889
- CreateExtensionStmt(node, context) {
890
- return { CreateExtensionStmt: node };
891
- }
892
- AlterExtensionStmt(node, context) {
893
- return { AlterExtensionStmt: node };
894
- }
895
- CreateFdwStmt(node, context) {
896
- return { CreateFdwStmt: node };
897
- }
898
- SetOperationStmt(node, context) {
899
- return { SetOperationStmt: node };
900
- }
901
- ReplicaIdentityStmt(node, context) {
902
- return { ReplicaIdentityStmt: node };
903
- }
904
- AlterCollationStmt(node, context) {
905
- return { AlterCollationStmt: node };
906
- }
907
- AlterDomainStmt(node, context) {
908
- return { AlterDomainStmt: node };
909
- }
910
- PrepareStmt(node, context) {
911
- return { PrepareStmt: node };
912
- }
913
- ExecuteStmt(node, context) {
914
- return { ExecuteStmt: node };
915
- }
916
- DeallocateStmt(node, context) {
917
- const result = {};
918
- if (node.name !== undefined) {
919
- result.name = node.name;
920
- }
921
- if (node.name === undefined || node.name === null) {
922
- result.isall = true;
923
- }
924
- return { DeallocateStmt: result };
925
- }
926
- NotifyStmt(node, context) {
927
- return { NotifyStmt: node };
928
- }
929
- ListenStmt(node, context) {
930
- return { ListenStmt: node };
931
- }
932
- UnlistenStmt(node, context) {
933
- return { UnlistenStmt: node };
934
- }
935
- CheckPointStmt(node, context) {
936
- return { CheckPointStmt: node };
937
- }
938
- LoadStmt(node, context) {
939
- return { LoadStmt: node };
940
- }
941
- DiscardStmt(node, context) {
942
- return { DiscardStmt: node };
943
- }
944
- CommentStmt(node, context) {
945
- return { CommentStmt: node };
946
- }
947
- LockStmt(node, context) {
948
- return { LockStmt: node };
949
- }
950
- CreatePolicyStmt(node, context) {
951
- return { CreatePolicyStmt: node };
952
- }
953
- AlterPolicyStmt(node, context) {
954
- return { AlterPolicyStmt: node };
955
- }
956
- CreateUserMappingStmt(node, context) {
957
- return { CreateUserMappingStmt: node };
958
- }
959
- CreateStatsStmt(node, context) {
960
- return { CreateStatsStmt: node };
961
- }
962
- StatsElem(node, context) {
963
- return { StatsElem: node };
964
- }
965
- CreatePublicationStmt(node, context) {
966
- return { CreatePublicationStmt: node };
967
- }
968
- CreateSubscriptionStmt(node, context) {
969
- return { CreateSubscriptionStmt: node };
970
- }
971
- AlterPublicationStmt(node, context) {
972
- return { AlterPublicationStmt: node };
973
- }
974
- AlterSubscriptionStmt(node, context) {
975
- return { AlterSubscriptionStmt: node };
976
- }
977
- DropSubscriptionStmt(node, context) {
978
- return { DropSubscriptionStmt: node };
979
- }
980
- DoStmt(node, context) {
981
- return { DoStmt: node };
982
- }
983
- InlineCodeBlock(node, context) {
984
- return { InlineCodeBlock: node };
985
- }
986
- CallContext(node, context) {
987
- return { CallContext: node };
988
- }
989
- ConstraintsSetStmt(node, context) {
990
- return { ConstraintsSetStmt: node };
991
- }
992
- AlterSystemStmt(node, context) {
993
- return { AlterSystemStmt: node };
994
- }
995
- VacuumRelation(node, context) {
996
- return { VacuumRelation: node };
997
- }
998
- DropOwnedStmt(node, context) {
999
- return { DropOwnedStmt: node };
1000
- }
1001
- ReassignOwnedStmt(node, context) {
1002
- return { ReassignOwnedStmt: node };
1003
- }
1004
- AlterTSDictionaryStmt(node, context) {
1005
- return { AlterTSDictionaryStmt: node };
1006
- }
1007
- AlterTSConfigurationStmt(node, context) {
1008
- return { AlterTSConfigurationStmt: node };
1009
- }
1010
- ClosePortalStmt(node, context) {
1011
- return { ClosePortalStmt: node };
1012
- }
1013
- FetchStmt(node, context) {
1014
- return { FetchStmt: node };
1015
- }
1016
- AlterStatsStmt(node, context) {
1017
- return { AlterStatsStmt: node };
1018
- }
1019
- ObjectWithArgs(node, context) {
1020
- return { ObjectWithArgs: node };
1021
- }
1022
- AlterOperatorStmt(node, context) {
1023
- return { AlterOperatorStmt: node };
1024
- }
1025
- AlterFdwStmt(node, context) {
1026
- return { AlterFdwStmt: node };
1027
- }
1028
- CreateForeignServerStmt(node, context) {
1029
- return { CreateForeignServerStmt: node };
1030
- }
1031
- AlterForeignServerStmt(node, context) {
1032
- return { AlterForeignServerStmt: node };
1033
- }
1034
- AlterUserMappingStmt(node, context) {
1035
- return { AlterUserMappingStmt: node };
1036
- }
1037
- DropUserMappingStmt(node, context) {
1038
- return { DropUserMappingStmt: node };
1039
- }
1040
- ImportForeignSchemaStmt(node, context) {
1041
- return { ImportForeignSchemaStmt: node };
1042
- }
1043
- ClusterStmt(node, context) {
1044
- return { ClusterStmt: node };
1045
- }
1046
- VacuumStmt(node, context) {
1047
- return { VacuumStmt: node };
1048
- }
1049
- ExplainStmt(node, context) {
1050
- return { ExplainStmt: node };
1051
- }
1052
- ReindexStmt(node, context) {
1053
- return { ReindexStmt: node };
1054
- }
1055
- CallStmt(node, context) {
1056
- return { CallStmt: node };
1057
- }
1058
- CreatedbStmt(node, context) {
1059
- return { CreatedbStmt: node };
1060
- }
1061
- DropdbStmt(node, context) {
1062
- return { DropdbStmt: node };
1063
- }
1064
- RenameStmt(node, context) {
1065
- return { RenameStmt: node };
1066
- }
1067
- AlterOwnerStmt(node, context) {
1068
- return { AlterOwnerStmt: node };
1069
- }
1070
- GrantStmt(node, context) {
1071
- return { GrantStmt: node };
1072
- }
1073
- GrantRoleStmt(node, context) {
1074
- return { GrantRoleStmt: node };
1075
- }
1076
- SecLabelStmt(node, context) {
1077
- return { SecLabelStmt: node };
1078
- }
1079
- AlterDefaultPrivilegesStmt(node, context) {
1080
- return { AlterDefaultPrivilegesStmt: node };
1081
- }
1082
- CreateConversionStmt(node, context) {
1083
- return { CreateConversionStmt: node };
1084
- }
1085
- CreateCastStmt(node, context) {
1086
- return { CreateCastStmt: node };
1087
- }
1088
- CreatePLangStmt(node, context) {
1089
- return { CreatePLangStmt: node };
1090
- }
1091
- CreateTransformStmt(node, context) {
1092
- return { CreateTransformStmt: node };
1093
- }
1094
- CreateTrigStmt(node, context) {
1095
- return { CreateTrigStmt: node };
1096
- }
1097
- TriggerTransition(node, context) {
1098
- return { TriggerTransition: node };
1099
- }
1100
- CreateEventTrigStmt(node, context) {
1101
- return { CreateEventTrigStmt: node };
1102
- }
1103
- AlterEventTrigStmt(node, context) {
1104
- return { AlterEventTrigStmt: node };
1105
- }
1106
- CreateOpClassStmt(node, context) {
1107
- return { CreateOpClassStmt: node };
1108
- }
1109
- CreateOpFamilyStmt(node, context) {
1110
- return { CreateOpFamilyStmt: node };
1111
- }
1112
- AlterOpFamilyStmt(node, context) {
1113
- return { AlterOpFamilyStmt: node };
1114
- }
1115
- MergeStmt(node, context) {
1116
- return { MergeStmt: node };
1117
- }
1118
- AlterTableMoveAllStmt(node, context) {
1119
- return { AlterTableMoveAllStmt: node };
1120
- }
1121
- CreateSeqStmt(node, context) {
1122
- return { CreateSeqStmt: node };
1123
- }
1124
- AlterSeqStmt(node, context) {
1125
- return { AlterSeqStmt: node };
1126
- }
1127
- CompositeTypeStmt(node, context) {
1128
- const result = {};
1129
- if (node.typevar !== undefined) {
1130
- result.typevar = this.transform(node.typevar, context);
1131
- }
1132
- if (node.coldeflist !== undefined) {
1133
- result.coldeflist = Array.isArray(node.coldeflist)
1134
- ? node.coldeflist.map(item => this.transform(item, context))
1135
- : this.transform(node.coldeflist, context);
1136
- }
1137
- return { CompositeTypeStmt: result };
1138
- }
1139
- CreateRangeStmt(node, context) {
1140
- return { CreateRangeStmt: node };
1141
- }
1142
- AlterEnumStmt(node, context) {
1143
- return { AlterEnumStmt: node };
1144
- }
1145
- AlterTypeStmt(node, context) {
1146
- return { AlterTypeStmt: node };
1147
- }
1148
- AlterRoleStmt(node, context) {
1149
- return { AlterRoleStmt: node };
1150
- }
1151
- DropRoleStmt(node, context) {
1152
- return { DropRoleStmt: node };
1153
- }
1154
- // NOTE PG 17 has a no CreateAggregateStmt?
1155
- // In PostgreSQL 17, the CreateAggregateStmt has been removed from the backend parser infrastructure and replaced by CreateFunctionStmt with a kind = OBJECT_AGGREGATE variant.
1156
- CreateAggregateStmt(node, context) {
1157
- return { CreateAggregateStmt: node };
1158
- }
1159
- CreateTableAsStmt(node, context) {
1160
- return { CreateTableAsStmt: node };
1161
- }
1162
- RefreshMatViewStmt(node, context) {
1163
- return { RefreshMatViewStmt: node };
1164
- }
1165
- AccessPriv(node, context) {
1166
- return { AccessPriv: node };
1167
- }
1168
- DefineStmt(node, context) {
1169
- return { DefineStmt: node };
1170
- }
1171
- AlterDatabaseStmt(node, context) {
1172
- return { AlterDatabaseStmt: node };
1173
- }
1174
- AlterDatabaseRefreshCollStmt(node, context) {
1175
- return { AlterDatabaseRefreshCollStmt: node };
1176
- }
1177
- AlterDatabaseSetStmt(node, context) {
1178
- return { AlterDatabaseSetStmt: node };
1179
- }
1180
- DeclareCursorStmt(node, context) {
1181
- return { DeclareCursorStmt: node };
1182
- }
1183
- PublicationObjSpec(node, context) {
1184
- return { PublicationObjSpec: node };
1185
- }
1186
- PublicationTable(node, context) {
1187
- return { PublicationTable: node };
1188
- }
1189
- CreateAmStmt(node, context) {
1190
- return { CreateAmStmt: node };
1191
- }
1192
- IntoClause(node, context) {
1193
- return { IntoClause: node };
1194
- }
1195
- OnConflictExpr(node, context) {
1196
- return { OnConflictExpr: node };
1197
- }
1198
- ScanToken(node, context) {
1199
- return { ScanToken: node };
1200
- }
1201
- CreateOpClassItem(node, context) {
1202
- return { CreateOpClassItem: node };
1203
- }
1204
- Var(node, context) {
1205
- return { Var: node };
1206
- }
1207
- TableFunc(node, context) {
1208
- return { TableFunc: node };
1209
- }
1210
- RangeTableFunc(node, context) {
1211
- return { RangeTableFunc: node };
1212
- }
1213
- RangeTableFuncCol(node, context) {
1214
- return { RangeTableFuncCol: node };
1215
- }
1216
- JsonArrayQueryConstructor(node, context) {
1217
- return { JsonArrayQueryConstructor: node };
1218
- }
1219
- RangeFunction(node, context) {
1220
- const result = {};
1221
- if (node.lateral !== undefined) {
1222
- result.lateral = node.lateral;
1223
- }
1224
- if (node.ordinality !== undefined) {
1225
- result.ordinality = node.ordinality;
1226
- }
1227
- if (node.is_rowsfrom !== undefined) {
1228
- result.is_rowsfrom = node.is_rowsfrom;
1229
- }
1230
- if (node.functions !== undefined) {
1231
- result.functions = Array.isArray(node.functions)
1232
- ? node.functions.map(item => this.transform(item, context))
1233
- : this.transform(node.functions, context);
1234
- }
1235
- if (node.alias !== undefined) {
1236
- result.alias = this.transform(node.alias, context);
1237
- }
1238
- if (node.coldeflist !== undefined) {
1239
- result.coldeflist = Array.isArray(node.coldeflist)
1240
- ? node.coldeflist.map(item => this.transform(item, context))
1241
- : this.transform(node.coldeflist, context);
1242
- }
1243
- return { RangeFunction: result };
1244
- }
1245
- XmlSerialize(node, context) {
1246
- const result = {};
1247
- if (node.xmloption !== undefined) {
1248
- result.xmloption = node.xmloption;
1249
- }
1250
- if (node.expr !== undefined) {
1251
- result.expr = this.transform(node.expr, context);
1252
- }
1253
- if (node.typeName !== undefined) {
1254
- result.typeName = this.transform(node.typeName, context);
1255
- }
1256
- if (node.location !== undefined) {
1257
- result.location = node.location;
1258
- }
1259
- return { XmlSerialize: result };
1260
- }
1261
- RuleStmt(node, context) {
1262
- return { RuleStmt: node };
1263
- }
1264
- GroupingFunc(node, context) {
1265
- const result = {};
1266
- if (node.args !== undefined) {
1267
- result.args = Array.isArray(node.args)
1268
- ? node.args.map((item) => this.transform(item, context))
1269
- : this.transform(node.args, context);
1270
- }
1271
- if (node.refs !== undefined) {
1272
- result.refs = Array.isArray(node.refs)
1273
- ? node.refs.map((item) => this.transform(item, context))
1274
- : this.transform(node.refs, context);
1275
- }
1276
- if (node.agglevelsup !== undefined) {
1277
- result.agglevelsup = node.agglevelsup;
1278
- }
1279
- if (node.location !== undefined) {
1280
- result.location = node.location;
1281
- }
1282
- return { GroupingFunc: result };
1283
- }
1284
- MultiAssignRef(node, context) {
1285
- const result = {};
1286
- if (node.source !== undefined) {
1287
- result.source = this.transform(node.source, context);
1288
- }
1289
- if (node.colno !== undefined) {
1290
- result.colno = node.colno;
1291
- }
1292
- if (node.ncolumns !== undefined) {
1293
- result.ncolumns = node.ncolumns;
1294
- }
1295
- return { MultiAssignRef: result };
1296
- }
1297
- CurrentOfExpr(node, context) {
1298
- const result = {};
1299
- if (node.cursor_name !== undefined) {
1300
- result.cursor_name = node.cursor_name;
1301
- }
1302
- if (node.cursor_param !== undefined) {
1303
- result.cursor_param = node.cursor_param;
1304
- }
1305
- return { CurrentOfExpr: result };
1306
- }
1307
- TableLikeClause(node, context) {
1308
- return { TableLikeClause: node };
1309
- }
1310
- AlterFunctionStmt(node, context) {
1311
- return { AlterFunctionStmt: node };
1312
- }
1313
- AlterObjectSchemaStmt(node, context) {
1314
- return { AlterObjectSchemaStmt: node };
1315
- }
1316
- AlterRoleSetStmt(node, context) {
1317
- const result = {};
1318
- if (node.role !== undefined) {
1319
- result.role = this.transform(node.role, context);
1320
- }
1321
- if (node.database !== undefined) {
1322
- result.database = node.database;
1323
- }
1324
- if (node.setstmt !== undefined) {
1325
- result.setstmt = this.transform(node.setstmt, context);
1326
- }
1327
- return { AlterRoleSetStmt: result };
1328
- }
1329
- CreateForeignTableStmt(node, context) {
1330
- return { CreateForeignTableStmt: node };
1331
- }
1332
- getFuncformatValue(node, funcname, context) {
1333
- const functionName = this.getFunctionName(node, funcname);
1334
- if (!functionName) {
1335
- return 'COERCE_EXPLICIT_CALL';
1336
- }
1337
- const hasPgCatalogPrefix = this.hasPgCatalogPrefix(funcname);
1338
- const sqlSyntaxFunctions = [
1339
- 'trim', 'ltrim', 'rtrim', 'btrim',
1340
- 'position', 'overlay', 'substring',
1341
- 'extract', 'timezone', 'xmlexists',
1342
- 'current_date', 'current_time', 'current_timestamp',
1343
- 'localtime', 'localtimestamp', 'overlaps'
1344
- ];
1345
- // Handle specific functions that depend on pg_catalog prefix
1346
- if (functionName.toLowerCase() === 'substring') {
1347
- if (hasPgCatalogPrefix) {
1348
- return 'COERCE_SQL_SYNTAX';
1349
- }
1350
- return 'COERCE_EXPLICIT_CALL';
1351
- }
1352
- if (functionName.toLowerCase() === 'ltrim') {
1353
- if (hasPgCatalogPrefix) {
1354
- return 'COERCE_SQL_SYNTAX';
1355
- }
1356
- return 'COERCE_EXPLICIT_CALL';
1357
- }
1358
- if (functionName.toLowerCase() === 'btrim') {
1359
- if (hasPgCatalogPrefix) {
1360
- return 'COERCE_SQL_SYNTAX';
1361
- }
1362
- return 'COERCE_EXPLICIT_CALL';
1363
- }
1364
- if (functionName.toLowerCase() === 'pg_collation_for') {
1365
- if (hasPgCatalogPrefix) {
1366
- return 'COERCE_SQL_SYNTAX';
1367
- }
1368
- return 'COERCE_EXPLICIT_CALL';
1369
- }
1370
- if (sqlSyntaxFunctions.includes(functionName.toLowerCase())) {
1371
- return 'COERCE_SQL_SYNTAX';
1372
- }
1373
- return 'COERCE_EXPLICIT_CALL';
1374
- }
1375
- getFunctionName(node, funcname) {
1376
- const names = funcname || node?.funcname;
1377
- if (names && Array.isArray(names) && names.length > 0) {
1378
- const lastName = names[names.length - 1];
1379
- if (lastName && typeof lastName === 'object' && 'String' in lastName) {
1380
- return lastName.String.str || lastName.String.sval;
1381
- }
1382
- }
1383
- return null;
1384
- }
1385
- hasPgCatalogPrefix(funcname) {
1386
- if (funcname && Array.isArray(funcname) && funcname.length >= 2) {
1387
- const firstElement = funcname[0];
1388
- if (firstElement && typeof firstElement === 'object' && 'String' in firstElement) {
1389
- const prefix = firstElement.String.str || firstElement.String.sval;
1390
- return prefix === 'pg_catalog';
1391
- }
1392
- }
1393
- return false;
1394
- }
1395
- RangeTableSample(node, context) {
1396
- const result = {};
1397
- if (node.relation !== undefined) {
1398
- result.relation = this.transform(node.relation, context);
1399
- }
1400
- if (node.method !== undefined) {
1401
- result.method = Array.isArray(node.method)
1402
- ? node.method.map(item => this.transform(item, context))
1403
- : this.transform(node.method, context);
1404
- }
1405
- if (node.args !== undefined) {
1406
- result.args = Array.isArray(node.args)
1407
- ? node.args.map(item => this.transform(item, context))
1408
- : this.transform(node.args, context);
1409
- }
1410
- if (node.repeatable !== undefined) {
1411
- result.repeatable = this.transform(node.repeatable, context);
1412
- }
1413
- if (node.location !== undefined) {
1414
- result.location = node.location;
1415
- }
1416
- return { RangeTableSample: result };
1417
- }
1418
- SQLValueFunction(node, context) {
1419
- const result = {};
1420
- if (node.op !== undefined) {
1421
- result.op = node.op;
1422
- }
1423
- if (node.type !== undefined) {
1424
- result.type = node.type;
1425
- }
1426
- if (node.typmod !== undefined) {
1427
- result.typmod = node.typmod;
1428
- }
1429
- if (node.location !== undefined) {
1430
- result.location = node.location;
1431
- }
1432
- return { SQLValueFunction: result };
1433
- }
1434
- XmlExpr(node, context) {
1435
- const result = {};
1436
- if (node.op !== undefined) {
1437
- result.op = node.op;
1438
- }
1439
- if (node.name !== undefined) {
1440
- result.name = node.name;
1441
- }
1442
- if (node.named_args !== undefined) {
1443
- result.named_args = Array.isArray(node.named_args)
1444
- ? node.named_args.map(item => this.transform(item, context))
1445
- : this.transform(node.named_args, context);
1446
- }
1447
- if (node.arg_names !== undefined) {
1448
- result.arg_names = Array.isArray(node.arg_names)
1449
- ? node.arg_names.map(item => this.transform(item, context))
1450
- : this.transform(node.arg_names, context);
1451
- }
1452
- if (node.args !== undefined) {
1453
- result.args = Array.isArray(node.args)
1454
- ? node.args.map(item => this.transform(item, context))
1455
- : this.transform(node.args, context);
1456
- }
1457
- if (node.xmloption !== undefined) {
1458
- result.xmloption = node.xmloption;
1459
- }
1460
- if (node.type !== undefined) {
1461
- result.type = node.type;
1462
- }
1463
- if (node.typmod !== undefined) {
1464
- result.typmod = node.typmod;
1465
- }
1466
- if (node.location !== undefined) {
1467
- result.location = node.location;
1468
- }
1469
- return { XmlExpr: result };
1470
- }
1471
- RangeSubselect(node, context) {
1472
- const result = {};
1473
- if (node.lateral !== undefined) {
1474
- result.lateral = node.lateral;
1475
- }
1476
- if (node.subquery !== undefined) {
1477
- result.subquery = this.transform(node.subquery, context);
1478
- }
1479
- if (node.alias !== undefined) {
1480
- result.alias = this.transform(node.alias, context);
1481
- }
1482
- return { RangeSubselect: result };
1483
- }
1484
- SetToDefault(node, context) {
1485
- const result = {};
1486
- if (node.location !== undefined) {
1487
- result.location = node.location;
1488
- }
1489
- return { SetToDefault: result };
1490
- }
1491
- }
1492
- exports.V16ToV17Transformer = V16ToV17Transformer;