pgsql-deparser 13.3.10 → 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,14 @@
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
+
6
14
  ## [13.3.10](https://github.com/pyramation/pgsql-parser/compare/pgsql-deparser@13.3.9...pgsql-deparser@13.3.10) (2022-05-19)
7
15
 
8
16
  **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
  });
@@ -2917,17 +2950,17 @@ var Deparser = /*#__PURE__*/function () {
2917
2950
  var output = [];
2918
2951
 
2919
2952
  function getExclusionGroup(nde) {
2920
- var _this16 = this;
2953
+ var _this17 = this;
2921
2954
 
2922
2955
  var a = nde.exclusions.map(function (excl) {
2923
2956
  if (excl[0].IndexElem.name) {
2924
2957
  return excl[0].IndexElem.name;
2925
2958
  }
2926
2959
 
2927
- 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;
2928
2961
  });
2929
2962
  var b = nde.exclusions.map(function (excl) {
2930
- return _this16.deparse(excl[1][0], context);
2963
+ return _this17.deparse(excl[1][0], context);
2931
2964
  });
2932
2965
  var stmts = a.map(function (_v, i) {
2933
2966
  return "".concat(a[i], " WITH ").concat(b[i]);
@@ -3145,7 +3178,7 @@ var Deparser = /*#__PURE__*/function () {
3145
3178
  }, {
3146
3179
  key: 'CreateFunctionStmt',
3147
3180
  value: function CreateFunctionStmt(node) {
3148
- var _this17 = this;
3181
+ var _this18 = this;
3149
3182
 
3150
3183
  var context = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
3151
3184
  var output = [];
@@ -3157,7 +3190,7 @@ var Deparser = /*#__PURE__*/function () {
3157
3190
 
3158
3191
  output.push('FUNCTION');
3159
3192
  output.push(node.funcname.map(function (name) {
3160
- return _this17.deparse(name, context);
3193
+ return _this18.deparse(name, context);
3161
3194
  }).join('.'));
3162
3195
  output.push('(');
3163
3196
  var parameters = [];
@@ -3194,12 +3227,12 @@ var Deparser = /*#__PURE__*/function () {
3194
3227
 
3195
3228
  switch (option.DefElem.defname) {
3196
3229
  case 'as':
3197
- value = _this17.deparse(option.DefElem.arg[0], context);
3230
+ value = _this18.deparse(option.DefElem.arg[0], context);
3198
3231
  output.push("AS $EOFCODE$".concat(value, "$EOFCODE$"));
3199
3232
  break;
3200
3233
 
3201
3234
  case 'language':
3202
- value = _this17.deparse(option.DefElem.arg, context);
3235
+ value = _this18.deparse(option.DefElem.arg, context);
3203
3236
  output.push('LANGUAGE');
3204
3237
  output.push(value);
3205
3238
  break;
@@ -3246,11 +3279,11 @@ var Deparser = /*#__PURE__*/function () {
3246
3279
  break;
3247
3280
 
3248
3281
  case 'set':
3249
- output.push(_this17.deparse(option, context));
3282
+ output.push(_this18.deparse(option, context));
3250
3283
  break;
3251
3284
 
3252
3285
  case 'volatility':
3253
- value = _this17.deparse(option.DefElem.arg, context);
3286
+ value = _this18.deparse(option.DefElem.arg, context);
3254
3287
  output.push(value.toUpperCase());
3255
3288
  break;
3256
3289
 
@@ -3447,7 +3480,7 @@ var Deparser = /*#__PURE__*/function () {
3447
3480
  }, {
3448
3481
  key: 'CreateRoleStmt',
3449
3482
  value: function CreateRoleStmt(node) {
3450
- var _this18 = this;
3483
+ var _this19 = this;
3451
3484
 
3452
3485
  var context = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
3453
3486
  var output = [];
@@ -3508,12 +3541,12 @@ var Deparser = /*#__PURE__*/function () {
3508
3541
 
3509
3542
  case 'adminmembers':
3510
3543
  output.push('ADMIN');
3511
- output.push(_this18.list(node.options[i].DefElem.arg, ', ', '', context));
3544
+ output.push(_this19.list(node.options[i].DefElem.arg, ', ', '', context));
3512
3545
  break;
3513
3546
 
3514
3547
  case 'rolemembers':
3515
3548
  output.push('USER');
3516
- output.push(_this18.list(node.options[i].DefElem.arg, ', ', '', context));
3549
+ output.push(_this19.list(node.options[i].DefElem.arg, ', ', '', context));
3517
3550
  break;
3518
3551
 
3519
3552
  case 'createdb':
@@ -3556,7 +3589,7 @@ var Deparser = /*#__PURE__*/function () {
3556
3589
  }, {
3557
3590
  key: 'TransactionStmt',
3558
3591
  value: function TransactionStmt(node) {
3559
- var _this19 = this;
3592
+ var _this20 = this;
3560
3593
 
3561
3594
  var context = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
3562
3595
  var output = [];
@@ -3568,7 +3601,7 @@ var Deparser = /*#__PURE__*/function () {
3568
3601
  var index = opts.indexOf('transaction_read_only');
3569
3602
  var obj = nodeOpts.options[index];
3570
3603
  var set = false;
3571
- var flag = Number(_this19.deparse(dotty.get(obj, 'DefElem.arg'), context));
3604
+ var flag = Number(_this20.deparse(dotty.get(obj, 'DefElem.arg'), context));
3572
3605
 
3573
3606
  if (flag > 0) {
3574
3607
  set = true;
@@ -3586,7 +3619,7 @@ var Deparser = /*#__PURE__*/function () {
3586
3619
 
3587
3620
  var _obj = nodeOpts.options[_index];
3588
3621
 
3589
- 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, '');
3590
3623
 
3591
3624
  return "BEGIN TRANSACTION ISOLATION LEVEL ".concat(lopts.toUpperCase());
3592
3625
  }
@@ -3601,7 +3634,7 @@ var Deparser = /*#__PURE__*/function () {
3601
3634
  var index = opts.indexOf('transaction_read_only');
3602
3635
  var obj = nodeOpts.options[index];
3603
3636
  var set = false;
3604
- var flag = Number(_this19.deparse(dotty.get(obj, 'DefElem.arg'), context));
3637
+ var flag = Number(_this20.deparse(dotty.get(obj, 'DefElem.arg'), context));
3605
3638
 
3606
3639
  if (flag > 0) {
3607
3640
  set = true;
@@ -3705,7 +3738,7 @@ var Deparser = /*#__PURE__*/function () {
3705
3738
  }, {
3706
3739
  key: 'ObjectWithArgs',
3707
3740
  value: function ObjectWithArgs(node) {
3708
- var _this20 = this;
3741
+ var _this21 = this;
3709
3742
 
3710
3743
  var context = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
3711
3744
  var output = [];
@@ -3723,7 +3756,7 @@ var Deparser = /*#__PURE__*/function () {
3723
3756
  return 'NONE';
3724
3757
  }
3725
3758
 
3726
- return _this20.deparse(arg, context);
3759
+ return _this21.deparse(arg, context);
3727
3760
  }).join(','));
3728
3761
  output.push(')');
3729
3762
  } else if (!node.args_unspecified) {
@@ -3802,7 +3835,7 @@ var Deparser = /*#__PURE__*/function () {
3802
3835
  }, {
3803
3836
  key: 'TypeName',
3804
3837
  value: function TypeName(node) {
3805
- var _this21 = this;
3838
+ var _this22 = this;
3806
3839
 
3807
3840
  var context = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
3808
3841
 
@@ -3820,7 +3853,7 @@ var Deparser = /*#__PURE__*/function () {
3820
3853
 
3821
3854
  if (node.typmods != null) {
3822
3855
  args = node.typmods.map(function (item) {
3823
- return _this21.deparse(item, context);
3856
+ return _this22.deparse(item, context);
3824
3857
  });
3825
3858
  }
3826
3859
 
@@ -3847,7 +3880,7 @@ var Deparser = /*#__PURE__*/function () {
3847
3880
  }, {
3848
3881
  key: 'WindowDef',
3849
3882
  value: function WindowDef(node) {
3850
- var _this22 = this;
3883
+ var _this23 = this;
3851
3884
 
3852
3885
  var context = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
3853
3886
  var output = [];
@@ -3871,7 +3904,7 @@ var Deparser = /*#__PURE__*/function () {
3871
3904
  if (node.partitionClause) {
3872
3905
  var partition = ['PARTITION BY'];
3873
3906
  var clause = node.partitionClause.map(function (item) {
3874
- return _this22.deparse(item, context);
3907
+ return _this23.deparse(item, context);
3875
3908
  });
3876
3909
  partition.push(clause.join(', '));
3877
3910
  windowParts.push(partition.join(' '));
@@ -3881,7 +3914,7 @@ var Deparser = /*#__PURE__*/function () {
3881
3914
  if (node.orderClause) {
3882
3915
  windowParts.push('ORDER BY');
3883
3916
  var orders = node.orderClause.map(function (item) {
3884
- return _this22.deparse(item);
3917
+ return _this23.deparse(item);
3885
3918
  });
3886
3919
  windowParts.push(orders.join(', '));
3887
3920
  useParens = true;
@@ -4088,7 +4121,7 @@ var Deparser = /*#__PURE__*/function () {
4088
4121
  }, {
4089
4122
  key: "deparseInterval",
4090
4123
  value: function deparseInterval(node) {
4091
- var _this23 = this;
4124
+ var _this24 = this;
4092
4125
 
4093
4126
  var type = ['interval'];
4094
4127
 
@@ -4098,7 +4131,7 @@ var Deparser = /*#__PURE__*/function () {
4098
4131
 
4099
4132
  if (node.typmods) {
4100
4133
  var typmods = node.typmods.map(function (item) {
4101
- return _this23.deparse(item);
4134
+ return _this24.deparse(item);
4102
4135
  });
4103
4136
  var intervals = this.interval(typmods[0]); // SELECT interval(0) '1 day 01:23:45.6789'
4104
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');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pgsql-deparser",
3
- "version": "13.3.10",
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.10",
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": "330bf9929afa01f21e7e19136045bbbf48af7e98"
78
+ "gitHead": "3000794fa5f3a0e3e0d3a05cb1cee76f99124557"
79
79
  }