pgsql-parser 13.4.1 → 13.6.0

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,22 @@
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.6.0](https://github.com/launchql/pgsql-parser/compare/pgsql-parser@13.5.0...pgsql-parser@13.6.0) (2023-12-15)
7
+
8
+ **Note:** Version bump only for package pgsql-parser
9
+
10
+
11
+
12
+
13
+
14
+ # [13.5.0](https://github.com/pyramation/pgsql-parser/compare/pgsql-parser@13.4.1...pgsql-parser@13.5.0) (2023-03-15)
15
+
16
+ **Note:** Version bump only for package pgsql-parser
17
+
18
+
19
+
20
+
21
+
6
22
  ## [13.4.1](https://github.com/pyramation/pgsql-parser/compare/pgsql-parser@13.4.0...pgsql-parser@13.4.1) (2022-12-22)
7
23
 
8
24
  **Note:** Version bump only for package pgsql-parser
package/README.md CHANGED
@@ -1,4 +1,5 @@
1
- # pgsql-parser [![tests](https://github.com/pyramation/pgsql-parser/actions/workflows/run-tests.yaml/badge.svg)](https://github.com/pyramation/pgsql-parser/actions/workflows/run-tests.yaml)
1
+ # pgsql-parser [![tests](https://github.com/launchql/pgsql-parser/actions/workflows/run-tests.yaml/badge.svg)](https://github.com/launchql/pgsql-parser/actions/workflows/run-tests.yaml) ![npm](https://img.shields.io/npm/dw/pgsql-parser)
2
+
2
3
 
3
4
  The real PostgreSQL parser for nodejs. The primary objective of this module is to provide symmetric parsing and deparsing of SQL statements. With this module you can modify parts of a SQL query statement and serialize the query tree back into a formatted SQL statement. It uses the *real* [PostgreSQL parser](https://github.com/pganalyze/libpg_query).
4
5
 
@@ -102,7 +103,7 @@ Our latest is built with `13-latest` branch from libpg_query
102
103
  | 13 | 13-latest | Active development | `latest`
103
104
  | 12 | (n/a) | Not supported |
104
105
  | 11 | (n/a) | Not supported |
105
- | 10 | 10-latest | Not supported | `@1.3.1` ([tree](https://github.com/pyramation/pgsql-parser/tree/39b7b1adc8914253226e286a48105785219a81ca)) |
106
+ | 10 | 10-latest | Not supported | `@1.3.1` ([tree](https://github.com/launchql/pgsql-parser/tree/39b7b1adc8914253226e286a48105785219a81ca)) |
106
107
 
107
108
 
108
109
  ## Resources
package/main/cli.js CHANGED
@@ -2,32 +2,23 @@
2
2
  "use strict";
3
3
 
4
4
  var _path = require("path");
5
-
6
5
  var _fs = require("fs");
7
-
8
6
  var _index = require("./index");
9
-
10
7
  var _utils = require("./utils");
11
-
12
8
  var argv = require('minimist')(process.argv.slice(2));
13
-
14
9
  var args = argv._;
15
-
16
10
  if (args.length !== 1) {
17
11
  console.log(argv);
18
12
  console.warn('Usage: pgsql-parser <sqlfile>');
19
13
  process.exit(1);
20
14
  }
21
-
22
15
  var pth = args[0].startsWith('/') ? args[0] : (0, _path.resolve)((0, _path.join)(process.cwd(), args[0]));
23
16
  var content = (0, _fs.readFileSync)(pth, 'utf-8');
24
17
  var query;
25
-
26
18
  if (argv.pl) {
27
19
  // plpgsql ONLY
28
20
  query = (0, _index.parseFunction)(content);
29
21
  } else {
30
22
  query = (0, _index.parse)(content);
31
23
  }
32
-
33
24
  process.stdout.write(JSON.stringify((0, _utils.cleanTreeWithStmt)(query), null, 2));
package/main/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
4
+ var _typeof = require("@babel/runtime/helpers/typeof");
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
@@ -23,28 +23,22 @@ Object.defineProperty(exports, "enums", {
23
23
  return _pgsqlEnums.enums;
24
24
  }
25
25
  });
26
+ exports.parseAsync = exports.parse = void 0;
26
27
  Object.defineProperty(exports, "parseFunction", {
27
28
  enumerable: true,
28
29
  get: function get() {
29
30
  return _libpgQuery.parsePlPgSQLSync;
30
31
  }
31
32
  });
32
- exports.parseAsync = exports.parse = void 0;
33
-
34
- var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
35
-
36
33
  var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
37
-
38
34
  var _pgsqlDeparser = require("pgsql-deparser");
39
-
40
35
  var _pgsqlEnums = require("pgsql-enums");
41
-
42
36
  var _libpgQuery = require("libpg-query");
43
-
37
+ function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, defineProperty = Object.defineProperty || function (obj, key, desc) { obj[key] = desc.value; }, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return defineProperty(generator, "_invoke", { value: makeInvokeMethod(innerFn, self, context) }), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; defineProperty(this, "_invoke", { value: function value(method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; } function maybeInvokeDelegate(delegate, context) { var methodName = context.method, method = delegate.iterator[methodName]; if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator["return"] && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel; var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), defineProperty(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (val) { var object = Object(val), keys = []; for (var key in object) keys.push(key); return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, "catch": function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
44
38
  function mapStmt(_ref) {
45
39
  var stmt = _ref.stmt,
46
- stmt_len = _ref.stmt_len,
47
- stmt_location = _ref.stmt_location;
40
+ stmt_len = _ref.stmt_len,
41
+ stmt_location = _ref.stmt_location;
48
42
  return {
49
43
  RawStmt: {
50
44
  stmt: stmt,
@@ -53,48 +47,37 @@ function mapStmt(_ref) {
53
47
  }
54
48
  };
55
49
  }
56
-
57
50
  var parse = function parse(sql) {
58
51
  if (!sql) throw new Error('no SQL provided to parser');
59
52
  var result = (0, _libpgQuery.parseQuerySync)(sql);
60
53
  return result.stmts.map(mapStmt);
61
54
  };
62
-
63
55
  exports.parse = parse;
64
-
65
56
  var parseAsync = /*#__PURE__*/function () {
66
- var _ref2 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(sql) {
57
+ var _ref2 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(sql) {
67
58
  var result;
68
- return _regenerator["default"].wrap(function _callee$(_context) {
69
- while (1) {
70
- switch (_context.prev = _context.next) {
71
- case 0:
72
- if (sql) {
73
- _context.next = 2;
74
- break;
75
- }
76
-
77
- throw new Error('no SQL provided to parser');
78
-
79
- case 2:
80
- _context.next = 4;
81
- return (0, _libpgQuery.parseQuery)(sql);
82
-
83
- case 4:
84
- result = _context.sent;
85
- return _context.abrupt("return", result.stmts.map(mapStmt));
86
-
87
- case 6:
88
- case "end":
89
- return _context.stop();
90
- }
59
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
60
+ while (1) switch (_context.prev = _context.next) {
61
+ case 0:
62
+ if (sql) {
63
+ _context.next = 2;
64
+ break;
65
+ }
66
+ throw new Error('no SQL provided to parser');
67
+ case 2:
68
+ _context.next = 4;
69
+ return (0, _libpgQuery.parseQuery)(sql);
70
+ case 4:
71
+ result = _context.sent;
72
+ return _context.abrupt("return", result.stmts.map(mapStmt));
73
+ case 6:
74
+ case "end":
75
+ return _context.stop();
91
76
  }
92
77
  }, _callee);
93
78
  }));
94
-
95
79
  return function parseAsync(_x) {
96
80
  return _ref2.apply(this, arguments);
97
81
  };
98
82
  }();
99
-
100
83
  exports.parseAsync = parseAsync;
@@ -1,15 +1,13 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
- exports.cleanTreeWithStmt = exports.cleanTree = exports.transform = exports.cleanLines = void 0;
9
-
7
+ exports.transform = exports.cleanTreeWithStmt = exports.cleanTree = exports.cleanLines = void 0;
10
8
  var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
11
-
12
9
  /* eslint-disable no-restricted-syntax */
10
+
13
11
  var cleanLines = function cleanLines(sql) {
14
12
  return sql.split('\n').map(function (l) {
15
13
  return l.trim();
@@ -17,38 +15,33 @@ var cleanLines = function cleanLines(sql) {
17
15
  return a;
18
16
  }).join('\n');
19
17
  };
20
-
21
18
  exports.cleanLines = cleanLines;
22
-
23
19
  var transform = function transform(obj, props) {
24
- var copy = null; // Handle the 3 simple types, and null or undefined
25
-
20
+ var copy = null;
21
+ // Handle the 3 simple types, and null or undefined
26
22
  if (obj == null || (0, _typeof2["default"])(obj) !== 'object') {
27
23
  return obj;
28
- } // Handle Date
29
-
24
+ }
30
25
 
26
+ // Handle Date
31
27
  if (obj instanceof Date) {
32
28
  copy = new Date();
33
29
  copy.setTime(obj.getTime());
34
30
  return copy;
35
- } // Handle Array
36
-
31
+ }
37
32
 
33
+ // Handle Array
38
34
  if (obj instanceof Array) {
39
35
  copy = [];
40
-
41
36
  for (var i = 0, len = obj.length; i < len; i++) {
42
37
  copy[i] = transform(obj[i], props);
43
38
  }
44
-
45
39
  return copy;
46
- } // Handle Object
47
-
40
+ }
48
41
 
42
+ // Handle Object
49
43
  if (obj instanceof Object || (0, _typeof2["default"])(obj) === 'object') {
50
44
  copy = {};
51
-
52
45
  for (var attr in obj) {
53
46
  if (obj.hasOwnProperty(attr)) {
54
47
  if (props.hasOwnProperty(attr)) {
@@ -66,19 +59,14 @@ var transform = function transform(obj, props) {
66
59
  copy[attr] = transform(obj[attr], props);
67
60
  }
68
61
  }
69
-
70
62
  return copy;
71
63
  }
72
-
73
64
  throw new Error("Unable to copy obj! Its type isn't supported.");
74
65
  };
75
-
76
66
  exports.transform = transform;
77
-
78
67
  var noop = function noop() {
79
68
  return undefined;
80
69
  };
81
-
82
70
  var cleanTree = function cleanTree(tree) {
83
71
  return transform(tree, {
84
72
  stmt_len: noop,
@@ -96,7 +84,6 @@ var cleanTree = function cleanTree(tree) {
96
84
  // do stmt
97
85
  obj.arg.String.str = obj.arg.String.str.trim();
98
86
  }
99
-
100
87
  return cleanTree(obj);
101
88
  } else {
102
89
  return cleanTree(obj);
@@ -104,14 +91,11 @@ var cleanTree = function cleanTree(tree) {
104
91
  }
105
92
  });
106
93
  };
107
-
108
94
  exports.cleanTree = cleanTree;
109
-
110
95
  var cleanTreeWithStmt = function cleanTreeWithStmt(tree) {
111
96
  return transform(tree, {
112
97
  stmt_location: noop,
113
98
  location: noop
114
99
  });
115
100
  };
116
-
117
101
  exports.cleanTreeWithStmt = cleanTreeWithStmt;
package/module/cli.js CHANGED
@@ -3,26 +3,20 @@ import { resolve, join } from 'path';
3
3
  import { readFileSync } from 'fs';
4
4
  import { parse, parseFunction } from './index';
5
5
  import { cleanTreeWithStmt } from './utils';
6
-
7
6
  const argv = require('minimist')(process.argv.slice(2));
8
-
9
7
  const args = argv._;
10
-
11
8
  if (args.length !== 1) {
12
9
  console.log(argv);
13
10
  console.warn('Usage: pgsql-parser <sqlfile>');
14
11
  process.exit(1);
15
12
  }
16
-
17
13
  const pth = args[0].startsWith('/') ? args[0] : resolve(join(process.cwd(), args[0]));
18
14
  const content = readFileSync(pth, 'utf-8');
19
15
  let query;
20
-
21
16
  if (argv.pl) {
22
17
  // plpgsql ONLY
23
18
  query = parseFunction(content);
24
19
  } else {
25
20
  query = parse(content);
26
21
  }
27
-
28
22
  process.stdout.write(JSON.stringify(cleanTreeWithStmt(query), null, 2));
package/module/index.js CHANGED
@@ -1,7 +1,6 @@
1
1
  import { Deparser, deparse } from 'pgsql-deparser';
2
2
  import { enums } from 'pgsql-enums';
3
3
  import { parseQuery, parseQuerySync, parsePlPgSQLSync as parseFunction } from 'libpg-query';
4
-
5
4
  function mapStmt({
6
5
  stmt,
7
6
  stmt_len,
@@ -15,7 +14,6 @@ function mapStmt({
15
14
  }
16
15
  };
17
16
  }
18
-
19
17
  export const parse = sql => {
20
18
  if (!sql) throw new Error('no SQL provided to parser');
21
19
  const result = parseQuerySync(sql);
@@ -1,36 +1,34 @@
1
1
  /* eslint-disable no-restricted-syntax */
2
+
2
3
  export const cleanLines = sql => {
3
4
  return sql.split('\n').map(l => l.trim()).filter(a => a).join('\n');
4
5
  };
5
6
  export const transform = (obj, props) => {
6
- let copy = null; // Handle the 3 simple types, and null or undefined
7
-
7
+ let copy = null;
8
+ // Handle the 3 simple types, and null or undefined
8
9
  if (obj == null || typeof obj !== 'object') {
9
10
  return obj;
10
- } // Handle Date
11
-
11
+ }
12
12
 
13
+ // Handle Date
13
14
  if (obj instanceof Date) {
14
15
  copy = new Date();
15
16
  copy.setTime(obj.getTime());
16
17
  return copy;
17
- } // Handle Array
18
-
18
+ }
19
19
 
20
+ // Handle Array
20
21
  if (obj instanceof Array) {
21
22
  copy = [];
22
-
23
23
  for (let i = 0, len = obj.length; i < len; i++) {
24
24
  copy[i] = transform(obj[i], props);
25
25
  }
26
-
27
26
  return copy;
28
- } // Handle Object
29
-
27
+ }
30
28
 
29
+ // Handle Object
31
30
  if (obj instanceof Object || typeof obj === 'object') {
32
31
  copy = {};
33
-
34
32
  for (const attr in obj) {
35
33
  if (obj.hasOwnProperty(attr)) {
36
34
  if (props.hasOwnProperty(attr)) {
@@ -48,15 +46,11 @@ export const transform = (obj, props) => {
48
46
  copy[attr] = transform(obj[attr], props);
49
47
  }
50
48
  }
51
-
52
49
  return copy;
53
50
  }
54
-
55
51
  throw new Error("Unable to copy obj! Its type isn't supported.");
56
52
  };
57
-
58
53
  const noop = () => undefined;
59
-
60
54
  export const cleanTree = tree => {
61
55
  return transform(tree, {
62
56
  stmt_len: noop,
@@ -74,7 +68,6 @@ export const cleanTree = tree => {
74
68
  // do stmt
75
69
  obj.arg.String.str = obj.arg.String.str.trim();
76
70
  }
77
-
78
71
  return cleanTree(obj);
79
72
  } else {
80
73
  return cleanTree(obj);
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "pgsql-parser",
3
- "version": "13.4.1",
3
+ "version": "13.6.0",
4
4
  "description": "The real PostgreSQL query parser",
5
5
  "author": "Dan Lynch <pyramation@gmail.com>",
6
- "homepage": "https://github.com/pyramation/pgsql-parser",
6
+ "homepage": "https://github.com/launchql/pgsql-parser",
7
7
  "license": "SEE LICENSE IN LICENSE",
8
8
  "main": "main/index.js",
9
9
  "module": "module/index.js",
@@ -32,7 +32,7 @@
32
32
  ],
33
33
  "repository": {
34
34
  "type": "git",
35
- "url": "https://github.com/pyramation/pgsql-parser"
35
+ "url": "https://github.com/launchql/pgsql-parser"
36
36
  },
37
37
  "scripts": {
38
38
  "build:main": "cross-env BABEL_ENV=production babel src --out-dir main --delete-dir-on-start",
@@ -47,7 +47,7 @@
47
47
  "test:debug": "node --inspect node_modules/.bin/jest --runInBand"
48
48
  },
49
49
  "bugs": {
50
- "url": "https://github.com/pyramation/pgsql-parser/issues"
50
+ "url": "https://github.com/launchql/pgsql-parser/issues"
51
51
  },
52
52
  "devDependencies": {
53
53
  "@babel/cli": "7.11.6",
@@ -74,8 +74,8 @@
74
74
  "@babel/runtime": "^7.11.2",
75
75
  "libpg-query": "13.3.1",
76
76
  "minimist": "^1.2.6",
77
- "pgsql-deparser": "^13.3.15",
78
- "pgsql-enums": "^13.1.3"
77
+ "pgsql-deparser": "^13.5.0",
78
+ "pgsql-enums": "^13.2.0"
79
79
  },
80
- "gitHead": "f2353fb8a98b0ac1d637c57d2c8be79f5495b446"
80
+ "gitHead": "1e92743734b549c008f07c12b6972eeab7504ebe"
81
81
  }