pgsql-deparser 13.1.9 → 13.1.13

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.13](https://github.com/pyramation/pgsql-parser/compare/pgsql-deparser@13.1.12...pgsql-deparser@13.1.13) (2022-01-07)
7
+
8
+ **Note:** Version bump only for package pgsql-deparser
9
+
10
+
11
+
12
+
13
+
14
+ ## [13.1.12](https://github.com/pyramation/pgsql-parser/compare/pgsql-deparser@13.1.11...pgsql-deparser@13.1.12) (2022-01-05)
15
+
16
+ **Note:** Version bump only for package pgsql-deparser
17
+
18
+
19
+
20
+
21
+
22
+ ## [13.1.11](https://github.com/pyramation/pgsql-parser/compare/pgsql-deparser@13.1.10...pgsql-deparser@13.1.11) (2021-10-19)
23
+
24
+ **Note:** Version bump only for package pgsql-deparser
25
+
26
+
27
+
28
+
29
+
30
+ ## [13.1.10](https://github.com/pyramation/pgsql-parser/compare/pgsql-deparser@13.1.9...pgsql-deparser@13.1.10) (2021-10-19)
31
+
32
+ **Note:** Version bump only for package pgsql-deparser
33
+
34
+
35
+
36
+
37
+
6
38
  ## [13.1.9](https://github.com/pyramation/pgsql-parser/compare/pgsql-deparser@13.1.8...pgsql-deparser@13.1.9) (2021-10-13)
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,6 +1034,110 @@ 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) {
1039
1143
  var _this7 = this;
@@ -1062,7 +1166,7 @@ var Deparser = /*#__PURE__*/function () {
1062
1166
  name = "".concat(node.defnamespace, ".").concat(node.defname);
1063
1167
  }
1064
1168
 
1065
- if (context === 'generated') {
1169
+ if (context === 'generated' || context === 'sequence') {
1066
1170
  switch (name) {
1067
1171
  case 'start':
1068
1172
  {
@@ -1073,16 +1177,20 @@ var Deparser = /*#__PURE__*/function () {
1073
1177
  case 'increment':
1074
1178
  {
1075
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
+
1076
1186
  return "INCREMENT BY ".concat(inc);
1077
1187
  }
1078
1188
 
1079
- default:
1080
- throw new Error('NOT_IMPLEMENTED');
1081
- }
1082
- }
1189
+ case 'sequence_name':
1190
+ {
1191
+ return "SEQUENCE NAME ".concat(this.listQuotes(node.arg, '.'));
1192
+ }
1083
1193
 
1084
- if (context === 'sequence') {
1085
- switch (name) {
1086
1194
  case 'cycle':
1087
1195
  {
1088
1196
  var on = this.deparse(node.arg, context) + '' === '1';
@@ -1107,17 +1215,12 @@ var Deparser = /*#__PURE__*/function () {
1107
1215
  {
1108
1216
  var output = [];
1109
1217
  node.arg.forEach(function (opt) {
1110
- output.push(_this7.quote(_this7.deparse(opt, 'sequence')));
1218
+ output.push(_this7.quote(_this7.deparse(opt, context)));
1111
1219
  });
1112
1220
  return "OWNED BY ".concat(output.join('.'));
1113
1221
  }
1114
1222
  // alter
1115
1223
 
1116
- case 'start':
1117
- {
1118
- return "START WITH ".concat(this.deparse(node.arg, context));
1119
- }
1120
-
1121
1224
  case 'restart':
1122
1225
  {
1123
1226
  if (node.arg) {
@@ -1847,12 +1950,12 @@ var Deparser = /*#__PURE__*/function () {
1847
1950
  if (node.distinctClause) {
1848
1951
  if (!isEmptyObject(node.distinctClause[0]) // new change distinctClause can be {}
1849
1952
  ) {
1850
- output.push('DISTINCT ON');
1851
- var clause = node.distinctClause.map(function (e) {
1852
- return _this11.deparse(e, 'select');
1853
- }).join(",".concat(NEWLINE_CHAR));
1854
- output.push("(".concat(clause, ")"));
1855
- } 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 {
1856
1959
  output.push('DISTINCT');
1857
1960
  }
1858
1961
  }
@@ -2124,6 +2227,11 @@ var Deparser = /*#__PURE__*/function () {
2124
2227
  output.push('(');
2125
2228
  output.push(this.list(node.def, ', ', '', context));
2126
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));
2127
2235
  } else if (node.subtype === 'AT_AddInherit') {
2128
2236
  output.push('INHERIT');
2129
2237
  output.push(this.deparse(node.def, context));
@@ -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';
@@ -987,17 +1093,12 @@ export default class Deparser {
987
1093
  {
988
1094
  const output = [];
989
1095
  node.arg.forEach(opt => {
990
- output.push(this.quote(this.deparse(opt, 'sequence')));
1096
+ output.push(this.quote(this.deparse(opt, context)));
991
1097
  });
992
1098
  return `OWNED BY ${output.join('.')}`;
993
1099
  }
994
1100
  // alter
995
1101
 
996
- case 'start':
997
- {
998
- return `START WITH ${this.deparse(node.arg, context)}`;
999
- }
1000
-
1001
1102
  case 'restart':
1002
1103
  {
1003
1104
  if (node.arg) {
@@ -1653,10 +1754,10 @@ export default class Deparser {
1653
1754
  if (node.distinctClause) {
1654
1755
  if (!isEmptyObject(node.distinctClause[0]) // new change distinctClause can be {}
1655
1756
  ) {
1656
- output.push('DISTINCT ON');
1657
- const clause = node.distinctClause.map(e => this.deparse(e, 'select')).join(`,${NEWLINE_CHAR}`);
1658
- output.push(`(${clause})`);
1659
- } 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 {
1660
1761
  output.push('DISTINCT');
1661
1762
  }
1662
1763
  }
@@ -1912,6 +2013,11 @@ export default class Deparser {
1912
2013
  output.push('(');
1913
2014
  output.push(this.list(node.def, ', ', '', context));
1914
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));
1915
2021
  } else if (node.subtype === 'AT_AddInherit') {
1916
2022
  output.push('INHERIT');
1917
2023
  output.push(this.deparse(node.def, context));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pgsql-deparser",
3
- "version": "13.1.9",
3
+ "version": "13.1.13",
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.9",
68
+ "pgsql-parser": "^13.1.13",
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": "656c440ca3cf29f5b70681b52b53a92e4174f110"
78
+ "gitHead": "dae375591a9a48ee61ec7a8209362b22b4a645db"
79
79
  }