pgsql-deparser 13.3.8 → 13.3.11

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,30 @@
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.3.11](https://github.com/pyramation/pgsql-parser/compare/pgsql-deparser@13.3.10...pgsql-deparser@13.3.11) (2022-05-20)
7
+
8
+ **Note:** Version bump only for package pgsql-deparser
9
+
10
+
11
+
12
+
13
+
14
+ ## [13.3.10](https://github.com/pyramation/pgsql-parser/compare/pgsql-deparser@13.3.9...pgsql-deparser@13.3.10) (2022-05-19)
15
+
16
+ **Note:** Version bump only for package pgsql-deparser
17
+
18
+
19
+
20
+
21
+
22
+ ## [13.3.9](https://github.com/pyramation/pgsql-parser/compare/pgsql-deparser@13.3.8...pgsql-deparser@13.3.9) (2022-04-19)
23
+
24
+ **Note:** Version bump only for package pgsql-deparser
25
+
26
+
27
+
28
+
29
+
6
30
  ## [13.3.8](https://github.com/pyramation/pgsql-parser/compare/pgsql-deparser@13.3.7...pgsql-deparser@13.3.8) (2022-04-19)
7
31
 
8
32
  **Note:** Version bump only for package pgsql-deparser
package/main/deparser.js CHANGED
@@ -45,7 +45,18 @@ var fail = function fail(type, node) {
45
45
  }; // select word from pg_get_keywords() where catcode = 'R';
46
46
 
47
47
 
48
- var RESERVED_WORDS = ['all', 'analyse', 'analyze', 'and', 'any', 'array', 'as', 'asc', 'asymmetric', 'both', 'case', 'cast', 'check', 'collate', 'column', 'constraint', 'create', 'current_catalog', 'current_date', 'current_role', 'current_time', 'current_timestamp', 'current_user', 'default', 'deferrable', 'desc', 'distinct', 'do', 'else', 'end', 'except', 'false', 'fetch', 'for', 'foreign', 'from', 'grant', 'group', 'having', 'in', 'initially', 'intersect', 'into', 'lateral', 'leading', 'limit', 'localtime', 'localtimestamp', 'not', 'null', 'offset', 'on', 'only', 'or', 'order', 'placing', 'primary', 'references', 'returning', 'select', 'session_user', 'some', 'symmetric', 'table', 'then', 'to', 'trailing', 'true', 'union', 'unique', 'user', 'using', 'variadic', 'when', 'where', 'window', 'with'];
48
+ var RESERVED_WORDS = ['all', 'analyse', 'analyze', 'and', 'any', 'array', 'as', 'asc', 'asymmetric', 'both', 'case', 'cast', 'check', 'collate', 'column', 'constraint', 'create', 'current_catalog', 'current_date', 'current_role', 'current_time', 'current_timestamp', 'current_user', 'default', 'deferrable', 'desc', 'distinct', 'do', 'else', 'end', 'except', 'false', 'fetch', 'for', 'foreign', 'from', 'grant', 'group', 'having', 'in', 'initially', 'intersect', 'into', 'lateral', 'leading', 'limit', 'localtime', 'localtimestamp', 'not', 'null', 'offset', 'on', 'only', 'or', 'order', 'placing', 'primary', 'references', 'returning', 'select', 'session_user', 'some', 'symmetric', 'table', 'then', 'to', 'trailing', 'true', 'union', 'unique', 'user', 'using', 'variadic', 'when', 'where', 'window', 'with']; // https://github.com/pganalyze/libpg_query/blob/b2790f8140721ff7f047167ecd7d44267b0a3880/src/postgres/include/storage/lockdefs.h
49
+
50
+ var LOCK_MODES = {
51
+ 1: 'ACCESS SHARE',
52
+ 2: 'ROW SHARE',
53
+ 3: 'ROW EXCLUSIVE',
54
+ 4: 'SHARE UPDATE EXCLUSIVE',
55
+ 5: 'SHARE',
56
+ 6: 'SHARE ROW',
57
+ 7: 'EXCLUSIVE',
58
+ 8: 'ACCESS EXCLUSIVE'
59
+ };
49
60
 
50
61
  var isReserved = function isReserved(value) {
51
62
  return RESERVED_WORDS.includes(value.toLowerCase());
@@ -1699,6 +1710,28 @@ var Deparser = /*#__PURE__*/function () {
1699
1710
  return output.join(' ');
1700
1711
  }
1701
1712
  }, {
1713
+ key: 'LockStmt',
1714
+ value: function LockStmt(node) {
1715
+ var _this11 = this;
1716
+
1717
+ var context = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1718
+ var output = ['LOCK'];
1719
+ output.push(node.relations.map(function (e) {
1720
+ return _this11.deparse(e, {
1721
+ lock: true
1722
+ });
1723
+ }).join(', '));
1724
+ output.push('IN');
1725
+ output.push(LOCK_MODES[node.mode]);
1726
+ output.push('MODE');
1727
+
1728
+ if (node.nowait) {
1729
+ output.push('NOWAIT');
1730
+ }
1731
+
1732
+ return output.join(' ');
1733
+ }
1734
+ }, {
1702
1735
  key: 'MinMaxExpr',
1703
1736
  value: function MinMaxExpr(node) {
1704
1737
  var context = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
@@ -1847,11 +1880,11 @@ var Deparser = /*#__PURE__*/function () {
1847
1880
 
1848
1881
  if (node.inhOpt === 0) {
1849
1882
  output.push('ONLY');
1850
- } // TODO why does this seem to be what we really need vs the above?
1851
- // if (!node.inh) {
1852
- // output.push('ONLY');
1853
- // }
1883
+ }
1854
1884
 
1885
+ if (!node.inh && context.lock) {
1886
+ output.push('ONLY');
1887
+ }
1855
1888
 
1856
1889
  if (node.relpersistence === 'u') {
1857
1890
  output.push('UNLOGGED');
@@ -1911,7 +1944,7 @@ var Deparser = /*#__PURE__*/function () {
1911
1944
  }, {
1912
1945
  key: 'SelectStmt',
1913
1946
  value: function SelectStmt(node) {
1914
- var _this11 = this;
1947
+ var _this12 = this;
1915
1948
 
1916
1949
  var context = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1917
1950
  var output = [];
@@ -1961,7 +1994,7 @@ var Deparser = /*#__PURE__*/function () {
1961
1994
  ) {
1962
1995
  output.push('DISTINCT ON');
1963
1996
  var clause = node.distinctClause.map(function (e) {
1964
- return _this11.deparse(e, 'select');
1997
+ return _this12.deparse(e, 'select');
1965
1998
  }).join(",".concat(NEWLINE_CHAR));
1966
1999
  output.push("(".concat(clause, ")"));
1967
2000
  } else {
@@ -1971,7 +2004,7 @@ var Deparser = /*#__PURE__*/function () {
1971
2004
 
1972
2005
  if (node.targetList) {
1973
2006
  output.push(indent(node.targetList.map(function (e) {
1974
- return _this11.deparse(e, 'select');
2007
+ return _this12.deparse(e, 'select');
1975
2008
  }).join(",".concat(NEWLINE_CHAR))));
1976
2009
  }
1977
2010
 
@@ -1983,7 +2016,7 @@ var Deparser = /*#__PURE__*/function () {
1983
2016
  if (node.fromClause) {
1984
2017
  output.push('FROM');
1985
2018
  output.push(indent(node.fromClause.map(function (e) {
1986
- return _this11.deparse(e, 'from');
2019
+ return _this12.deparse(e, 'from');
1987
2020
  }).join(",".concat(NEWLINE_CHAR))));
1988
2021
  }
1989
2022
 
@@ -1995,7 +2028,7 @@ var Deparser = /*#__PURE__*/function () {
1995
2028
  if (node.valuesLists) {
1996
2029
  output.push('VALUES');
1997
2030
  var lists = node.valuesLists.map(function (list) {
1998
- return "(".concat(_this11.list(list, ', ', '', context), ")");
2031
+ return "(".concat(_this12.list(list, ', ', '', context), ")");
1999
2032
  });
2000
2033
  output.push(lists.join(', '));
2001
2034
  }
@@ -2003,7 +2036,7 @@ var Deparser = /*#__PURE__*/function () {
2003
2036
  if (node.groupClause) {
2004
2037
  output.push('GROUP BY');
2005
2038
  output.push(indent(node.groupClause.map(function (e) {
2006
- return _this11.deparse(e, 'group');
2039
+ return _this12.deparse(e, 'group');
2007
2040
  }).join(",".concat(NEWLINE_CHAR))));
2008
2041
  }
2009
2042
 
@@ -2034,7 +2067,7 @@ var Deparser = /*#__PURE__*/function () {
2034
2067
  if (node.sortClause) {
2035
2068
  output.push('ORDER BY');
2036
2069
  output.push(indent(node.sortClause.map(function (e) {
2037
- return _this11.deparse(e, 'sort');
2070
+ return _this12.deparse(e, 'sort');
2038
2071
  }).join(",".concat(NEWLINE_CHAR))));
2039
2072
  }
2040
2073
 
@@ -2050,7 +2083,7 @@ var Deparser = /*#__PURE__*/function () {
2050
2083
 
2051
2084
  if (node.lockingClause) {
2052
2085
  node.lockingClause.forEach(function (item) {
2053
- return output.push(_this11.deparse(item, context));
2086
+ return output.push(_this12.deparse(item, context));
2054
2087
  });
2055
2088
  }
2056
2089
 
@@ -2360,7 +2393,7 @@ var Deparser = /*#__PURE__*/function () {
2360
2393
  }, {
2361
2394
  key: 'CreateExtensionStmt',
2362
2395
  value: function CreateExtensionStmt(node) {
2363
- var _this12 = this;
2396
+ var _this13 = this;
2364
2397
 
2365
2398
  var output = [];
2366
2399
  output.push('CREATE EXTENSION');
@@ -2379,7 +2412,7 @@ var Deparser = /*#__PURE__*/function () {
2379
2412
 
2380
2413
  if (opt.DefElem.defname === 'schema') {
2381
2414
  output.push('WITH SCHEMA');
2382
- output.push(_this12.quote(_this12.deparse(opt.DefElem.arg)));
2415
+ output.push(_this13.quote(_this13.deparse(opt.DefElem.arg)));
2383
2416
  }
2384
2417
  });
2385
2418
  }
@@ -2588,7 +2621,7 @@ var Deparser = /*#__PURE__*/function () {
2588
2621
  }, {
2589
2622
  key: 'CreateSeqStmt',
2590
2623
  value: function CreateSeqStmt(node) {
2591
- var _this13 = this;
2624
+ var _this14 = this;
2592
2625
 
2593
2626
  var context = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
2594
2627
  var output = [];
@@ -2597,7 +2630,7 @@ var Deparser = /*#__PURE__*/function () {
2597
2630
 
2598
2631
  if (node.options && node.options.length) {
2599
2632
  node.options.forEach(function (opt) {
2600
- output.push(_this13.deparse(opt, 'sequence'));
2633
+ output.push(_this14.deparse(opt, 'sequence'));
2601
2634
  });
2602
2635
  }
2603
2636
 
@@ -2606,7 +2639,7 @@ var Deparser = /*#__PURE__*/function () {
2606
2639
  }, {
2607
2640
  key: 'AlterSeqStmt',
2608
2641
  value: function AlterSeqStmt(node) {
2609
- var _this14 = this;
2642
+ var _this15 = this;
2610
2643
 
2611
2644
  var context = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
2612
2645
  var output = [];
@@ -2615,7 +2648,7 @@ var Deparser = /*#__PURE__*/function () {
2615
2648
 
2616
2649
  if (node.options && node.options.length) {
2617
2650
  node.options.forEach(function (opt) {
2618
- output.push(_this14.deparse(opt, 'sequence'));
2651
+ output.push(_this15.deparse(opt, 'sequence'));
2619
2652
  });
2620
2653
  }
2621
2654
 
@@ -2635,7 +2668,7 @@ var Deparser = /*#__PURE__*/function () {
2635
2668
  }, {
2636
2669
  key: 'CreateTrigStmt',
2637
2670
  value: function CreateTrigStmt(node) {
2638
- var _this15 = this;
2671
+ var _this16 = this;
2639
2672
 
2640
2673
  var context = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
2641
2674
  var output = [];
@@ -2754,7 +2787,7 @@ var Deparser = /*#__PURE__*/function () {
2754
2787
  return "'".concat(dotty.get(arg, 'String.str'), "'");
2755
2788
  }
2756
2789
 
2757
- return _this15.deparse(arg, context);
2790
+ return _this16.deparse(arg, context);
2758
2791
  }).filter(function (a) {
2759
2792
  return a;
2760
2793
  });
@@ -2789,6 +2822,10 @@ var Deparser = /*#__PURE__*/function () {
2789
2822
  output.push('CREATE');
2790
2823
  } else {
2791
2824
  output.push('CREATE TABLE');
2825
+
2826
+ if (node.if_not_exists) {
2827
+ output.push('IF NOT EXISTS');
2828
+ }
2792
2829
  }
2793
2830
 
2794
2831
  output.push(this.RangeVar(node.relation, context));
@@ -2913,17 +2950,17 @@ var Deparser = /*#__PURE__*/function () {
2913
2950
  var output = [];
2914
2951
 
2915
2952
  function getExclusionGroup(nde) {
2916
- var _this16 = this;
2953
+ var _this17 = this;
2917
2954
 
2918
2955
  var a = nde.exclusions.map(function (excl) {
2919
2956
  if (excl[0].IndexElem.name) {
2920
2957
  return excl[0].IndexElem.name;
2921
2958
  }
2922
2959
 
2923
- return excl[0].IndexElem.expr ? _this16.deparse(excl[0].IndexElem.expr, context) : null;
2960
+ return excl[0].IndexElem.expr ? _this17.deparse(excl[0].IndexElem.expr, context) : null;
2924
2961
  });
2925
2962
  var b = nde.exclusions.map(function (excl) {
2926
- return _this16.deparse(excl[1][0], context);
2963
+ return _this17.deparse(excl[1][0], context);
2927
2964
  });
2928
2965
  var stmts = a.map(function (_v, i) {
2929
2966
  return "".concat(a[i], " WITH ").concat(b[i]);
@@ -3141,7 +3178,7 @@ var Deparser = /*#__PURE__*/function () {
3141
3178
  }, {
3142
3179
  key: 'CreateFunctionStmt',
3143
3180
  value: function CreateFunctionStmt(node) {
3144
- var _this17 = this;
3181
+ var _this18 = this;
3145
3182
 
3146
3183
  var context = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
3147
3184
  var output = [];
@@ -3153,7 +3190,7 @@ var Deparser = /*#__PURE__*/function () {
3153
3190
 
3154
3191
  output.push('FUNCTION');
3155
3192
  output.push(node.funcname.map(function (name) {
3156
- return _this17.deparse(name, context);
3193
+ return _this18.deparse(name, context);
3157
3194
  }).join('.'));
3158
3195
  output.push('(');
3159
3196
  var parameters = [];
@@ -3190,12 +3227,12 @@ var Deparser = /*#__PURE__*/function () {
3190
3227
 
3191
3228
  switch (option.DefElem.defname) {
3192
3229
  case 'as':
3193
- value = _this17.deparse(option.DefElem.arg[0], context);
3230
+ value = _this18.deparse(option.DefElem.arg[0], context);
3194
3231
  output.push("AS $EOFCODE$".concat(value, "$EOFCODE$"));
3195
3232
  break;
3196
3233
 
3197
3234
  case 'language':
3198
- value = _this17.deparse(option.DefElem.arg, context);
3235
+ value = _this18.deparse(option.DefElem.arg, context);
3199
3236
  output.push('LANGUAGE');
3200
3237
  output.push(value);
3201
3238
  break;
@@ -3242,11 +3279,11 @@ var Deparser = /*#__PURE__*/function () {
3242
3279
  break;
3243
3280
 
3244
3281
  case 'set':
3245
- output.push(_this17.deparse(option, context));
3282
+ output.push(_this18.deparse(option, context));
3246
3283
  break;
3247
3284
 
3248
3285
  case 'volatility':
3249
- value = _this17.deparse(option.DefElem.arg, context);
3286
+ value = _this18.deparse(option.DefElem.arg, context);
3250
3287
  output.push(value.toUpperCase());
3251
3288
  break;
3252
3289
 
@@ -3443,7 +3480,7 @@ var Deparser = /*#__PURE__*/function () {
3443
3480
  }, {
3444
3481
  key: 'CreateRoleStmt',
3445
3482
  value: function CreateRoleStmt(node) {
3446
- var _this18 = this;
3483
+ var _this19 = this;
3447
3484
 
3448
3485
  var context = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
3449
3486
  var output = [];
@@ -3504,12 +3541,12 @@ var Deparser = /*#__PURE__*/function () {
3504
3541
 
3505
3542
  case 'adminmembers':
3506
3543
  output.push('ADMIN');
3507
- output.push(_this18.list(node.options[i].DefElem.arg, ', ', '', context));
3544
+ output.push(_this19.list(node.options[i].DefElem.arg, ', ', '', context));
3508
3545
  break;
3509
3546
 
3510
3547
  case 'rolemembers':
3511
3548
  output.push('USER');
3512
- output.push(_this18.list(node.options[i].DefElem.arg, ', ', '', context));
3549
+ output.push(_this19.list(node.options[i].DefElem.arg, ', ', '', context));
3513
3550
  break;
3514
3551
 
3515
3552
  case 'createdb':
@@ -3552,7 +3589,7 @@ var Deparser = /*#__PURE__*/function () {
3552
3589
  }, {
3553
3590
  key: 'TransactionStmt',
3554
3591
  value: function TransactionStmt(node) {
3555
- var _this19 = this;
3592
+ var _this20 = this;
3556
3593
 
3557
3594
  var context = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
3558
3595
  var output = [];
@@ -3564,7 +3601,7 @@ var Deparser = /*#__PURE__*/function () {
3564
3601
  var index = opts.indexOf('transaction_read_only');
3565
3602
  var obj = nodeOpts.options[index];
3566
3603
  var set = false;
3567
- var flag = Number(_this19.deparse(dotty.get(obj, 'DefElem.arg'), context));
3604
+ var flag = Number(_this20.deparse(dotty.get(obj, 'DefElem.arg'), context));
3568
3605
 
3569
3606
  if (flag > 0) {
3570
3607
  set = true;
@@ -3582,7 +3619,7 @@ var Deparser = /*#__PURE__*/function () {
3582
3619
 
3583
3620
  var _obj = nodeOpts.options[_index];
3584
3621
 
3585
- var lopts = _this19.deparse(dotty.get(_obj, 'DefElem.arg'), context).replace(/['"]+/g, '');
3622
+ var lopts = _this20.deparse(dotty.get(_obj, 'DefElem.arg'), context).replace(/['"]+/g, '');
3586
3623
 
3587
3624
  return "BEGIN TRANSACTION ISOLATION LEVEL ".concat(lopts.toUpperCase());
3588
3625
  }
@@ -3597,7 +3634,7 @@ var Deparser = /*#__PURE__*/function () {
3597
3634
  var index = opts.indexOf('transaction_read_only');
3598
3635
  var obj = nodeOpts.options[index];
3599
3636
  var set = false;
3600
- var flag = Number(_this19.deparse(dotty.get(obj, 'DefElem.arg'), context));
3637
+ var flag = Number(_this20.deparse(dotty.get(obj, 'DefElem.arg'), context));
3601
3638
 
3602
3639
  if (flag > 0) {
3603
3640
  set = true;
@@ -3701,7 +3738,7 @@ var Deparser = /*#__PURE__*/function () {
3701
3738
  }, {
3702
3739
  key: 'ObjectWithArgs',
3703
3740
  value: function ObjectWithArgs(node) {
3704
- var _this20 = this;
3741
+ var _this21 = this;
3705
3742
 
3706
3743
  var context = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
3707
3744
  var output = [];
@@ -3719,7 +3756,7 @@ var Deparser = /*#__PURE__*/function () {
3719
3756
  return 'NONE';
3720
3757
  }
3721
3758
 
3722
- return _this20.deparse(arg, context);
3759
+ return _this21.deparse(arg, context);
3723
3760
  }).join(','));
3724
3761
  output.push(')');
3725
3762
  } else if (!node.args_unspecified) {
@@ -3798,7 +3835,7 @@ var Deparser = /*#__PURE__*/function () {
3798
3835
  }, {
3799
3836
  key: 'TypeName',
3800
3837
  value: function TypeName(node) {
3801
- var _this21 = this;
3838
+ var _this22 = this;
3802
3839
 
3803
3840
  var context = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
3804
3841
 
@@ -3816,7 +3853,7 @@ var Deparser = /*#__PURE__*/function () {
3816
3853
 
3817
3854
  if (node.typmods != null) {
3818
3855
  args = node.typmods.map(function (item) {
3819
- return _this21.deparse(item, context);
3856
+ return _this22.deparse(item, context);
3820
3857
  });
3821
3858
  }
3822
3859
 
@@ -3843,7 +3880,7 @@ var Deparser = /*#__PURE__*/function () {
3843
3880
  }, {
3844
3881
  key: 'WindowDef',
3845
3882
  value: function WindowDef(node) {
3846
- var _this22 = this;
3883
+ var _this23 = this;
3847
3884
 
3848
3885
  var context = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
3849
3886
  var output = [];
@@ -3867,7 +3904,7 @@ var Deparser = /*#__PURE__*/function () {
3867
3904
  if (node.partitionClause) {
3868
3905
  var partition = ['PARTITION BY'];
3869
3906
  var clause = node.partitionClause.map(function (item) {
3870
- return _this22.deparse(item, context);
3907
+ return _this23.deparse(item, context);
3871
3908
  });
3872
3909
  partition.push(clause.join(', '));
3873
3910
  windowParts.push(partition.join(' '));
@@ -3877,7 +3914,7 @@ var Deparser = /*#__PURE__*/function () {
3877
3914
  if (node.orderClause) {
3878
3915
  windowParts.push('ORDER BY');
3879
3916
  var orders = node.orderClause.map(function (item) {
3880
- return _this22.deparse(item);
3917
+ return _this23.deparse(item);
3881
3918
  });
3882
3919
  windowParts.push(orders.join(', '));
3883
3920
  useParens = true;
@@ -4084,7 +4121,7 @@ var Deparser = /*#__PURE__*/function () {
4084
4121
  }, {
4085
4122
  key: "deparseInterval",
4086
4123
  value: function deparseInterval(node) {
4087
- var _this23 = this;
4124
+ var _this24 = this;
4088
4125
 
4089
4126
  var type = ['interval'];
4090
4127
 
@@ -4094,7 +4131,7 @@ var Deparser = /*#__PURE__*/function () {
4094
4131
 
4095
4132
  if (node.typmods) {
4096
4133
  var typmods = node.typmods.map(function (item) {
4097
- return _this23.deparse(item);
4134
+ return _this24.deparse(item);
4098
4135
  });
4099
4136
  var intervals = this.interval(typmods[0]); // SELECT interval(0) '1 day 01:23:45.6789'
4100
4137
 
@@ -22,7 +22,18 @@ const fail = (type, node) => {
22
22
  }; // select word from pg_get_keywords() where catcode = 'R';
23
23
 
24
24
 
25
- const RESERVED_WORDS = ['all', 'analyse', 'analyze', 'and', 'any', 'array', 'as', 'asc', 'asymmetric', 'both', 'case', 'cast', 'check', 'collate', 'column', 'constraint', 'create', 'current_catalog', 'current_date', 'current_role', 'current_time', 'current_timestamp', 'current_user', 'default', 'deferrable', 'desc', 'distinct', 'do', 'else', 'end', 'except', 'false', 'fetch', 'for', 'foreign', 'from', 'grant', 'group', 'having', 'in', 'initially', 'intersect', 'into', 'lateral', 'leading', 'limit', 'localtime', 'localtimestamp', 'not', 'null', 'offset', 'on', 'only', 'or', 'order', 'placing', 'primary', 'references', 'returning', 'select', 'session_user', 'some', 'symmetric', 'table', 'then', 'to', 'trailing', 'true', 'union', 'unique', 'user', 'using', 'variadic', 'when', 'where', 'window', 'with'];
25
+ const RESERVED_WORDS = ['all', 'analyse', 'analyze', 'and', 'any', 'array', 'as', 'asc', 'asymmetric', 'both', 'case', 'cast', 'check', 'collate', 'column', 'constraint', 'create', 'current_catalog', 'current_date', 'current_role', 'current_time', 'current_timestamp', 'current_user', 'default', 'deferrable', 'desc', 'distinct', 'do', 'else', 'end', 'except', 'false', 'fetch', 'for', 'foreign', 'from', 'grant', 'group', 'having', 'in', 'initially', 'intersect', 'into', 'lateral', 'leading', 'limit', 'localtime', 'localtimestamp', 'not', 'null', 'offset', 'on', 'only', 'or', 'order', 'placing', 'primary', 'references', 'returning', 'select', 'session_user', 'some', 'symmetric', 'table', 'then', 'to', 'trailing', 'true', 'union', 'unique', 'user', 'using', 'variadic', 'when', 'where', 'window', 'with']; // https://github.com/pganalyze/libpg_query/blob/b2790f8140721ff7f047167ecd7d44267b0a3880/src/postgres/include/storage/lockdefs.h
26
+
27
+ const LOCK_MODES = {
28
+ 1: 'ACCESS SHARE',
29
+ 2: 'ROW SHARE',
30
+ 3: 'ROW EXCLUSIVE',
31
+ 4: 'SHARE UPDATE EXCLUSIVE',
32
+ 5: 'SHARE',
33
+ 6: 'SHARE ROW',
34
+ 7: 'EXCLUSIVE',
35
+ 8: 'ACCESS EXCLUSIVE'
36
+ };
26
37
 
27
38
  const isReserved = value => RESERVED_WORDS.includes(value.toLowerCase()); // usually the AST lowercases all the things, so if we
28
39
  // have both, the author most likely used double quotes
@@ -1532,6 +1543,22 @@ export default class Deparser {
1532
1543
  return output.join(' ');
1533
1544
  }
1534
1545
 
1546
+ ['LockStmt'](node, context = {}) {
1547
+ const output = ['LOCK'];
1548
+ output.push(node.relations.map(e => this.deparse(e, {
1549
+ lock: true
1550
+ })).join(', '));
1551
+ output.push('IN');
1552
+ output.push(LOCK_MODES[node.mode]);
1553
+ output.push('MODE');
1554
+
1555
+ if (node.nowait) {
1556
+ output.push('NOWAIT');
1557
+ }
1558
+
1559
+ return output.join(' ');
1560
+ }
1561
+
1535
1562
  ['MinMaxExpr'](node, context = {}) {
1536
1563
  const output = [];
1537
1564
 
@@ -1664,11 +1691,11 @@ export default class Deparser {
1664
1691
 
1665
1692
  if (node.inhOpt === 0) {
1666
1693
  output.push('ONLY');
1667
- } // TODO why does this seem to be what we really need vs the above?
1668
- // if (!node.inh) {
1669
- // output.push('ONLY');
1670
- // }
1694
+ }
1671
1695
 
1696
+ if (!node.inh && context.lock) {
1697
+ output.push('ONLY');
1698
+ }
1672
1699
 
1673
1700
  if (node.relpersistence === 'u') {
1674
1701
  output.push('UNLOGGED');
@@ -2538,6 +2565,10 @@ export default class Deparser {
2538
2565
  output.push('CREATE');
2539
2566
  } else {
2540
2567
  output.push('CREATE TABLE');
2568
+
2569
+ if (node.if_not_exists) {
2570
+ output.push('IF NOT EXISTS');
2571
+ }
2541
2572
  }
2542
2573
 
2543
2574
  output.push(this.RangeVar(node.relation, context));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pgsql-deparser",
3
- "version": "13.3.8",
3
+ "version": "13.3.11",
4
4
  "description": "PostgreSQL AST Deparser",
5
5
  "author": "Dan Lynch <pyramation@gmail.com>",
6
6
  "homepage": "https://github.com/pyramation/pgsql-parser",
@@ -65,7 +65,7 @@
65
65
  "eslint-plugin-prettier": "^3.1.2",
66
66
  "glob": "7.1.6",
67
67
  "jest": "^25.1.0",
68
- "pgsql-parser": "^13.3.8",
68
+ "pgsql-parser": "^13.3.11",
69
69
  "prettier": "^2.1.2",
70
70
  "regenerator-runtime": "^0.13.2"
71
71
  },
@@ -75,5 +75,5 @@
75
75
  "lodash": "^4.17.20",
76
76
  "pgsql-enums": "^13.1.2"
77
77
  },
78
- "gitHead": "b5341b62b3fa7d239ba8a285382d9ffda0deacfd"
78
+ "gitHead": "3000794fa5f3a0e3e0d3a05cb1cee76f99124557"
79
79
  }