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