pgsql-deparser 17.8.4 → 17.9.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.
- package/README.md +10 -4
- package/deparser.js +129 -38
- package/esm/deparser.js +129 -38
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -80,12 +80,17 @@ npm install pgsql-deparser
|
|
|
80
80
|
While we highly recommend using PG17, for PostgreSQL versions 13-16, use the version-specific packages:
|
|
81
81
|
|
|
82
82
|
```sh
|
|
83
|
-
npm install pgsql-deparser@
|
|
84
|
-
npm install pgsql-deparser@
|
|
85
|
-
npm install pgsql-deparser@
|
|
86
|
-
npm install pgsql-deparser@
|
|
83
|
+
npm install pgsql-deparser@pg13 # PostgreSQL 13
|
|
84
|
+
npm install pgsql-deparser@pg14 # PostgreSQL 14
|
|
85
|
+
npm install pgsql-deparser@pg15 # PostgreSQL 15
|
|
86
|
+
npm install pgsql-deparser@pg16 # PostgreSQL 16
|
|
87
87
|
```
|
|
88
88
|
|
|
89
|
+
**Version Status:**
|
|
90
|
+
- **PG17**: 🚀 Recommended (stable + modern AST)
|
|
91
|
+
- **PG14-16**: ⚠️ Experimental (modern AST, hardening in progress)
|
|
92
|
+
- **PG13**: Stable (legacy AST format)
|
|
93
|
+
|
|
89
94
|
## Options
|
|
90
95
|
|
|
91
96
|
The deparser accepts optional configuration for formatting and output control:
|
|
@@ -150,6 +155,7 @@ Built on the excellent work of several contributors:
|
|
|
150
155
|
* [@pgsql/types](https://www.npmjs.com/package/@pgsql/types): Offers TypeScript type definitions for PostgreSQL AST nodes, facilitating type-safe construction, analysis, and manipulation of ASTs.
|
|
151
156
|
* [@pgsql/enums](https://www.npmjs.com/package/@pgsql/enums): Provides TypeScript enum definitions for PostgreSQL constants, enabling type-safe usage of PostgreSQL enums and constants in your applications.
|
|
152
157
|
* [@pgsql/utils](https://www.npmjs.com/package/@pgsql/utils): A comprehensive utility library for PostgreSQL, offering type-safe AST node creation and enum value conversions, simplifying the construction and manipulation of PostgreSQL ASTs.
|
|
158
|
+
* [@pgsql/traverse](https://www.npmjs.com/package/@pgsql/traverse): PostgreSQL AST traversal utilities for pgsql-parser, providing a visitor pattern for traversing PostgreSQL Abstract Syntax Tree nodes, similar to Babel's traverse functionality but specifically designed for PostgreSQL AST structures.
|
|
153
159
|
* [pg-proto-parser](https://www.npmjs.com/package/pg-proto-parser): A TypeScript tool that parses PostgreSQL Protocol Buffers definitions to generate TypeScript interfaces, utility functions, and JSON mappings for enums.
|
|
154
160
|
* [libpg-query](https://github.com/launchql/libpg-query-node): The real PostgreSQL parser exposed for Node.js, used primarily in `pgsql-parser` for parsing and deparsing SQL queries.
|
|
155
161
|
|
package/deparser.js
CHANGED
|
@@ -2485,30 +2485,61 @@ class Deparser {
|
|
|
2485
2485
|
.map(option => {
|
|
2486
2486
|
if (option.DefElem) {
|
|
2487
2487
|
const defElem = option.DefElem;
|
|
2488
|
-
|
|
2489
|
-
|
|
2488
|
+
if (defElem.defname === 'sequence_name') {
|
|
2489
|
+
if (defElem.arg && defElem.arg.List) {
|
|
2490
|
+
const nameList = list_utils_1.ListUtils.unwrapList(defElem.arg)
|
|
2491
|
+
.map(item => this.visit(item, context))
|
|
2492
|
+
.join('.');
|
|
2493
|
+
return `SEQUENCE NAME ${nameList}`;
|
|
2494
|
+
}
|
|
2495
|
+
return 'SEQUENCE NAME';
|
|
2496
|
+
}
|
|
2497
|
+
else if (defElem.defname === 'start') {
|
|
2498
|
+
const argValue = defElem.arg ? this.visit(defElem.arg, context) : '';
|
|
2490
2499
|
return `START WITH ${argValue}`;
|
|
2491
2500
|
}
|
|
2492
2501
|
else if (defElem.defname === 'increment') {
|
|
2502
|
+
const argValue = defElem.arg ? this.visit(defElem.arg, context) : '';
|
|
2493
2503
|
return `INCREMENT BY ${argValue}`;
|
|
2494
2504
|
}
|
|
2495
2505
|
else if (defElem.defname === 'minvalue') {
|
|
2496
|
-
|
|
2506
|
+
if (defElem.arg) {
|
|
2507
|
+
const argValue = this.visit(defElem.arg, context);
|
|
2508
|
+
return `MINVALUE ${argValue}`;
|
|
2509
|
+
}
|
|
2510
|
+
else {
|
|
2511
|
+
return 'NO MINVALUE';
|
|
2512
|
+
}
|
|
2497
2513
|
}
|
|
2498
2514
|
else if (defElem.defname === 'maxvalue') {
|
|
2499
|
-
|
|
2515
|
+
if (defElem.arg) {
|
|
2516
|
+
const argValue = this.visit(defElem.arg, context);
|
|
2517
|
+
return `MAXVALUE ${argValue}`;
|
|
2518
|
+
}
|
|
2519
|
+
else {
|
|
2520
|
+
return 'NO MAXVALUE';
|
|
2521
|
+
}
|
|
2500
2522
|
}
|
|
2501
2523
|
else if (defElem.defname === 'cache') {
|
|
2524
|
+
const argValue = defElem.arg ? this.visit(defElem.arg, context) : '';
|
|
2502
2525
|
return `CACHE ${argValue}`;
|
|
2503
2526
|
}
|
|
2504
2527
|
else if (defElem.defname === 'cycle') {
|
|
2528
|
+
const argValue = defElem.arg ? this.visit(defElem.arg, context) : '';
|
|
2505
2529
|
return argValue === 'true' ? 'CYCLE' : 'NO CYCLE';
|
|
2506
2530
|
}
|
|
2531
|
+
const argValue = defElem.arg ? this.visit(defElem.arg, context) : '';
|
|
2507
2532
|
return `${defElem.defname.toUpperCase()} ${argValue}`;
|
|
2508
2533
|
}
|
|
2509
2534
|
return this.visit(option, context);
|
|
2510
2535
|
});
|
|
2511
|
-
|
|
2536
|
+
if (context.isPretty()) {
|
|
2537
|
+
const indentedOptions = optionStrs.map(option => context.indent(option));
|
|
2538
|
+
output.push('(\n' + indentedOptions.join('\n') + '\n)');
|
|
2539
|
+
}
|
|
2540
|
+
else {
|
|
2541
|
+
output.push(`(${optionStrs.join(' ')})`);
|
|
2542
|
+
}
|
|
2512
2543
|
}
|
|
2513
2544
|
break;
|
|
2514
2545
|
case 'CONSTR_PRIMARY':
|
|
@@ -4327,10 +4358,7 @@ class Deparser {
|
|
|
4327
4358
|
const commandsStr = commands
|
|
4328
4359
|
.map(cmd => {
|
|
4329
4360
|
const cmdStr = this.visit(cmd, alterContext);
|
|
4330
|
-
|
|
4331
|
-
return context.newline() + context.indent(cmdStr);
|
|
4332
|
-
}
|
|
4333
|
-
return cmdStr;
|
|
4361
|
+
return context.newline() + context.indent(cmdStr);
|
|
4334
4362
|
})
|
|
4335
4363
|
.join(',');
|
|
4336
4364
|
output.push(commandsStr);
|
|
@@ -4360,35 +4388,99 @@ class Deparser {
|
|
|
4360
4388
|
}
|
|
4361
4389
|
if (node.def) {
|
|
4362
4390
|
const colDefData = this.getNodeData(node.def);
|
|
4363
|
-
|
|
4364
|
-
|
|
4365
|
-
|
|
4366
|
-
|
|
4367
|
-
|
|
4368
|
-
|
|
4369
|
-
|
|
4370
|
-
|
|
4371
|
-
|
|
4372
|
-
|
|
4373
|
-
|
|
4374
|
-
|
|
4375
|
-
|
|
4376
|
-
|
|
4377
|
-
|
|
4378
|
-
|
|
4379
|
-
const
|
|
4380
|
-
|
|
4381
|
-
|
|
4382
|
-
|
|
4383
|
-
|
|
4384
|
-
|
|
4385
|
-
|
|
4386
|
-
|
|
4391
|
+
if (context.isPretty()) {
|
|
4392
|
+
const parts = [];
|
|
4393
|
+
const indentedParts = [];
|
|
4394
|
+
if (colDefData.colname) {
|
|
4395
|
+
parts.push(quote_utils_1.QuoteUtils.quote(colDefData.colname));
|
|
4396
|
+
}
|
|
4397
|
+
if (colDefData.typeName) {
|
|
4398
|
+
parts.push(this.TypeName(colDefData.typeName, context));
|
|
4399
|
+
}
|
|
4400
|
+
if (colDefData.is_not_null) {
|
|
4401
|
+
indentedParts.push('NOT NULL');
|
|
4402
|
+
}
|
|
4403
|
+
if (colDefData.collClause) {
|
|
4404
|
+
indentedParts.push(this.CollateClause(colDefData.collClause, context));
|
|
4405
|
+
}
|
|
4406
|
+
if (colDefData.constraints) {
|
|
4407
|
+
const constraints = list_utils_1.ListUtils.unwrapList(colDefData.constraints);
|
|
4408
|
+
constraints.forEach(constraint => {
|
|
4409
|
+
const columnConstraintContext = context.spawn('ColumnDef', { isColumnConstraint: true });
|
|
4410
|
+
const constraintStr = this.visit(constraint, columnConstraintContext);
|
|
4411
|
+
if (constraintStr.includes('REFERENCES') && constraintStr.includes('ON DELETE')) {
|
|
4412
|
+
const refMatch = constraintStr.match(/^(.*REFERENCES[^)]*\([^)]*\))\s*(ON\s+DELETE\s+CASCADE.*)$/);
|
|
4413
|
+
if (refMatch) {
|
|
4414
|
+
indentedParts.push(refMatch[1]);
|
|
4415
|
+
indentedParts.push(refMatch[2]);
|
|
4416
|
+
}
|
|
4417
|
+
else {
|
|
4418
|
+
indentedParts.push(constraintStr);
|
|
4419
|
+
}
|
|
4420
|
+
}
|
|
4421
|
+
else if (constraintStr === 'UNIQUE' && colDefData.raw_default) {
|
|
4422
|
+
const defaultStr = 'DEFAULT ' + this.visit(colDefData.raw_default, context);
|
|
4423
|
+
indentedParts.push('UNIQUE ' + defaultStr);
|
|
4424
|
+
}
|
|
4425
|
+
else {
|
|
4426
|
+
indentedParts.push(constraintStr);
|
|
4427
|
+
}
|
|
4428
|
+
});
|
|
4429
|
+
}
|
|
4430
|
+
if (colDefData.raw_default && !colDefData.constraints?.some((c) => {
|
|
4431
|
+
const constraintStr = this.visit(c, context.spawn('ColumnDef', { isColumnConstraint: true }));
|
|
4432
|
+
return constraintStr === 'UNIQUE';
|
|
4433
|
+
})) {
|
|
4434
|
+
const defaultStr = 'DEFAULT ' + this.visit(colDefData.raw_default, context);
|
|
4435
|
+
indentedParts.push(defaultStr);
|
|
4436
|
+
}
|
|
4437
|
+
if (colDefData.fdwoptions && colDefData.fdwoptions.length > 0) {
|
|
4438
|
+
indentedParts.push('OPTIONS');
|
|
4439
|
+
const columnContext = context.spawn('ColumnDef');
|
|
4440
|
+
const options = list_utils_1.ListUtils.unwrapList(colDefData.fdwoptions).map(opt => this.visit(opt, columnContext));
|
|
4441
|
+
indentedParts.push(`(${options.join(', ')})`);
|
|
4442
|
+
}
|
|
4443
|
+
let result = parts.join(' ');
|
|
4444
|
+
if (indentedParts.length > 0) {
|
|
4445
|
+
const indentedStr = indentedParts.map(part => context.indent(part)).join(context.newline());
|
|
4446
|
+
result += context.newline() + indentedStr;
|
|
4447
|
+
}
|
|
4448
|
+
output.push(result);
|
|
4387
4449
|
}
|
|
4388
|
-
|
|
4389
|
-
parts
|
|
4450
|
+
else {
|
|
4451
|
+
const parts = [];
|
|
4452
|
+
if (colDefData.colname) {
|
|
4453
|
+
parts.push(quote_utils_1.QuoteUtils.quote(colDefData.colname));
|
|
4454
|
+
}
|
|
4455
|
+
if (colDefData.typeName) {
|
|
4456
|
+
parts.push(this.TypeName(colDefData.typeName, context));
|
|
4457
|
+
}
|
|
4458
|
+
if (colDefData.collClause) {
|
|
4459
|
+
parts.push(this.CollateClause(colDefData.collClause, context));
|
|
4460
|
+
}
|
|
4461
|
+
if (colDefData.fdwoptions && colDefData.fdwoptions.length > 0) {
|
|
4462
|
+
parts.push('OPTIONS');
|
|
4463
|
+
const columnContext = context.spawn('ColumnDef');
|
|
4464
|
+
const options = list_utils_1.ListUtils.unwrapList(colDefData.fdwoptions).map(opt => this.visit(opt, columnContext));
|
|
4465
|
+
parts.push(`(${options.join(', ')})`);
|
|
4466
|
+
}
|
|
4467
|
+
if (colDefData.constraints) {
|
|
4468
|
+
const constraints = list_utils_1.ListUtils.unwrapList(colDefData.constraints);
|
|
4469
|
+
const constraintStrs = constraints.map(constraint => {
|
|
4470
|
+
const columnConstraintContext = context.spawn('ColumnDef', { isColumnConstraint: true });
|
|
4471
|
+
return this.visit(constraint, columnConstraintContext);
|
|
4472
|
+
});
|
|
4473
|
+
parts.push(...constraintStrs);
|
|
4474
|
+
}
|
|
4475
|
+
if (colDefData.raw_default) {
|
|
4476
|
+
parts.push('DEFAULT');
|
|
4477
|
+
parts.push(this.visit(colDefData.raw_default, context));
|
|
4478
|
+
}
|
|
4479
|
+
if (colDefData.is_not_null) {
|
|
4480
|
+
parts.push('NOT NULL');
|
|
4481
|
+
}
|
|
4482
|
+
output.push(parts.join(' '));
|
|
4390
4483
|
}
|
|
4391
|
-
output.push(parts.join(' '));
|
|
4392
4484
|
}
|
|
4393
4485
|
if (node.behavior === 'DROP_CASCADE') {
|
|
4394
4486
|
output.push('CASCADE');
|
|
@@ -4904,11 +4996,10 @@ class Deparser {
|
|
|
4904
4996
|
if (node.name) {
|
|
4905
4997
|
output.push(quote_utils_1.QuoteUtils.quote(node.name));
|
|
4906
4998
|
}
|
|
4907
|
-
output.push('ADD
|
|
4999
|
+
output.push('ADD');
|
|
4908
5000
|
if (node.def) {
|
|
4909
5001
|
output.push(this.visit(node.def, context));
|
|
4910
5002
|
}
|
|
4911
|
-
output.push('AS IDENTITY');
|
|
4912
5003
|
break;
|
|
4913
5004
|
case 'AT_SetIdentity':
|
|
4914
5005
|
output.push('ALTER COLUMN');
|
package/esm/deparser.js
CHANGED
|
@@ -2482,30 +2482,61 @@ export class Deparser {
|
|
|
2482
2482
|
.map(option => {
|
|
2483
2483
|
if (option.DefElem) {
|
|
2484
2484
|
const defElem = option.DefElem;
|
|
2485
|
-
|
|
2486
|
-
|
|
2485
|
+
if (defElem.defname === 'sequence_name') {
|
|
2486
|
+
if (defElem.arg && defElem.arg.List) {
|
|
2487
|
+
const nameList = ListUtils.unwrapList(defElem.arg)
|
|
2488
|
+
.map(item => this.visit(item, context))
|
|
2489
|
+
.join('.');
|
|
2490
|
+
return `SEQUENCE NAME ${nameList}`;
|
|
2491
|
+
}
|
|
2492
|
+
return 'SEQUENCE NAME';
|
|
2493
|
+
}
|
|
2494
|
+
else if (defElem.defname === 'start') {
|
|
2495
|
+
const argValue = defElem.arg ? this.visit(defElem.arg, context) : '';
|
|
2487
2496
|
return `START WITH ${argValue}`;
|
|
2488
2497
|
}
|
|
2489
2498
|
else if (defElem.defname === 'increment') {
|
|
2499
|
+
const argValue = defElem.arg ? this.visit(defElem.arg, context) : '';
|
|
2490
2500
|
return `INCREMENT BY ${argValue}`;
|
|
2491
2501
|
}
|
|
2492
2502
|
else if (defElem.defname === 'minvalue') {
|
|
2493
|
-
|
|
2503
|
+
if (defElem.arg) {
|
|
2504
|
+
const argValue = this.visit(defElem.arg, context);
|
|
2505
|
+
return `MINVALUE ${argValue}`;
|
|
2506
|
+
}
|
|
2507
|
+
else {
|
|
2508
|
+
return 'NO MINVALUE';
|
|
2509
|
+
}
|
|
2494
2510
|
}
|
|
2495
2511
|
else if (defElem.defname === 'maxvalue') {
|
|
2496
|
-
|
|
2512
|
+
if (defElem.arg) {
|
|
2513
|
+
const argValue = this.visit(defElem.arg, context);
|
|
2514
|
+
return `MAXVALUE ${argValue}`;
|
|
2515
|
+
}
|
|
2516
|
+
else {
|
|
2517
|
+
return 'NO MAXVALUE';
|
|
2518
|
+
}
|
|
2497
2519
|
}
|
|
2498
2520
|
else if (defElem.defname === 'cache') {
|
|
2521
|
+
const argValue = defElem.arg ? this.visit(defElem.arg, context) : '';
|
|
2499
2522
|
return `CACHE ${argValue}`;
|
|
2500
2523
|
}
|
|
2501
2524
|
else if (defElem.defname === 'cycle') {
|
|
2525
|
+
const argValue = defElem.arg ? this.visit(defElem.arg, context) : '';
|
|
2502
2526
|
return argValue === 'true' ? 'CYCLE' : 'NO CYCLE';
|
|
2503
2527
|
}
|
|
2528
|
+
const argValue = defElem.arg ? this.visit(defElem.arg, context) : '';
|
|
2504
2529
|
return `${defElem.defname.toUpperCase()} ${argValue}`;
|
|
2505
2530
|
}
|
|
2506
2531
|
return this.visit(option, context);
|
|
2507
2532
|
});
|
|
2508
|
-
|
|
2533
|
+
if (context.isPretty()) {
|
|
2534
|
+
const indentedOptions = optionStrs.map(option => context.indent(option));
|
|
2535
|
+
output.push('(\n' + indentedOptions.join('\n') + '\n)');
|
|
2536
|
+
}
|
|
2537
|
+
else {
|
|
2538
|
+
output.push(`(${optionStrs.join(' ')})`);
|
|
2539
|
+
}
|
|
2509
2540
|
}
|
|
2510
2541
|
break;
|
|
2511
2542
|
case 'CONSTR_PRIMARY':
|
|
@@ -4324,10 +4355,7 @@ export class Deparser {
|
|
|
4324
4355
|
const commandsStr = commands
|
|
4325
4356
|
.map(cmd => {
|
|
4326
4357
|
const cmdStr = this.visit(cmd, alterContext);
|
|
4327
|
-
|
|
4328
|
-
return context.newline() + context.indent(cmdStr);
|
|
4329
|
-
}
|
|
4330
|
-
return cmdStr;
|
|
4358
|
+
return context.newline() + context.indent(cmdStr);
|
|
4331
4359
|
})
|
|
4332
4360
|
.join(',');
|
|
4333
4361
|
output.push(commandsStr);
|
|
@@ -4357,35 +4385,99 @@ export class Deparser {
|
|
|
4357
4385
|
}
|
|
4358
4386
|
if (node.def) {
|
|
4359
4387
|
const colDefData = this.getNodeData(node.def);
|
|
4360
|
-
|
|
4361
|
-
|
|
4362
|
-
|
|
4363
|
-
|
|
4364
|
-
|
|
4365
|
-
|
|
4366
|
-
|
|
4367
|
-
|
|
4368
|
-
|
|
4369
|
-
|
|
4370
|
-
|
|
4371
|
-
|
|
4372
|
-
|
|
4373
|
-
|
|
4374
|
-
|
|
4375
|
-
|
|
4376
|
-
const
|
|
4377
|
-
|
|
4378
|
-
|
|
4379
|
-
|
|
4380
|
-
|
|
4381
|
-
|
|
4382
|
-
|
|
4383
|
-
|
|
4388
|
+
if (context.isPretty()) {
|
|
4389
|
+
const parts = [];
|
|
4390
|
+
const indentedParts = [];
|
|
4391
|
+
if (colDefData.colname) {
|
|
4392
|
+
parts.push(QuoteUtils.quote(colDefData.colname));
|
|
4393
|
+
}
|
|
4394
|
+
if (colDefData.typeName) {
|
|
4395
|
+
parts.push(this.TypeName(colDefData.typeName, context));
|
|
4396
|
+
}
|
|
4397
|
+
if (colDefData.is_not_null) {
|
|
4398
|
+
indentedParts.push('NOT NULL');
|
|
4399
|
+
}
|
|
4400
|
+
if (colDefData.collClause) {
|
|
4401
|
+
indentedParts.push(this.CollateClause(colDefData.collClause, context));
|
|
4402
|
+
}
|
|
4403
|
+
if (colDefData.constraints) {
|
|
4404
|
+
const constraints = ListUtils.unwrapList(colDefData.constraints);
|
|
4405
|
+
constraints.forEach(constraint => {
|
|
4406
|
+
const columnConstraintContext = context.spawn('ColumnDef', { isColumnConstraint: true });
|
|
4407
|
+
const constraintStr = this.visit(constraint, columnConstraintContext);
|
|
4408
|
+
if (constraintStr.includes('REFERENCES') && constraintStr.includes('ON DELETE')) {
|
|
4409
|
+
const refMatch = constraintStr.match(/^(.*REFERENCES[^)]*\([^)]*\))\s*(ON\s+DELETE\s+CASCADE.*)$/);
|
|
4410
|
+
if (refMatch) {
|
|
4411
|
+
indentedParts.push(refMatch[1]);
|
|
4412
|
+
indentedParts.push(refMatch[2]);
|
|
4413
|
+
}
|
|
4414
|
+
else {
|
|
4415
|
+
indentedParts.push(constraintStr);
|
|
4416
|
+
}
|
|
4417
|
+
}
|
|
4418
|
+
else if (constraintStr === 'UNIQUE' && colDefData.raw_default) {
|
|
4419
|
+
const defaultStr = 'DEFAULT ' + this.visit(colDefData.raw_default, context);
|
|
4420
|
+
indentedParts.push('UNIQUE ' + defaultStr);
|
|
4421
|
+
}
|
|
4422
|
+
else {
|
|
4423
|
+
indentedParts.push(constraintStr);
|
|
4424
|
+
}
|
|
4425
|
+
});
|
|
4426
|
+
}
|
|
4427
|
+
if (colDefData.raw_default && !colDefData.constraints?.some((c) => {
|
|
4428
|
+
const constraintStr = this.visit(c, context.spawn('ColumnDef', { isColumnConstraint: true }));
|
|
4429
|
+
return constraintStr === 'UNIQUE';
|
|
4430
|
+
})) {
|
|
4431
|
+
const defaultStr = 'DEFAULT ' + this.visit(colDefData.raw_default, context);
|
|
4432
|
+
indentedParts.push(defaultStr);
|
|
4433
|
+
}
|
|
4434
|
+
if (colDefData.fdwoptions && colDefData.fdwoptions.length > 0) {
|
|
4435
|
+
indentedParts.push('OPTIONS');
|
|
4436
|
+
const columnContext = context.spawn('ColumnDef');
|
|
4437
|
+
const options = ListUtils.unwrapList(colDefData.fdwoptions).map(opt => this.visit(opt, columnContext));
|
|
4438
|
+
indentedParts.push(`(${options.join(', ')})`);
|
|
4439
|
+
}
|
|
4440
|
+
let result = parts.join(' ');
|
|
4441
|
+
if (indentedParts.length > 0) {
|
|
4442
|
+
const indentedStr = indentedParts.map(part => context.indent(part)).join(context.newline());
|
|
4443
|
+
result += context.newline() + indentedStr;
|
|
4444
|
+
}
|
|
4445
|
+
output.push(result);
|
|
4384
4446
|
}
|
|
4385
|
-
|
|
4386
|
-
parts
|
|
4447
|
+
else {
|
|
4448
|
+
const parts = [];
|
|
4449
|
+
if (colDefData.colname) {
|
|
4450
|
+
parts.push(QuoteUtils.quote(colDefData.colname));
|
|
4451
|
+
}
|
|
4452
|
+
if (colDefData.typeName) {
|
|
4453
|
+
parts.push(this.TypeName(colDefData.typeName, context));
|
|
4454
|
+
}
|
|
4455
|
+
if (colDefData.collClause) {
|
|
4456
|
+
parts.push(this.CollateClause(colDefData.collClause, context));
|
|
4457
|
+
}
|
|
4458
|
+
if (colDefData.fdwoptions && colDefData.fdwoptions.length > 0) {
|
|
4459
|
+
parts.push('OPTIONS');
|
|
4460
|
+
const columnContext = context.spawn('ColumnDef');
|
|
4461
|
+
const options = ListUtils.unwrapList(colDefData.fdwoptions).map(opt => this.visit(opt, columnContext));
|
|
4462
|
+
parts.push(`(${options.join(', ')})`);
|
|
4463
|
+
}
|
|
4464
|
+
if (colDefData.constraints) {
|
|
4465
|
+
const constraints = ListUtils.unwrapList(colDefData.constraints);
|
|
4466
|
+
const constraintStrs = constraints.map(constraint => {
|
|
4467
|
+
const columnConstraintContext = context.spawn('ColumnDef', { isColumnConstraint: true });
|
|
4468
|
+
return this.visit(constraint, columnConstraintContext);
|
|
4469
|
+
});
|
|
4470
|
+
parts.push(...constraintStrs);
|
|
4471
|
+
}
|
|
4472
|
+
if (colDefData.raw_default) {
|
|
4473
|
+
parts.push('DEFAULT');
|
|
4474
|
+
parts.push(this.visit(colDefData.raw_default, context));
|
|
4475
|
+
}
|
|
4476
|
+
if (colDefData.is_not_null) {
|
|
4477
|
+
parts.push('NOT NULL');
|
|
4478
|
+
}
|
|
4479
|
+
output.push(parts.join(' '));
|
|
4387
4480
|
}
|
|
4388
|
-
output.push(parts.join(' '));
|
|
4389
4481
|
}
|
|
4390
4482
|
if (node.behavior === 'DROP_CASCADE') {
|
|
4391
4483
|
output.push('CASCADE');
|
|
@@ -4901,11 +4993,10 @@ export class Deparser {
|
|
|
4901
4993
|
if (node.name) {
|
|
4902
4994
|
output.push(QuoteUtils.quote(node.name));
|
|
4903
4995
|
}
|
|
4904
|
-
output.push('ADD
|
|
4996
|
+
output.push('ADD');
|
|
4905
4997
|
if (node.def) {
|
|
4906
4998
|
output.push(this.visit(node.def, context));
|
|
4907
4999
|
}
|
|
4908
|
-
output.push('AS IDENTITY');
|
|
4909
5000
|
break;
|
|
4910
5001
|
case 'AT_SetIdentity':
|
|
4911
5002
|
output.push('ALTER COLUMN');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pgsql-deparser",
|
|
3
|
-
"version": "17.
|
|
3
|
+
"version": "17.9.0",
|
|
4
4
|
"author": "Dan Lynch <pyramation@gmail.com>",
|
|
5
5
|
"description": "PostgreSQL AST Deparser",
|
|
6
6
|
"main": "index.js",
|
|
@@ -58,5 +58,5 @@
|
|
|
58
58
|
"dependencies": {
|
|
59
59
|
"@pgsql/types": "^17.6.1"
|
|
60
60
|
},
|
|
61
|
-
"gitHead": "
|
|
61
|
+
"gitHead": "c2982c6793a8e92395a32e5d9d656b04e060466b"
|
|
62
62
|
}
|