pgsql-deparser 17.8.0 → 17.8.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/deparser.js +57 -14
- package/esm/deparser.js +57 -14
- package/package.json +2 -2
package/deparser.js
CHANGED
|
@@ -896,14 +896,15 @@ class Deparser {
|
|
|
896
896
|
if (node.ctes && node.ctes.length > 0) {
|
|
897
897
|
const ctes = list_utils_1.ListUtils.unwrapList(node.ctes);
|
|
898
898
|
if (this.formatter.isPretty()) {
|
|
899
|
-
const cteStrings = ctes.map(cte => {
|
|
899
|
+
const cteStrings = ctes.map((cte, index) => {
|
|
900
900
|
const cteStr = this.visit(cte, context);
|
|
901
|
+
const prefix = index === 0 ? this.formatter.newline() : ',' + this.formatter.newline();
|
|
901
902
|
if (this.containsMultilineStringLiteral(cteStr)) {
|
|
902
|
-
return
|
|
903
|
+
return prefix + cteStr;
|
|
903
904
|
}
|
|
904
|
-
return
|
|
905
|
+
return prefix + this.formatter.indent(cteStr);
|
|
905
906
|
});
|
|
906
|
-
output.push(cteStrings.join('
|
|
907
|
+
output.push(cteStrings.join(''));
|
|
907
908
|
}
|
|
908
909
|
else {
|
|
909
910
|
const cteStrings = ctes.map(cte => this.visit(cte, context));
|
|
@@ -1211,7 +1212,13 @@ class Deparser {
|
|
|
1211
1212
|
windowParts.push(frameClause);
|
|
1212
1213
|
}
|
|
1213
1214
|
if (windowParts.length > 0) {
|
|
1214
|
-
|
|
1215
|
+
if (this.formatter.isPretty() && windowParts.length > 1) {
|
|
1216
|
+
const formattedParts = windowParts.map(part => this.formatter.indent(part));
|
|
1217
|
+
result += ` OVER (${this.formatter.newline()}${formattedParts.join(this.formatter.newline())}${this.formatter.newline()})`;
|
|
1218
|
+
}
|
|
1219
|
+
else {
|
|
1220
|
+
result += ` OVER (${windowParts.join(' ')})`;
|
|
1221
|
+
}
|
|
1215
1222
|
}
|
|
1216
1223
|
else {
|
|
1217
1224
|
result += ` OVER ()`;
|
|
@@ -1835,15 +1842,39 @@ class Deparser {
|
|
|
1835
1842
|
output.push(this.visit(node.arg, context));
|
|
1836
1843
|
}
|
|
1837
1844
|
const args = list_utils_1.ListUtils.unwrapList(node.args);
|
|
1838
|
-
|
|
1839
|
-
|
|
1845
|
+
if (this.formatter.isPretty() && args.length > 0) {
|
|
1846
|
+
for (const arg of args) {
|
|
1847
|
+
const whenClause = this.visit(arg, context);
|
|
1848
|
+
if (this.containsMultilineStringLiteral(whenClause)) {
|
|
1849
|
+
output.push(this.formatter.newline() + whenClause);
|
|
1850
|
+
}
|
|
1851
|
+
else {
|
|
1852
|
+
output.push(this.formatter.newline() + this.formatter.indent(whenClause));
|
|
1853
|
+
}
|
|
1854
|
+
}
|
|
1855
|
+
if (node.defresult) {
|
|
1856
|
+
const elseResult = this.visit(node.defresult, context);
|
|
1857
|
+
if (this.containsMultilineStringLiteral(elseResult)) {
|
|
1858
|
+
output.push(this.formatter.newline() + 'ELSE ' + elseResult);
|
|
1859
|
+
}
|
|
1860
|
+
else {
|
|
1861
|
+
output.push(this.formatter.newline() + this.formatter.indent('ELSE ' + elseResult));
|
|
1862
|
+
}
|
|
1863
|
+
}
|
|
1864
|
+
output.push(this.formatter.newline() + 'END');
|
|
1865
|
+
return output.join(' ');
|
|
1840
1866
|
}
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1867
|
+
else {
|
|
1868
|
+
for (const arg of args) {
|
|
1869
|
+
output.push(this.visit(arg, context));
|
|
1870
|
+
}
|
|
1871
|
+
if (node.defresult) {
|
|
1872
|
+
output.push('ELSE');
|
|
1873
|
+
output.push(this.visit(node.defresult, context));
|
|
1874
|
+
}
|
|
1875
|
+
output.push('END');
|
|
1876
|
+
return output.join(' ');
|
|
1844
1877
|
}
|
|
1845
|
-
output.push('END');
|
|
1846
|
-
return output.join(' ');
|
|
1847
1878
|
}
|
|
1848
1879
|
CoalesceExpr(node, context) {
|
|
1849
1880
|
const args = list_utils_1.ListUtils.unwrapList(node.args);
|
|
@@ -3268,11 +3299,23 @@ class Deparser {
|
|
|
3268
3299
|
}
|
|
3269
3300
|
}
|
|
3270
3301
|
else if (node.quals) {
|
|
3302
|
+
const qualsStr = this.visit(node.quals, context);
|
|
3271
3303
|
if (this.formatter.isPretty()) {
|
|
3272
|
-
|
|
3304
|
+
// For complex JOIN conditions, format with proper indentation
|
|
3305
|
+
if (qualsStr.includes('AND') || qualsStr.includes('OR') || qualsStr.length > 50) {
|
|
3306
|
+
if (this.containsMultilineStringLiteral(qualsStr)) {
|
|
3307
|
+
output.push(` ON ${qualsStr}`);
|
|
3308
|
+
}
|
|
3309
|
+
else {
|
|
3310
|
+
output.push(` ON${this.formatter.newline()}${this.formatter.indent(qualsStr)}`);
|
|
3311
|
+
}
|
|
3312
|
+
}
|
|
3313
|
+
else {
|
|
3314
|
+
output.push(` ON ${qualsStr}`);
|
|
3315
|
+
}
|
|
3273
3316
|
}
|
|
3274
3317
|
else {
|
|
3275
|
-
output.push(`ON ${
|
|
3318
|
+
output.push(`ON ${qualsStr}`);
|
|
3276
3319
|
}
|
|
3277
3320
|
}
|
|
3278
3321
|
let result;
|
package/esm/deparser.js
CHANGED
|
@@ -893,14 +893,15 @@ export class Deparser {
|
|
|
893
893
|
if (node.ctes && node.ctes.length > 0) {
|
|
894
894
|
const ctes = ListUtils.unwrapList(node.ctes);
|
|
895
895
|
if (this.formatter.isPretty()) {
|
|
896
|
-
const cteStrings = ctes.map(cte => {
|
|
896
|
+
const cteStrings = ctes.map((cte, index) => {
|
|
897
897
|
const cteStr = this.visit(cte, context);
|
|
898
|
+
const prefix = index === 0 ? this.formatter.newline() : ',' + this.formatter.newline();
|
|
898
899
|
if (this.containsMultilineStringLiteral(cteStr)) {
|
|
899
|
-
return
|
|
900
|
+
return prefix + cteStr;
|
|
900
901
|
}
|
|
901
|
-
return
|
|
902
|
+
return prefix + this.formatter.indent(cteStr);
|
|
902
903
|
});
|
|
903
|
-
output.push(cteStrings.join('
|
|
904
|
+
output.push(cteStrings.join(''));
|
|
904
905
|
}
|
|
905
906
|
else {
|
|
906
907
|
const cteStrings = ctes.map(cte => this.visit(cte, context));
|
|
@@ -1208,7 +1209,13 @@ export class Deparser {
|
|
|
1208
1209
|
windowParts.push(frameClause);
|
|
1209
1210
|
}
|
|
1210
1211
|
if (windowParts.length > 0) {
|
|
1211
|
-
|
|
1212
|
+
if (this.formatter.isPretty() && windowParts.length > 1) {
|
|
1213
|
+
const formattedParts = windowParts.map(part => this.formatter.indent(part));
|
|
1214
|
+
result += ` OVER (${this.formatter.newline()}${formattedParts.join(this.formatter.newline())}${this.formatter.newline()})`;
|
|
1215
|
+
}
|
|
1216
|
+
else {
|
|
1217
|
+
result += ` OVER (${windowParts.join(' ')})`;
|
|
1218
|
+
}
|
|
1212
1219
|
}
|
|
1213
1220
|
else {
|
|
1214
1221
|
result += ` OVER ()`;
|
|
@@ -1832,15 +1839,39 @@ export class Deparser {
|
|
|
1832
1839
|
output.push(this.visit(node.arg, context));
|
|
1833
1840
|
}
|
|
1834
1841
|
const args = ListUtils.unwrapList(node.args);
|
|
1835
|
-
|
|
1836
|
-
|
|
1842
|
+
if (this.formatter.isPretty() && args.length > 0) {
|
|
1843
|
+
for (const arg of args) {
|
|
1844
|
+
const whenClause = this.visit(arg, context);
|
|
1845
|
+
if (this.containsMultilineStringLiteral(whenClause)) {
|
|
1846
|
+
output.push(this.formatter.newline() + whenClause);
|
|
1847
|
+
}
|
|
1848
|
+
else {
|
|
1849
|
+
output.push(this.formatter.newline() + this.formatter.indent(whenClause));
|
|
1850
|
+
}
|
|
1851
|
+
}
|
|
1852
|
+
if (node.defresult) {
|
|
1853
|
+
const elseResult = this.visit(node.defresult, context);
|
|
1854
|
+
if (this.containsMultilineStringLiteral(elseResult)) {
|
|
1855
|
+
output.push(this.formatter.newline() + 'ELSE ' + elseResult);
|
|
1856
|
+
}
|
|
1857
|
+
else {
|
|
1858
|
+
output.push(this.formatter.newline() + this.formatter.indent('ELSE ' + elseResult));
|
|
1859
|
+
}
|
|
1860
|
+
}
|
|
1861
|
+
output.push(this.formatter.newline() + 'END');
|
|
1862
|
+
return output.join(' ');
|
|
1837
1863
|
}
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1864
|
+
else {
|
|
1865
|
+
for (const arg of args) {
|
|
1866
|
+
output.push(this.visit(arg, context));
|
|
1867
|
+
}
|
|
1868
|
+
if (node.defresult) {
|
|
1869
|
+
output.push('ELSE');
|
|
1870
|
+
output.push(this.visit(node.defresult, context));
|
|
1871
|
+
}
|
|
1872
|
+
output.push('END');
|
|
1873
|
+
return output.join(' ');
|
|
1841
1874
|
}
|
|
1842
|
-
output.push('END');
|
|
1843
|
-
return output.join(' ');
|
|
1844
1875
|
}
|
|
1845
1876
|
CoalesceExpr(node, context) {
|
|
1846
1877
|
const args = ListUtils.unwrapList(node.args);
|
|
@@ -3265,11 +3296,23 @@ export class Deparser {
|
|
|
3265
3296
|
}
|
|
3266
3297
|
}
|
|
3267
3298
|
else if (node.quals) {
|
|
3299
|
+
const qualsStr = this.visit(node.quals, context);
|
|
3268
3300
|
if (this.formatter.isPretty()) {
|
|
3269
|
-
|
|
3301
|
+
// For complex JOIN conditions, format with proper indentation
|
|
3302
|
+
if (qualsStr.includes('AND') || qualsStr.includes('OR') || qualsStr.length > 50) {
|
|
3303
|
+
if (this.containsMultilineStringLiteral(qualsStr)) {
|
|
3304
|
+
output.push(` ON ${qualsStr}`);
|
|
3305
|
+
}
|
|
3306
|
+
else {
|
|
3307
|
+
output.push(` ON${this.formatter.newline()}${this.formatter.indent(qualsStr)}`);
|
|
3308
|
+
}
|
|
3309
|
+
}
|
|
3310
|
+
else {
|
|
3311
|
+
output.push(` ON ${qualsStr}`);
|
|
3312
|
+
}
|
|
3270
3313
|
}
|
|
3271
3314
|
else {
|
|
3272
|
-
output.push(`ON ${
|
|
3315
|
+
output.push(`ON ${qualsStr}`);
|
|
3273
3316
|
}
|
|
3274
3317
|
}
|
|
3275
3318
|
let result;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pgsql-deparser",
|
|
3
|
-
"version": "17.8.
|
|
3
|
+
"version": "17.8.1",
|
|
4
4
|
"author": "Dan Lynch <pyramation@gmail.com>",
|
|
5
5
|
"description": "PostgreSQL AST Deparser",
|
|
6
6
|
"main": "index.js",
|
|
@@ -51,5 +51,5 @@
|
|
|
51
51
|
"dependencies": {
|
|
52
52
|
"@pgsql/types": "^17.6.1"
|
|
53
53
|
},
|
|
54
|
-
"gitHead": "
|
|
54
|
+
"gitHead": "cffd419f76ad6975c89e7e4f79972f7f27b0eab7"
|
|
55
55
|
}
|