pgsql-deparser 17.8.5 → 17.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/deparser.js +147 -38
- package/esm/deparser.js +147 -38
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -155,6 +155,7 @@ Built on the excellent work of several contributors:
|
|
|
155
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.
|
|
156
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.
|
|
157
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.
|
|
158
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.
|
|
159
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.
|
|
160
161
|
|
package/deparser.js
CHANGED
|
@@ -1711,6 +1711,24 @@ class Deparser {
|
|
|
1711
1711
|
typeName = 'time with time zone';
|
|
1712
1712
|
}
|
|
1713
1713
|
}
|
|
1714
|
+
else if (type === 'timestamp') {
|
|
1715
|
+
if (args) {
|
|
1716
|
+
typeName = `timestamp(${args})`;
|
|
1717
|
+
args = null; // Don't apply args again in mods()
|
|
1718
|
+
}
|
|
1719
|
+
else {
|
|
1720
|
+
typeName = 'timestamp';
|
|
1721
|
+
}
|
|
1722
|
+
}
|
|
1723
|
+
else if (type === 'time') {
|
|
1724
|
+
if (args) {
|
|
1725
|
+
typeName = `time(${args})`;
|
|
1726
|
+
args = null; // Don't apply args again in mods()
|
|
1727
|
+
}
|
|
1728
|
+
else {
|
|
1729
|
+
typeName = 'time';
|
|
1730
|
+
}
|
|
1731
|
+
}
|
|
1714
1732
|
let result = mods(typeName, args);
|
|
1715
1733
|
if (node.arrayBounds && node.arrayBounds.length > 0) {
|
|
1716
1734
|
result += formatArrayBounds(node.arrayBounds);
|
|
@@ -2485,30 +2503,61 @@ class Deparser {
|
|
|
2485
2503
|
.map(option => {
|
|
2486
2504
|
if (option.DefElem) {
|
|
2487
2505
|
const defElem = option.DefElem;
|
|
2488
|
-
|
|
2489
|
-
|
|
2506
|
+
if (defElem.defname === 'sequence_name') {
|
|
2507
|
+
if (defElem.arg && defElem.arg.List) {
|
|
2508
|
+
const nameList = list_utils_1.ListUtils.unwrapList(defElem.arg)
|
|
2509
|
+
.map(item => this.visit(item, context))
|
|
2510
|
+
.join('.');
|
|
2511
|
+
return `SEQUENCE NAME ${nameList}`;
|
|
2512
|
+
}
|
|
2513
|
+
return 'SEQUENCE NAME';
|
|
2514
|
+
}
|
|
2515
|
+
else if (defElem.defname === 'start') {
|
|
2516
|
+
const argValue = defElem.arg ? this.visit(defElem.arg, context) : '';
|
|
2490
2517
|
return `START WITH ${argValue}`;
|
|
2491
2518
|
}
|
|
2492
2519
|
else if (defElem.defname === 'increment') {
|
|
2520
|
+
const argValue = defElem.arg ? this.visit(defElem.arg, context) : '';
|
|
2493
2521
|
return `INCREMENT BY ${argValue}`;
|
|
2494
2522
|
}
|
|
2495
2523
|
else if (defElem.defname === 'minvalue') {
|
|
2496
|
-
|
|
2524
|
+
if (defElem.arg) {
|
|
2525
|
+
const argValue = this.visit(defElem.arg, context);
|
|
2526
|
+
return `MINVALUE ${argValue}`;
|
|
2527
|
+
}
|
|
2528
|
+
else {
|
|
2529
|
+
return 'NO MINVALUE';
|
|
2530
|
+
}
|
|
2497
2531
|
}
|
|
2498
2532
|
else if (defElem.defname === 'maxvalue') {
|
|
2499
|
-
|
|
2533
|
+
if (defElem.arg) {
|
|
2534
|
+
const argValue = this.visit(defElem.arg, context);
|
|
2535
|
+
return `MAXVALUE ${argValue}`;
|
|
2536
|
+
}
|
|
2537
|
+
else {
|
|
2538
|
+
return 'NO MAXVALUE';
|
|
2539
|
+
}
|
|
2500
2540
|
}
|
|
2501
2541
|
else if (defElem.defname === 'cache') {
|
|
2542
|
+
const argValue = defElem.arg ? this.visit(defElem.arg, context) : '';
|
|
2502
2543
|
return `CACHE ${argValue}`;
|
|
2503
2544
|
}
|
|
2504
2545
|
else if (defElem.defname === 'cycle') {
|
|
2546
|
+
const argValue = defElem.arg ? this.visit(defElem.arg, context) : '';
|
|
2505
2547
|
return argValue === 'true' ? 'CYCLE' : 'NO CYCLE';
|
|
2506
2548
|
}
|
|
2549
|
+
const argValue = defElem.arg ? this.visit(defElem.arg, context) : '';
|
|
2507
2550
|
return `${defElem.defname.toUpperCase()} ${argValue}`;
|
|
2508
2551
|
}
|
|
2509
2552
|
return this.visit(option, context);
|
|
2510
2553
|
});
|
|
2511
|
-
|
|
2554
|
+
if (context.isPretty()) {
|
|
2555
|
+
const indentedOptions = optionStrs.map(option => context.indent(option));
|
|
2556
|
+
output.push('(\n' + indentedOptions.join('\n') + '\n)');
|
|
2557
|
+
}
|
|
2558
|
+
else {
|
|
2559
|
+
output.push(`(${optionStrs.join(' ')})`);
|
|
2560
|
+
}
|
|
2512
2561
|
}
|
|
2513
2562
|
break;
|
|
2514
2563
|
case 'CONSTR_PRIMARY':
|
|
@@ -4327,10 +4376,7 @@ class Deparser {
|
|
|
4327
4376
|
const commandsStr = commands
|
|
4328
4377
|
.map(cmd => {
|
|
4329
4378
|
const cmdStr = this.visit(cmd, alterContext);
|
|
4330
|
-
|
|
4331
|
-
return context.newline() + context.indent(cmdStr);
|
|
4332
|
-
}
|
|
4333
|
-
return cmdStr;
|
|
4379
|
+
return context.newline() + context.indent(cmdStr);
|
|
4334
4380
|
})
|
|
4335
4381
|
.join(',');
|
|
4336
4382
|
output.push(commandsStr);
|
|
@@ -4360,35 +4406,99 @@ class Deparser {
|
|
|
4360
4406
|
}
|
|
4361
4407
|
if (node.def) {
|
|
4362
4408
|
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
|
-
|
|
4409
|
+
if (context.isPretty()) {
|
|
4410
|
+
const parts = [];
|
|
4411
|
+
const indentedParts = [];
|
|
4412
|
+
if (colDefData.colname) {
|
|
4413
|
+
parts.push(quote_utils_1.QuoteUtils.quote(colDefData.colname));
|
|
4414
|
+
}
|
|
4415
|
+
if (colDefData.typeName) {
|
|
4416
|
+
parts.push(this.TypeName(colDefData.typeName, context));
|
|
4417
|
+
}
|
|
4418
|
+
if (colDefData.is_not_null) {
|
|
4419
|
+
indentedParts.push('NOT NULL');
|
|
4420
|
+
}
|
|
4421
|
+
if (colDefData.collClause) {
|
|
4422
|
+
indentedParts.push(this.CollateClause(colDefData.collClause, context));
|
|
4423
|
+
}
|
|
4424
|
+
if (colDefData.constraints) {
|
|
4425
|
+
const constraints = list_utils_1.ListUtils.unwrapList(colDefData.constraints);
|
|
4426
|
+
constraints.forEach(constraint => {
|
|
4427
|
+
const columnConstraintContext = context.spawn('ColumnDef', { isColumnConstraint: true });
|
|
4428
|
+
const constraintStr = this.visit(constraint, columnConstraintContext);
|
|
4429
|
+
if (constraintStr.includes('REFERENCES') && constraintStr.includes('ON DELETE')) {
|
|
4430
|
+
const refMatch = constraintStr.match(/^(.*REFERENCES[^)]*\([^)]*\))\s*(ON\s+DELETE\s+CASCADE.*)$/);
|
|
4431
|
+
if (refMatch) {
|
|
4432
|
+
indentedParts.push(refMatch[1]);
|
|
4433
|
+
indentedParts.push(refMatch[2]);
|
|
4434
|
+
}
|
|
4435
|
+
else {
|
|
4436
|
+
indentedParts.push(constraintStr);
|
|
4437
|
+
}
|
|
4438
|
+
}
|
|
4439
|
+
else if (constraintStr === 'UNIQUE' && colDefData.raw_default) {
|
|
4440
|
+
const defaultStr = 'DEFAULT ' + this.visit(colDefData.raw_default, context);
|
|
4441
|
+
indentedParts.push('UNIQUE ' + defaultStr);
|
|
4442
|
+
}
|
|
4443
|
+
else {
|
|
4444
|
+
indentedParts.push(constraintStr);
|
|
4445
|
+
}
|
|
4446
|
+
});
|
|
4447
|
+
}
|
|
4448
|
+
if (colDefData.raw_default && !colDefData.constraints?.some((c) => {
|
|
4449
|
+
const constraintStr = this.visit(c, context.spawn('ColumnDef', { isColumnConstraint: true }));
|
|
4450
|
+
return constraintStr === 'UNIQUE';
|
|
4451
|
+
})) {
|
|
4452
|
+
const defaultStr = 'DEFAULT ' + this.visit(colDefData.raw_default, context);
|
|
4453
|
+
indentedParts.push(defaultStr);
|
|
4454
|
+
}
|
|
4455
|
+
if (colDefData.fdwoptions && colDefData.fdwoptions.length > 0) {
|
|
4456
|
+
indentedParts.push('OPTIONS');
|
|
4457
|
+
const columnContext = context.spawn('ColumnDef');
|
|
4458
|
+
const options = list_utils_1.ListUtils.unwrapList(colDefData.fdwoptions).map(opt => this.visit(opt, columnContext));
|
|
4459
|
+
indentedParts.push(`(${options.join(', ')})`);
|
|
4460
|
+
}
|
|
4461
|
+
let result = parts.join(' ');
|
|
4462
|
+
if (indentedParts.length > 0) {
|
|
4463
|
+
const indentedStr = indentedParts.map(part => context.indent(part)).join(context.newline());
|
|
4464
|
+
result += context.newline() + indentedStr;
|
|
4465
|
+
}
|
|
4466
|
+
output.push(result);
|
|
4387
4467
|
}
|
|
4388
|
-
|
|
4389
|
-
parts
|
|
4468
|
+
else {
|
|
4469
|
+
const parts = [];
|
|
4470
|
+
if (colDefData.colname) {
|
|
4471
|
+
parts.push(quote_utils_1.QuoteUtils.quote(colDefData.colname));
|
|
4472
|
+
}
|
|
4473
|
+
if (colDefData.typeName) {
|
|
4474
|
+
parts.push(this.TypeName(colDefData.typeName, context));
|
|
4475
|
+
}
|
|
4476
|
+
if (colDefData.collClause) {
|
|
4477
|
+
parts.push(this.CollateClause(colDefData.collClause, context));
|
|
4478
|
+
}
|
|
4479
|
+
if (colDefData.fdwoptions && colDefData.fdwoptions.length > 0) {
|
|
4480
|
+
parts.push('OPTIONS');
|
|
4481
|
+
const columnContext = context.spawn('ColumnDef');
|
|
4482
|
+
const options = list_utils_1.ListUtils.unwrapList(colDefData.fdwoptions).map(opt => this.visit(opt, columnContext));
|
|
4483
|
+
parts.push(`(${options.join(', ')})`);
|
|
4484
|
+
}
|
|
4485
|
+
if (colDefData.constraints) {
|
|
4486
|
+
const constraints = list_utils_1.ListUtils.unwrapList(colDefData.constraints);
|
|
4487
|
+
const constraintStrs = constraints.map(constraint => {
|
|
4488
|
+
const columnConstraintContext = context.spawn('ColumnDef', { isColumnConstraint: true });
|
|
4489
|
+
return this.visit(constraint, columnConstraintContext);
|
|
4490
|
+
});
|
|
4491
|
+
parts.push(...constraintStrs);
|
|
4492
|
+
}
|
|
4493
|
+
if (colDefData.raw_default) {
|
|
4494
|
+
parts.push('DEFAULT');
|
|
4495
|
+
parts.push(this.visit(colDefData.raw_default, context));
|
|
4496
|
+
}
|
|
4497
|
+
if (colDefData.is_not_null) {
|
|
4498
|
+
parts.push('NOT NULL');
|
|
4499
|
+
}
|
|
4500
|
+
output.push(parts.join(' '));
|
|
4390
4501
|
}
|
|
4391
|
-
output.push(parts.join(' '));
|
|
4392
4502
|
}
|
|
4393
4503
|
if (node.behavior === 'DROP_CASCADE') {
|
|
4394
4504
|
output.push('CASCADE');
|
|
@@ -4904,11 +5014,10 @@ class Deparser {
|
|
|
4904
5014
|
if (node.name) {
|
|
4905
5015
|
output.push(quote_utils_1.QuoteUtils.quote(node.name));
|
|
4906
5016
|
}
|
|
4907
|
-
output.push('ADD
|
|
5017
|
+
output.push('ADD');
|
|
4908
5018
|
if (node.def) {
|
|
4909
5019
|
output.push(this.visit(node.def, context));
|
|
4910
5020
|
}
|
|
4911
|
-
output.push('AS IDENTITY');
|
|
4912
5021
|
break;
|
|
4913
5022
|
case 'AT_SetIdentity':
|
|
4914
5023
|
output.push('ALTER COLUMN');
|
package/esm/deparser.js
CHANGED
|
@@ -1708,6 +1708,24 @@ export class Deparser {
|
|
|
1708
1708
|
typeName = 'time with time zone';
|
|
1709
1709
|
}
|
|
1710
1710
|
}
|
|
1711
|
+
else if (type === 'timestamp') {
|
|
1712
|
+
if (args) {
|
|
1713
|
+
typeName = `timestamp(${args})`;
|
|
1714
|
+
args = null; // Don't apply args again in mods()
|
|
1715
|
+
}
|
|
1716
|
+
else {
|
|
1717
|
+
typeName = 'timestamp';
|
|
1718
|
+
}
|
|
1719
|
+
}
|
|
1720
|
+
else if (type === 'time') {
|
|
1721
|
+
if (args) {
|
|
1722
|
+
typeName = `time(${args})`;
|
|
1723
|
+
args = null; // Don't apply args again in mods()
|
|
1724
|
+
}
|
|
1725
|
+
else {
|
|
1726
|
+
typeName = 'time';
|
|
1727
|
+
}
|
|
1728
|
+
}
|
|
1711
1729
|
let result = mods(typeName, args);
|
|
1712
1730
|
if (node.arrayBounds && node.arrayBounds.length > 0) {
|
|
1713
1731
|
result += formatArrayBounds(node.arrayBounds);
|
|
@@ -2482,30 +2500,61 @@ export class Deparser {
|
|
|
2482
2500
|
.map(option => {
|
|
2483
2501
|
if (option.DefElem) {
|
|
2484
2502
|
const defElem = option.DefElem;
|
|
2485
|
-
|
|
2486
|
-
|
|
2503
|
+
if (defElem.defname === 'sequence_name') {
|
|
2504
|
+
if (defElem.arg && defElem.arg.List) {
|
|
2505
|
+
const nameList = ListUtils.unwrapList(defElem.arg)
|
|
2506
|
+
.map(item => this.visit(item, context))
|
|
2507
|
+
.join('.');
|
|
2508
|
+
return `SEQUENCE NAME ${nameList}`;
|
|
2509
|
+
}
|
|
2510
|
+
return 'SEQUENCE NAME';
|
|
2511
|
+
}
|
|
2512
|
+
else if (defElem.defname === 'start') {
|
|
2513
|
+
const argValue = defElem.arg ? this.visit(defElem.arg, context) : '';
|
|
2487
2514
|
return `START WITH ${argValue}`;
|
|
2488
2515
|
}
|
|
2489
2516
|
else if (defElem.defname === 'increment') {
|
|
2517
|
+
const argValue = defElem.arg ? this.visit(defElem.arg, context) : '';
|
|
2490
2518
|
return `INCREMENT BY ${argValue}`;
|
|
2491
2519
|
}
|
|
2492
2520
|
else if (defElem.defname === 'minvalue') {
|
|
2493
|
-
|
|
2521
|
+
if (defElem.arg) {
|
|
2522
|
+
const argValue = this.visit(defElem.arg, context);
|
|
2523
|
+
return `MINVALUE ${argValue}`;
|
|
2524
|
+
}
|
|
2525
|
+
else {
|
|
2526
|
+
return 'NO MINVALUE';
|
|
2527
|
+
}
|
|
2494
2528
|
}
|
|
2495
2529
|
else if (defElem.defname === 'maxvalue') {
|
|
2496
|
-
|
|
2530
|
+
if (defElem.arg) {
|
|
2531
|
+
const argValue = this.visit(defElem.arg, context);
|
|
2532
|
+
return `MAXVALUE ${argValue}`;
|
|
2533
|
+
}
|
|
2534
|
+
else {
|
|
2535
|
+
return 'NO MAXVALUE';
|
|
2536
|
+
}
|
|
2497
2537
|
}
|
|
2498
2538
|
else if (defElem.defname === 'cache') {
|
|
2539
|
+
const argValue = defElem.arg ? this.visit(defElem.arg, context) : '';
|
|
2499
2540
|
return `CACHE ${argValue}`;
|
|
2500
2541
|
}
|
|
2501
2542
|
else if (defElem.defname === 'cycle') {
|
|
2543
|
+
const argValue = defElem.arg ? this.visit(defElem.arg, context) : '';
|
|
2502
2544
|
return argValue === 'true' ? 'CYCLE' : 'NO CYCLE';
|
|
2503
2545
|
}
|
|
2546
|
+
const argValue = defElem.arg ? this.visit(defElem.arg, context) : '';
|
|
2504
2547
|
return `${defElem.defname.toUpperCase()} ${argValue}`;
|
|
2505
2548
|
}
|
|
2506
2549
|
return this.visit(option, context);
|
|
2507
2550
|
});
|
|
2508
|
-
|
|
2551
|
+
if (context.isPretty()) {
|
|
2552
|
+
const indentedOptions = optionStrs.map(option => context.indent(option));
|
|
2553
|
+
output.push('(\n' + indentedOptions.join('\n') + '\n)');
|
|
2554
|
+
}
|
|
2555
|
+
else {
|
|
2556
|
+
output.push(`(${optionStrs.join(' ')})`);
|
|
2557
|
+
}
|
|
2509
2558
|
}
|
|
2510
2559
|
break;
|
|
2511
2560
|
case 'CONSTR_PRIMARY':
|
|
@@ -4324,10 +4373,7 @@ export class Deparser {
|
|
|
4324
4373
|
const commandsStr = commands
|
|
4325
4374
|
.map(cmd => {
|
|
4326
4375
|
const cmdStr = this.visit(cmd, alterContext);
|
|
4327
|
-
|
|
4328
|
-
return context.newline() + context.indent(cmdStr);
|
|
4329
|
-
}
|
|
4330
|
-
return cmdStr;
|
|
4376
|
+
return context.newline() + context.indent(cmdStr);
|
|
4331
4377
|
})
|
|
4332
4378
|
.join(',');
|
|
4333
4379
|
output.push(commandsStr);
|
|
@@ -4357,35 +4403,99 @@ export class Deparser {
|
|
|
4357
4403
|
}
|
|
4358
4404
|
if (node.def) {
|
|
4359
4405
|
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
|
-
|
|
4406
|
+
if (context.isPretty()) {
|
|
4407
|
+
const parts = [];
|
|
4408
|
+
const indentedParts = [];
|
|
4409
|
+
if (colDefData.colname) {
|
|
4410
|
+
parts.push(QuoteUtils.quote(colDefData.colname));
|
|
4411
|
+
}
|
|
4412
|
+
if (colDefData.typeName) {
|
|
4413
|
+
parts.push(this.TypeName(colDefData.typeName, context));
|
|
4414
|
+
}
|
|
4415
|
+
if (colDefData.is_not_null) {
|
|
4416
|
+
indentedParts.push('NOT NULL');
|
|
4417
|
+
}
|
|
4418
|
+
if (colDefData.collClause) {
|
|
4419
|
+
indentedParts.push(this.CollateClause(colDefData.collClause, context));
|
|
4420
|
+
}
|
|
4421
|
+
if (colDefData.constraints) {
|
|
4422
|
+
const constraints = ListUtils.unwrapList(colDefData.constraints);
|
|
4423
|
+
constraints.forEach(constraint => {
|
|
4424
|
+
const columnConstraintContext = context.spawn('ColumnDef', { isColumnConstraint: true });
|
|
4425
|
+
const constraintStr = this.visit(constraint, columnConstraintContext);
|
|
4426
|
+
if (constraintStr.includes('REFERENCES') && constraintStr.includes('ON DELETE')) {
|
|
4427
|
+
const refMatch = constraintStr.match(/^(.*REFERENCES[^)]*\([^)]*\))\s*(ON\s+DELETE\s+CASCADE.*)$/);
|
|
4428
|
+
if (refMatch) {
|
|
4429
|
+
indentedParts.push(refMatch[1]);
|
|
4430
|
+
indentedParts.push(refMatch[2]);
|
|
4431
|
+
}
|
|
4432
|
+
else {
|
|
4433
|
+
indentedParts.push(constraintStr);
|
|
4434
|
+
}
|
|
4435
|
+
}
|
|
4436
|
+
else if (constraintStr === 'UNIQUE' && colDefData.raw_default) {
|
|
4437
|
+
const defaultStr = 'DEFAULT ' + this.visit(colDefData.raw_default, context);
|
|
4438
|
+
indentedParts.push('UNIQUE ' + defaultStr);
|
|
4439
|
+
}
|
|
4440
|
+
else {
|
|
4441
|
+
indentedParts.push(constraintStr);
|
|
4442
|
+
}
|
|
4443
|
+
});
|
|
4444
|
+
}
|
|
4445
|
+
if (colDefData.raw_default && !colDefData.constraints?.some((c) => {
|
|
4446
|
+
const constraintStr = this.visit(c, context.spawn('ColumnDef', { isColumnConstraint: true }));
|
|
4447
|
+
return constraintStr === 'UNIQUE';
|
|
4448
|
+
})) {
|
|
4449
|
+
const defaultStr = 'DEFAULT ' + this.visit(colDefData.raw_default, context);
|
|
4450
|
+
indentedParts.push(defaultStr);
|
|
4451
|
+
}
|
|
4452
|
+
if (colDefData.fdwoptions && colDefData.fdwoptions.length > 0) {
|
|
4453
|
+
indentedParts.push('OPTIONS');
|
|
4454
|
+
const columnContext = context.spawn('ColumnDef');
|
|
4455
|
+
const options = ListUtils.unwrapList(colDefData.fdwoptions).map(opt => this.visit(opt, columnContext));
|
|
4456
|
+
indentedParts.push(`(${options.join(', ')})`);
|
|
4457
|
+
}
|
|
4458
|
+
let result = parts.join(' ');
|
|
4459
|
+
if (indentedParts.length > 0) {
|
|
4460
|
+
const indentedStr = indentedParts.map(part => context.indent(part)).join(context.newline());
|
|
4461
|
+
result += context.newline() + indentedStr;
|
|
4462
|
+
}
|
|
4463
|
+
output.push(result);
|
|
4384
4464
|
}
|
|
4385
|
-
|
|
4386
|
-
parts
|
|
4465
|
+
else {
|
|
4466
|
+
const parts = [];
|
|
4467
|
+
if (colDefData.colname) {
|
|
4468
|
+
parts.push(QuoteUtils.quote(colDefData.colname));
|
|
4469
|
+
}
|
|
4470
|
+
if (colDefData.typeName) {
|
|
4471
|
+
parts.push(this.TypeName(colDefData.typeName, context));
|
|
4472
|
+
}
|
|
4473
|
+
if (colDefData.collClause) {
|
|
4474
|
+
parts.push(this.CollateClause(colDefData.collClause, context));
|
|
4475
|
+
}
|
|
4476
|
+
if (colDefData.fdwoptions && colDefData.fdwoptions.length > 0) {
|
|
4477
|
+
parts.push('OPTIONS');
|
|
4478
|
+
const columnContext = context.spawn('ColumnDef');
|
|
4479
|
+
const options = ListUtils.unwrapList(colDefData.fdwoptions).map(opt => this.visit(opt, columnContext));
|
|
4480
|
+
parts.push(`(${options.join(', ')})`);
|
|
4481
|
+
}
|
|
4482
|
+
if (colDefData.constraints) {
|
|
4483
|
+
const constraints = ListUtils.unwrapList(colDefData.constraints);
|
|
4484
|
+
const constraintStrs = constraints.map(constraint => {
|
|
4485
|
+
const columnConstraintContext = context.spawn('ColumnDef', { isColumnConstraint: true });
|
|
4486
|
+
return this.visit(constraint, columnConstraintContext);
|
|
4487
|
+
});
|
|
4488
|
+
parts.push(...constraintStrs);
|
|
4489
|
+
}
|
|
4490
|
+
if (colDefData.raw_default) {
|
|
4491
|
+
parts.push('DEFAULT');
|
|
4492
|
+
parts.push(this.visit(colDefData.raw_default, context));
|
|
4493
|
+
}
|
|
4494
|
+
if (colDefData.is_not_null) {
|
|
4495
|
+
parts.push('NOT NULL');
|
|
4496
|
+
}
|
|
4497
|
+
output.push(parts.join(' '));
|
|
4387
4498
|
}
|
|
4388
|
-
output.push(parts.join(' '));
|
|
4389
4499
|
}
|
|
4390
4500
|
if (node.behavior === 'DROP_CASCADE') {
|
|
4391
4501
|
output.push('CASCADE');
|
|
@@ -4901,11 +5011,10 @@ export class Deparser {
|
|
|
4901
5011
|
if (node.name) {
|
|
4902
5012
|
output.push(QuoteUtils.quote(node.name));
|
|
4903
5013
|
}
|
|
4904
|
-
output.push('ADD
|
|
5014
|
+
output.push('ADD');
|
|
4905
5015
|
if (node.def) {
|
|
4906
5016
|
output.push(this.visit(node.def, context));
|
|
4907
5017
|
}
|
|
4908
|
-
output.push('AS IDENTITY');
|
|
4909
5018
|
break;
|
|
4910
5019
|
case 'AT_SetIdentity':
|
|
4911
5020
|
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.1",
|
|
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": "ec88c0497ed19b222655ab8dba6a2f1ca1350fee"
|
|
62
62
|
}
|