pgsql-deparser 13.1.8 → 13.1.12

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/CHANGELOG.md CHANGED
@@ -3,6 +3,38 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [13.1.12](https://github.com/pyramation/pgsql-parser/compare/pgsql-deparser@13.1.11...pgsql-deparser@13.1.12) (2022-01-05)
7
+
8
+ **Note:** Version bump only for package pgsql-deparser
9
+
10
+
11
+
12
+
13
+
14
+ ## [13.1.11](https://github.com/pyramation/pgsql-parser/compare/pgsql-deparser@13.1.10...pgsql-deparser@13.1.11) (2021-10-19)
15
+
16
+ **Note:** Version bump only for package pgsql-deparser
17
+
18
+
19
+
20
+
21
+
22
+ ## [13.1.10](https://github.com/pyramation/pgsql-parser/compare/pgsql-deparser@13.1.9...pgsql-deparser@13.1.10) (2021-10-19)
23
+
24
+ **Note:** Version bump only for package pgsql-deparser
25
+
26
+
27
+
28
+
29
+
30
+ ## [13.1.9](https://github.com/pyramation/pgsql-parser/compare/pgsql-deparser@13.1.8...pgsql-deparser@13.1.9) (2021-10-13)
31
+
32
+ **Note:** Version bump only for package pgsql-deparser
33
+
34
+
35
+
36
+
37
+
6
38
  ## [13.1.8](https://github.com/pyramation/pgsql-parser/compare/pgsql-deparser@13.1.7...pgsql-deparser@13.1.8) (2021-09-09)
7
39
 
8
40
  **Note:** Version bump only for package pgsql-deparser
package/main/deparser.js CHANGED
@@ -27,7 +27,7 @@ var _pgsqlEnums = require("pgsql-enums");
27
27
 
28
28
  var _preparse = require("./preparse");
29
29
 
30
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
30
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
31
31
 
32
32
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
33
33
 
@@ -1034,8 +1034,114 @@ var Deparser = /*#__PURE__*/function () {
1034
1034
  return output.join(' ');
1035
1035
  }
1036
1036
  }, {
1037
+ key: 'DefineStmt',
1038
+ value: function DefineStmt(node) {
1039
+ var context = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1040
+ var output = [];
1041
+ output.push('CREATE');
1042
+
1043
+ if (node.replace) {
1044
+ output.push('OR REPLACE');
1045
+ }
1046
+
1047
+ switch (node.kind) {
1048
+ case 'OBJECT_AGGREGATE':
1049
+ output.push('AGGREGATE');
1050
+ break;
1051
+
1052
+ case 'OBJECT_OPERATOR':
1053
+ output.push('OPERATOR');
1054
+ break;
1055
+
1056
+ case 'OBJECT_TYPE':
1057
+ output.push('TYPE');
1058
+ break;
1059
+
1060
+ case 'OBJECT_TSPARSER':
1061
+ output.push('TEXT SEARCH PARSER');
1062
+ break;
1063
+
1064
+ case 'OBJECT_TSDICTIONARY':
1065
+ output.push('TEXT SEARCH DICTIONARY');
1066
+ break;
1067
+
1068
+ case 'OBJECT_TSTEMPLATE':
1069
+ output.push('TEXT SEARCH TEMPLATE');
1070
+ break;
1071
+
1072
+ case 'OBJECT_TSCONFIGURATION':
1073
+ output.push('TEXT SEARCH CONFIGURATION');
1074
+ break;
1075
+
1076
+ case 'OBJECT_COLLATION':
1077
+ output.push('COLLATION');
1078
+ break;
1079
+
1080
+ default:
1081
+ throw new Error('DefineStmt not recognized');
1082
+ }
1083
+
1084
+ if (node.if_not_exists) {
1085
+ output.push('IF NOT EXISTS');
1086
+ }
1087
+
1088
+ switch (node.kind) {
1089
+ case 'OBJECT_AGGREGATE':
1090
+ // output.push(this.deparse(node.defnames));
1091
+ output.push(this.list(node.defnames, '.', '', context));
1092
+ break;
1093
+
1094
+ case 'OBJECT_OPERATOR':
1095
+ output.push(this.list(node.defnames, '.', '', context)); // output.push(this.deparse(node.defnames));
1096
+
1097
+ break;
1098
+
1099
+ case 'OBJECT_TYPE':
1100
+ case 'OBJECT_TSPARSER':
1101
+ case 'OBJECT_TSDICTIONARY':
1102
+ case 'OBJECT_TSTEMPLATE':
1103
+ case 'OBJECT_TSCONFIGURATION':
1104
+ case 'OBJECT_COLLATION':
1105
+ output.push(this.deparse(node.defnames));
1106
+ break;
1107
+
1108
+ default:
1109
+ throw new Error('DefineStmt not recognized');
1110
+ }
1111
+
1112
+ if (!node.oldstyle && node.kind == 'OBJECT_AGGREGATE') {
1113
+ output.push('(');
1114
+ output.push("".concat(this.listQuotes(node.args[0], ',')));
1115
+ output.push(')');
1116
+ }
1117
+
1118
+ if (node.definition.length > 0) {
1119
+ output.push('(');
1120
+
1121
+ for (var n = 0; n < node.definition.length; n++) {
1122
+ var defElement = node.definition[n].DefElem;
1123
+ output.push(defElement.defname);
1124
+
1125
+ if (defElement.arg) {
1126
+ output.push('=');
1127
+ output.push(this.deparse(defElement.arg));
1128
+ }
1129
+
1130
+ if (n !== node.definition.length - 1) {
1131
+ output.push(',');
1132
+ }
1133
+ }
1134
+
1135
+ output.push(')');
1136
+ }
1137
+
1138
+ return output.join(' ');
1139
+ }
1140
+ }, {
1037
1141
  key: 'DefElem',
1038
1142
  value: function DefElem(node) {
1143
+ var _this7 = this;
1144
+
1039
1145
  var context = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1040
1146
 
1041
1147
  if (node.defname === 'transaction_isolation') {
@@ -1060,7 +1166,7 @@ var Deparser = /*#__PURE__*/function () {
1060
1166
  name = "".concat(node.defnamespace, ".").concat(node.defname);
1061
1167
  }
1062
1168
 
1063
- if (context === 'generated') {
1169
+ if (context === 'generated' || context === 'sequence') {
1064
1170
  switch (name) {
1065
1171
  case 'start':
1066
1172
  {
@@ -1071,16 +1177,20 @@ var Deparser = /*#__PURE__*/function () {
1071
1177
  case 'increment':
1072
1178
  {
1073
1179
  var inc = this.deparse(node.arg, context);
1180
+
1181
+ if (context === 'sequence') {
1182
+ // we need 'simple' so it doesn't wrap negative numbers in parens
1183
+ return "".concat(name, " ").concat(this.deparse(node.arg, 'simple'));
1184
+ }
1185
+
1074
1186
  return "INCREMENT BY ".concat(inc);
1075
1187
  }
1076
1188
 
1077
- default:
1078
- throw new Error('NOT_IMPLEMENTED');
1079
- }
1080
- }
1189
+ case 'sequence_name':
1190
+ {
1191
+ return "SEQUENCE NAME ".concat(this.listQuotes(node.arg, '.'));
1192
+ }
1081
1193
 
1082
- if (context === 'sequence') {
1083
- switch (name) {
1084
1194
  case 'cycle':
1085
1195
  {
1086
1196
  var on = this.deparse(node.arg, context) + '' === '1';
@@ -1099,6 +1209,26 @@ var Deparser = /*#__PURE__*/function () {
1099
1209
 
1100
1210
  return _off ? 'NO MAXVALUE' : "".concat(name, " ").concat(this.deparse(node.arg, 'simple'));
1101
1211
  }
1212
+ // alter
1213
+
1214
+ case 'owned_by':
1215
+ {
1216
+ var output = [];
1217
+ node.arg.forEach(function (opt) {
1218
+ output.push(_this7.quote(_this7.deparse(opt, context)));
1219
+ });
1220
+ return "OWNED BY ".concat(output.join('.'));
1221
+ }
1222
+ // alter
1223
+
1224
+ case 'restart':
1225
+ {
1226
+ if (node.arg) {
1227
+ return "RESTART WITH ".concat(this.deparse(node.arg, context));
1228
+ }
1229
+
1230
+ return "RESTART";
1231
+ }
1102
1232
 
1103
1233
  default:
1104
1234
  if (node.arg) {
@@ -1131,7 +1261,7 @@ var Deparser = /*#__PURE__*/function () {
1131
1261
  }, {
1132
1262
  key: 'FuncCall',
1133
1263
  value: function FuncCall(node) {
1134
- var _this7 = this;
1264
+ var _this8 = this;
1135
1265
 
1136
1266
  var context = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1137
1267
  var output = [];
@@ -1139,7 +1269,7 @@ var Deparser = /*#__PURE__*/function () {
1139
1269
 
1140
1270
  if (node.args) {
1141
1271
  params = node.args.map(function (item) {
1142
- return _this7.deparse(item, context);
1272
+ return _this8.deparse(item, context);
1143
1273
  });
1144
1274
  } // COUNT(*)
1145
1275
 
@@ -1296,7 +1426,7 @@ var Deparser = /*#__PURE__*/function () {
1296
1426
  }, {
1297
1427
  key: 'InsertStmt',
1298
1428
  value: function InsertStmt(node) {
1299
- var _this8 = this;
1429
+ var _this9 = this;
1300
1430
 
1301
1431
  var context = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1302
1432
  var output = [];
@@ -1346,7 +1476,7 @@ var Deparser = /*#__PURE__*/function () {
1346
1476
  if (node.returningList) {
1347
1477
  output.push('RETURNING');
1348
1478
  output.push(node.returningList.map(function (returning) {
1349
- return _this8.deparse(returning.ResTarget.val, context) + (returning.ResTarget.name ? ' AS ' + _this8.quote(returning.ResTarget.name) : '');
1479
+ return _this9.deparse(returning.ResTarget.val, context) + (returning.ResTarget.name ? ' AS ' + _this9.quote(returning.ResTarget.name) : '');
1350
1480
  }).join(','));
1351
1481
  }
1352
1482
 
@@ -1384,7 +1514,7 @@ var Deparser = /*#__PURE__*/function () {
1384
1514
  }, {
1385
1515
  key: 'UpdateStmt',
1386
1516
  value: function UpdateStmt(node) {
1387
- var _this9 = this;
1517
+ var _this10 = this;
1388
1518
 
1389
1519
  var context = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1390
1520
  var output = [];
@@ -1408,7 +1538,7 @@ var Deparser = /*#__PURE__*/function () {
1408
1538
  output.push(this.deparse(node.targetList[0].ResTarget.val, context));
1409
1539
  } else {
1410
1540
  output.push(node.targetList.map(function (target) {
1411
- return _this9.deparse(target, 'update');
1541
+ return _this10.deparse(target, 'update');
1412
1542
  }).join(','));
1413
1543
  }
1414
1544
  }
@@ -1426,7 +1556,7 @@ var Deparser = /*#__PURE__*/function () {
1426
1556
  if (node.returningList) {
1427
1557
  output.push('RETURNING');
1428
1558
  output.push(node.returningList.map(function (returning) {
1429
- return _this9.deparse(returning.ResTarget.val, context) + (returning.ResTarget.name ? ' AS ' + _this9.quote(returning.ResTarget.name) : '');
1559
+ return _this10.deparse(returning.ResTarget.val, context) + (returning.ResTarget.name ? ' AS ' + _this10.quote(returning.ResTarget.name) : '');
1430
1560
  }).join(','));
1431
1561
  }
1432
1562
 
@@ -1772,7 +1902,7 @@ var Deparser = /*#__PURE__*/function () {
1772
1902
  }, {
1773
1903
  key: 'SelectStmt',
1774
1904
  value: function SelectStmt(node) {
1775
- var _this10 = this;
1905
+ var _this11 = this;
1776
1906
 
1777
1907
  var context = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1778
1908
  var output = [];
@@ -1820,19 +1950,19 @@ var Deparser = /*#__PURE__*/function () {
1820
1950
  if (node.distinctClause) {
1821
1951
  if (!isEmptyObject(node.distinctClause[0]) // new change distinctClause can be {}
1822
1952
  ) {
1823
- output.push('DISTINCT ON');
1824
- var clause = node.distinctClause.map(function (e) {
1825
- return _this10.deparse(e, 'select');
1826
- }).join(",".concat(NEWLINE_CHAR));
1827
- output.push("(".concat(clause, ")"));
1828
- } else {
1953
+ output.push('DISTINCT ON');
1954
+ var clause = node.distinctClause.map(function (e) {
1955
+ return _this11.deparse(e, 'select');
1956
+ }).join(",".concat(NEWLINE_CHAR));
1957
+ output.push("(".concat(clause, ")"));
1958
+ } else {
1829
1959
  output.push('DISTINCT');
1830
1960
  }
1831
1961
  }
1832
1962
 
1833
1963
  if (node.targetList) {
1834
1964
  output.push(indent(node.targetList.map(function (e) {
1835
- return _this10.deparse(e, 'select');
1965
+ return _this11.deparse(e, 'select');
1836
1966
  }).join(",".concat(NEWLINE_CHAR))));
1837
1967
  }
1838
1968
 
@@ -1844,7 +1974,7 @@ var Deparser = /*#__PURE__*/function () {
1844
1974
  if (node.fromClause) {
1845
1975
  output.push('FROM');
1846
1976
  output.push(indent(node.fromClause.map(function (e) {
1847
- return _this10.deparse(e, 'from');
1977
+ return _this11.deparse(e, 'from');
1848
1978
  }).join(",".concat(NEWLINE_CHAR))));
1849
1979
  }
1850
1980
 
@@ -1856,7 +1986,7 @@ var Deparser = /*#__PURE__*/function () {
1856
1986
  if (node.valuesLists) {
1857
1987
  output.push('VALUES');
1858
1988
  var lists = node.valuesLists.map(function (list) {
1859
- return "(".concat(_this10.list(list, ', ', '', context), ")");
1989
+ return "(".concat(_this11.list(list, ', ', '', context), ")");
1860
1990
  });
1861
1991
  output.push(lists.join(', '));
1862
1992
  }
@@ -1864,7 +1994,7 @@ var Deparser = /*#__PURE__*/function () {
1864
1994
  if (node.groupClause) {
1865
1995
  output.push('GROUP BY');
1866
1996
  output.push(indent(node.groupClause.map(function (e) {
1867
- return _this10.deparse(e, 'group');
1997
+ return _this11.deparse(e, 'group');
1868
1998
  }).join(",".concat(NEWLINE_CHAR))));
1869
1999
  }
1870
2000
 
@@ -1895,7 +2025,7 @@ var Deparser = /*#__PURE__*/function () {
1895
2025
  if (node.sortClause) {
1896
2026
  output.push('ORDER BY');
1897
2027
  output.push(indent(node.sortClause.map(function (e) {
1898
- return _this10.deparse(e, 'sort');
2028
+ return _this11.deparse(e, 'sort');
1899
2029
  }).join(",".concat(NEWLINE_CHAR))));
1900
2030
  }
1901
2031
 
@@ -1911,7 +2041,7 @@ var Deparser = /*#__PURE__*/function () {
1911
2041
 
1912
2042
  if (node.lockingClause) {
1913
2043
  node.lockingClause.forEach(function (item) {
1914
- return output.push(_this10.deparse(item, context));
2044
+ return output.push(_this11.deparse(item, context));
1915
2045
  });
1916
2046
  }
1917
2047
 
@@ -2097,6 +2227,11 @@ var Deparser = /*#__PURE__*/function () {
2097
2227
  output.push('(');
2098
2228
  output.push(this.list(node.def, ', ', '', context));
2099
2229
  output.push(')');
2230
+ } else if (node.subtype === 'AT_AddIdentity') {
2231
+ output.push('ALTER COLUMN');
2232
+ output.push(this.quote(node.name));
2233
+ output.push('ADD');
2234
+ output.push(this.deparse(node.def, context));
2100
2235
  } else if (node.subtype === 'AT_AddInherit') {
2101
2236
  output.push('INHERIT');
2102
2237
  output.push(this.deparse(node.def, context));
@@ -2435,7 +2570,7 @@ var Deparser = /*#__PURE__*/function () {
2435
2570
  }, {
2436
2571
  key: 'CreateSeqStmt',
2437
2572
  value: function CreateSeqStmt(node) {
2438
- var _this11 = this;
2573
+ var _this12 = this;
2439
2574
 
2440
2575
  var context = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
2441
2576
  var output = [];
@@ -2444,7 +2579,25 @@ var Deparser = /*#__PURE__*/function () {
2444
2579
 
2445
2580
  if (node.options && node.options.length) {
2446
2581
  node.options.forEach(function (opt) {
2447
- output.push(_this11.deparse(opt, 'sequence'));
2582
+ output.push(_this12.deparse(opt, 'sequence'));
2583
+ });
2584
+ }
2585
+
2586
+ return output.join(' ');
2587
+ }
2588
+ }, {
2589
+ key: 'AlterSeqStmt',
2590
+ value: function AlterSeqStmt(node) {
2591
+ var _this13 = this;
2592
+
2593
+ var context = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
2594
+ var output = [];
2595
+ output.push('ALTER SEQUENCE');
2596
+ output.push(this.RangeVar(node.sequence, context));
2597
+
2598
+ if (node.options && node.options.length) {
2599
+ node.options.forEach(function (opt) {
2600
+ output.push(_this13.deparse(opt, 'sequence'));
2448
2601
  });
2449
2602
  }
2450
2603
 
@@ -2464,7 +2617,7 @@ var Deparser = /*#__PURE__*/function () {
2464
2617
  }, {
2465
2618
  key: 'CreateTrigStmt',
2466
2619
  value: function CreateTrigStmt(node) {
2467
- var _this12 = this;
2620
+ var _this14 = this;
2468
2621
 
2469
2622
  var context = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
2470
2623
  var output = [];
@@ -2583,7 +2736,7 @@ var Deparser = /*#__PURE__*/function () {
2583
2736
  return "'".concat(dotty.get(arg, 'String.str'), "'");
2584
2737
  }
2585
2738
 
2586
- return _this12.deparse(arg, context);
2739
+ return _this14.deparse(arg, context);
2587
2740
  }).filter(function (a) {
2588
2741
  return a;
2589
2742
  });
@@ -2742,17 +2895,17 @@ var Deparser = /*#__PURE__*/function () {
2742
2895
  var output = [];
2743
2896
 
2744
2897
  function getExclusionGroup(nde) {
2745
- var _this13 = this;
2898
+ var _this15 = this;
2746
2899
 
2747
2900
  var a = nde.exclusions.map(function (excl) {
2748
2901
  if (excl[0].IndexElem.name) {
2749
2902
  return excl[0].IndexElem.name;
2750
2903
  }
2751
2904
 
2752
- return excl[0].IndexElem.expr ? _this13.deparse(excl[0].IndexElem.expr, context) : null;
2905
+ return excl[0].IndexElem.expr ? _this15.deparse(excl[0].IndexElem.expr, context) : null;
2753
2906
  });
2754
2907
  var b = nde.exclusions.map(function (excl) {
2755
- return _this13.deparse(excl[1][0], context);
2908
+ return _this15.deparse(excl[1][0], context);
2756
2909
  });
2757
2910
  var stmts = a.map(function (_v, i) {
2758
2911
  return "".concat(a[i], " WITH ").concat(b[i]);
@@ -2970,7 +3123,7 @@ var Deparser = /*#__PURE__*/function () {
2970
3123
  }, {
2971
3124
  key: 'CreateFunctionStmt',
2972
3125
  value: function CreateFunctionStmt(node) {
2973
- var _this14 = this;
3126
+ var _this16 = this;
2974
3127
 
2975
3128
  var context = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
2976
3129
  var output = [];
@@ -2982,7 +3135,7 @@ var Deparser = /*#__PURE__*/function () {
2982
3135
 
2983
3136
  output.push('FUNCTION');
2984
3137
  output.push(node.funcname.map(function (name) {
2985
- return _this14.deparse(name, context);
3138
+ return _this16.deparse(name, context);
2986
3139
  }).join('.'));
2987
3140
  output.push('(');
2988
3141
  var parameters = [];
@@ -3019,12 +3172,12 @@ var Deparser = /*#__PURE__*/function () {
3019
3172
 
3020
3173
  switch (option.DefElem.defname) {
3021
3174
  case 'as':
3022
- value = _this14.deparse(option.DefElem.arg[0], context);
3175
+ value = _this16.deparse(option.DefElem.arg[0], context);
3023
3176
  output.push("AS $EOFCODE$".concat(value, "$EOFCODE$"));
3024
3177
  break;
3025
3178
 
3026
3179
  case 'language':
3027
- value = _this14.deparse(option.DefElem.arg, context);
3180
+ value = _this16.deparse(option.DefElem.arg, context);
3028
3181
  output.push('LANGUAGE');
3029
3182
  output.push(value);
3030
3183
  break;
@@ -3071,11 +3224,11 @@ var Deparser = /*#__PURE__*/function () {
3071
3224
  break;
3072
3225
 
3073
3226
  case 'set':
3074
- output.push(_this14.deparse(option, context));
3227
+ output.push(_this16.deparse(option, context));
3075
3228
  break;
3076
3229
 
3077
3230
  case 'volatility':
3078
- value = _this14.deparse(option.DefElem.arg, context);
3231
+ value = _this16.deparse(option.DefElem.arg, context);
3079
3232
  output.push(value.toUpperCase());
3080
3233
  break;
3081
3234
 
@@ -3272,7 +3425,7 @@ var Deparser = /*#__PURE__*/function () {
3272
3425
  }, {
3273
3426
  key: 'CreateRoleStmt',
3274
3427
  value: function CreateRoleStmt(node) {
3275
- var _this15 = this;
3428
+ var _this17 = this;
3276
3429
 
3277
3430
  var context = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
3278
3431
  var output = [];
@@ -3333,12 +3486,12 @@ var Deparser = /*#__PURE__*/function () {
3333
3486
 
3334
3487
  case 'adminmembers':
3335
3488
  output.push('ADMIN');
3336
- output.push(_this15.list(node.options[i].DefElem.arg, ', ', '', context));
3489
+ output.push(_this17.list(node.options[i].DefElem.arg, ', ', '', context));
3337
3490
  break;
3338
3491
 
3339
3492
  case 'rolemembers':
3340
3493
  output.push('USER');
3341
- output.push(_this15.list(node.options[i].DefElem.arg, ', ', '', context));
3494
+ output.push(_this17.list(node.options[i].DefElem.arg, ', ', '', context));
3342
3495
  break;
3343
3496
 
3344
3497
  case 'createdb':
@@ -3381,7 +3534,7 @@ var Deparser = /*#__PURE__*/function () {
3381
3534
  }, {
3382
3535
  key: 'TransactionStmt',
3383
3536
  value: function TransactionStmt(node) {
3384
- var _this16 = this;
3537
+ var _this18 = this;
3385
3538
 
3386
3539
  var context = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
3387
3540
  var output = [];
@@ -3393,7 +3546,7 @@ var Deparser = /*#__PURE__*/function () {
3393
3546
  var index = opts.indexOf('transaction_read_only');
3394
3547
  var obj = nodeOpts.options[index];
3395
3548
  var set = false;
3396
- var flag = Number(_this16.deparse(dotty.get(obj, 'DefElem.arg'), context));
3549
+ var flag = Number(_this18.deparse(dotty.get(obj, 'DefElem.arg'), context));
3397
3550
 
3398
3551
  if (flag > 0) {
3399
3552
  set = true;
@@ -3411,7 +3564,7 @@ var Deparser = /*#__PURE__*/function () {
3411
3564
 
3412
3565
  var _obj = nodeOpts.options[_index];
3413
3566
 
3414
- var lopts = _this16.deparse(dotty.get(_obj, 'DefElem.arg'), context).replace(/['"]+/g, '');
3567
+ var lopts = _this18.deparse(dotty.get(_obj, 'DefElem.arg'), context).replace(/['"]+/g, '');
3415
3568
 
3416
3569
  return "BEGIN TRANSACTION ISOLATION LEVEL ".concat(lopts.toUpperCase());
3417
3570
  }
@@ -3426,7 +3579,7 @@ var Deparser = /*#__PURE__*/function () {
3426
3579
  var index = opts.indexOf('transaction_read_only');
3427
3580
  var obj = nodeOpts.options[index];
3428
3581
  var set = false;
3429
- var flag = Number(_this16.deparse(dotty.get(obj, 'DefElem.arg'), context));
3582
+ var flag = Number(_this18.deparse(dotty.get(obj, 'DefElem.arg'), context));
3430
3583
 
3431
3584
  if (flag > 0) {
3432
3585
  set = true;
@@ -3530,7 +3683,7 @@ var Deparser = /*#__PURE__*/function () {
3530
3683
  }, {
3531
3684
  key: 'ObjectWithArgs',
3532
3685
  value: function ObjectWithArgs(node) {
3533
- var _this17 = this;
3686
+ var _this19 = this;
3534
3687
 
3535
3688
  var context = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
3536
3689
  var output = [];
@@ -3548,7 +3701,7 @@ var Deparser = /*#__PURE__*/function () {
3548
3701
  return 'NONE';
3549
3702
  }
3550
3703
 
3551
- return _this17.deparse(arg, context);
3704
+ return _this19.deparse(arg, context);
3552
3705
  }).join(','));
3553
3706
  output.push(')');
3554
3707
  }
@@ -3625,7 +3778,7 @@ var Deparser = /*#__PURE__*/function () {
3625
3778
  }, {
3626
3779
  key: 'TypeName',
3627
3780
  value: function TypeName(node) {
3628
- var _this18 = this;
3781
+ var _this20 = this;
3629
3782
 
3630
3783
  var context = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
3631
3784
 
@@ -3643,7 +3796,7 @@ var Deparser = /*#__PURE__*/function () {
3643
3796
 
3644
3797
  if (node.typmods != null) {
3645
3798
  args = node.typmods.map(function (item) {
3646
- return _this18.deparse(item, context);
3799
+ return _this20.deparse(item, context);
3647
3800
  });
3648
3801
  }
3649
3802
 
@@ -3670,7 +3823,7 @@ var Deparser = /*#__PURE__*/function () {
3670
3823
  }, {
3671
3824
  key: 'WindowDef',
3672
3825
  value: function WindowDef(node) {
3673
- var _this19 = this;
3826
+ var _this21 = this;
3674
3827
 
3675
3828
  var context = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
3676
3829
  var output = [];
@@ -3694,7 +3847,7 @@ var Deparser = /*#__PURE__*/function () {
3694
3847
  if (node.partitionClause) {
3695
3848
  var partition = ['PARTITION BY'];
3696
3849
  var clause = node.partitionClause.map(function (item) {
3697
- return _this19.deparse(item, context);
3850
+ return _this21.deparse(item, context);
3698
3851
  });
3699
3852
  partition.push(clause.join(', '));
3700
3853
  windowParts.push(partition.join(' '));
@@ -3704,7 +3857,7 @@ var Deparser = /*#__PURE__*/function () {
3704
3857
  if (node.orderClause) {
3705
3858
  windowParts.push('ORDER BY');
3706
3859
  var orders = node.orderClause.map(function (item) {
3707
- return _this19.deparse(item);
3860
+ return _this21.deparse(item);
3708
3861
  });
3709
3862
  windowParts.push(orders.join(', '));
3710
3863
  useParens = true;
@@ -3877,7 +4030,7 @@ var Deparser = /*#__PURE__*/function () {
3877
4030
  }, {
3878
4031
  key: "deparseInterval",
3879
4032
  value: function deparseInterval(node) {
3880
- var _this20 = this;
4033
+ var _this22 = this;
3881
4034
 
3882
4035
  var type = ['interval'];
3883
4036
 
@@ -3887,7 +4040,7 @@ var Deparser = /*#__PURE__*/function () {
3887
4040
 
3888
4041
  if (node.typmods) {
3889
4042
  var typmods = node.typmods.map(function (item) {
3890
- return _this20.deparse(item);
4043
+ return _this22.deparse(item);
3891
4044
  });
3892
4045
  var intervals = this.interval(typmods[0]); // SELECT interval(0) '1 day 01:23:45.6789'
3893
4046
 
@@ -1,6 +1,6 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
2
 
3
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
3
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
4
4
 
5
5
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
6
6
 
@@ -920,6 +920,108 @@ export default class Deparser {
920
920
  return output.join(' ');
921
921
  }
922
922
 
923
+ ['DefineStmt'](node, context = {}) {
924
+ const output = [];
925
+ output.push('CREATE');
926
+
927
+ if (node.replace) {
928
+ output.push('OR REPLACE');
929
+ }
930
+
931
+ switch (node.kind) {
932
+ case 'OBJECT_AGGREGATE':
933
+ output.push('AGGREGATE');
934
+ break;
935
+
936
+ case 'OBJECT_OPERATOR':
937
+ output.push('OPERATOR');
938
+ break;
939
+
940
+ case 'OBJECT_TYPE':
941
+ output.push('TYPE');
942
+ break;
943
+
944
+ case 'OBJECT_TSPARSER':
945
+ output.push('TEXT SEARCH PARSER');
946
+ break;
947
+
948
+ case 'OBJECT_TSDICTIONARY':
949
+ output.push('TEXT SEARCH DICTIONARY');
950
+ break;
951
+
952
+ case 'OBJECT_TSTEMPLATE':
953
+ output.push('TEXT SEARCH TEMPLATE');
954
+ break;
955
+
956
+ case 'OBJECT_TSCONFIGURATION':
957
+ output.push('TEXT SEARCH CONFIGURATION');
958
+ break;
959
+
960
+ case 'OBJECT_COLLATION':
961
+ output.push('COLLATION');
962
+ break;
963
+
964
+ default:
965
+ throw new Error('DefineStmt not recognized');
966
+ }
967
+
968
+ if (node.if_not_exists) {
969
+ output.push('IF NOT EXISTS');
970
+ }
971
+
972
+ switch (node.kind) {
973
+ case 'OBJECT_AGGREGATE':
974
+ // output.push(this.deparse(node.defnames));
975
+ output.push(this.list(node.defnames, '.', '', context));
976
+ break;
977
+
978
+ case 'OBJECT_OPERATOR':
979
+ output.push(this.list(node.defnames, '.', '', context)); // output.push(this.deparse(node.defnames));
980
+
981
+ break;
982
+
983
+ case 'OBJECT_TYPE':
984
+ case 'OBJECT_TSPARSER':
985
+ case 'OBJECT_TSDICTIONARY':
986
+ case 'OBJECT_TSTEMPLATE':
987
+ case 'OBJECT_TSCONFIGURATION':
988
+ case 'OBJECT_COLLATION':
989
+ output.push(this.deparse(node.defnames));
990
+ break;
991
+
992
+ default:
993
+ throw new Error('DefineStmt not recognized');
994
+ }
995
+
996
+ if (!node.oldstyle && node.kind == 'OBJECT_AGGREGATE') {
997
+ output.push('(');
998
+ output.push(`${this.listQuotes(node.args[0], ',')}`);
999
+ output.push(')');
1000
+ }
1001
+
1002
+ if (node.definition.length > 0) {
1003
+ output.push('(');
1004
+
1005
+ for (let n = 0; n < node.definition.length; n++) {
1006
+ const defElement = node.definition[n].DefElem;
1007
+ output.push(defElement.defname);
1008
+
1009
+ if (defElement.arg) {
1010
+ output.push('=');
1011
+ output.push(this.deparse(defElement.arg));
1012
+ }
1013
+
1014
+ if (n !== node.definition.length - 1) {
1015
+ output.push(',');
1016
+ }
1017
+ }
1018
+
1019
+ output.push(')');
1020
+ }
1021
+
1022
+ return output.join(' ');
1023
+ }
1024
+
923
1025
  ['DefElem'](node, context = {}) {
924
1026
  if (node.defname === 'transaction_isolation') {
925
1027
  return format('ISOLATION LEVEL %s', node.arg.A_Const.val.String.str.toUpperCase());
@@ -943,7 +1045,7 @@ export default class Deparser {
943
1045
  name = `${node.defnamespace}.${node.defname}`;
944
1046
  }
945
1047
 
946
- if (context === 'generated') {
1048
+ if (context === 'generated' || context === 'sequence') {
947
1049
  switch (name) {
948
1050
  case 'start':
949
1051
  {
@@ -954,16 +1056,20 @@ export default class Deparser {
954
1056
  case 'increment':
955
1057
  {
956
1058
  const inc = this.deparse(node.arg, context);
1059
+
1060
+ if (context === 'sequence') {
1061
+ // we need 'simple' so it doesn't wrap negative numbers in parens
1062
+ return `${name} ${this.deparse(node.arg, 'simple')}`;
1063
+ }
1064
+
957
1065
  return `INCREMENT BY ${inc}`;
958
1066
  }
959
1067
 
960
- default:
961
- throw new Error('NOT_IMPLEMENTED');
962
- }
963
- }
1068
+ case 'sequence_name':
1069
+ {
1070
+ return `SEQUENCE NAME ${this.listQuotes(node.arg, '.')}`;
1071
+ }
964
1072
 
965
- if (context === 'sequence') {
966
- switch (name) {
967
1073
  case 'cycle':
968
1074
  {
969
1075
  const on = this.deparse(node.arg, context) + '' === '1';
@@ -981,6 +1087,26 @@ export default class Deparser {
981
1087
  const off = !node.hasOwnProperty('arg');
982
1088
  return off ? 'NO MAXVALUE' : `${name} ${this.deparse(node.arg, 'simple')}`;
983
1089
  }
1090
+ // alter
1091
+
1092
+ case 'owned_by':
1093
+ {
1094
+ const output = [];
1095
+ node.arg.forEach(opt => {
1096
+ output.push(this.quote(this.deparse(opt, context)));
1097
+ });
1098
+ return `OWNED BY ${output.join('.')}`;
1099
+ }
1100
+ // alter
1101
+
1102
+ case 'restart':
1103
+ {
1104
+ if (node.arg) {
1105
+ return `RESTART WITH ${this.deparse(node.arg, context)}`;
1106
+ }
1107
+
1108
+ return `RESTART`;
1109
+ }
984
1110
 
985
1111
  default:
986
1112
  if (node.arg) {
@@ -1628,10 +1754,10 @@ export default class Deparser {
1628
1754
  if (node.distinctClause) {
1629
1755
  if (!isEmptyObject(node.distinctClause[0]) // new change distinctClause can be {}
1630
1756
  ) {
1631
- output.push('DISTINCT ON');
1632
- const clause = node.distinctClause.map(e => this.deparse(e, 'select')).join(`,${NEWLINE_CHAR}`);
1633
- output.push(`(${clause})`);
1634
- } else {
1757
+ output.push('DISTINCT ON');
1758
+ const clause = node.distinctClause.map(e => this.deparse(e, 'select')).join(`,${NEWLINE_CHAR}`);
1759
+ output.push(`(${clause})`);
1760
+ } else {
1635
1761
  output.push('DISTINCT');
1636
1762
  }
1637
1763
  }
@@ -1887,6 +2013,11 @@ export default class Deparser {
1887
2013
  output.push('(');
1888
2014
  output.push(this.list(node.def, ', ', '', context));
1889
2015
  output.push(')');
2016
+ } else if (node.subtype === 'AT_AddIdentity') {
2017
+ output.push('ALTER COLUMN');
2018
+ output.push(this.quote(node.name));
2019
+ output.push('ADD');
2020
+ output.push(this.deparse(node.def, context));
1890
2021
  } else if (node.subtype === 'AT_AddInherit') {
1891
2022
  output.push('INHERIT');
1892
2023
  output.push(this.deparse(node.def, context));
@@ -2221,6 +2352,20 @@ export default class Deparser {
2221
2352
  return output.join(' ');
2222
2353
  }
2223
2354
 
2355
+ ['AlterSeqStmt'](node, context = {}) {
2356
+ const output = [];
2357
+ output.push('ALTER SEQUENCE');
2358
+ output.push(this.RangeVar(node.sequence, context));
2359
+
2360
+ if (node.options && node.options.length) {
2361
+ node.options.forEach(opt => {
2362
+ output.push(this.deparse(opt, 'sequence'));
2363
+ });
2364
+ }
2365
+
2366
+ return output.join(' ');
2367
+ }
2368
+
2224
2369
  ['CreateTableAsStmt'](node, context = {}) {
2225
2370
  const output = [];
2226
2371
  output.push('CREATE MATERIALIZED VIEW');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pgsql-deparser",
3
- "version": "13.1.8",
3
+ "version": "13.1.12",
4
4
  "description": "PostgreSQL AST Deparser",
5
5
  "author": "Dan Lynch <pyramation@gmail.com>",
6
6
  "homepage": "https://github.com/pyramation/pgsql-parser",
@@ -65,15 +65,15 @@
65
65
  "eslint-plugin-prettier": "^3.1.2",
66
66
  "glob": "7.1.6",
67
67
  "jest": "^25.1.0",
68
- "pgsql-parser": "^13.1.8",
68
+ "pgsql-parser": "^13.1.12",
69
69
  "prettier": "^2.1.2",
70
70
  "regenerator-runtime": "^0.13.2"
71
71
  },
72
72
  "dependencies": {
73
73
  "@babel/runtime": "^7.11.2",
74
- "dotty": "0.1.0",
75
- "lodash": "4.17.20",
74
+ "dotty": "^0.1.0",
75
+ "lodash": "^4.17.20",
76
76
  "pgsql-enums": "^13.1.2"
77
77
  },
78
- "gitHead": "89c13fe4fb35e4dfee6e665b090c83d8b8ab3c6d"
78
+ "gitHead": "a22c6431acab41881e65514b24e6da462eec31d4"
79
79
  }