pgsql-parser 13.6.0 → 13.7.1

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/README.md CHANGED
@@ -1,5 +1,14 @@
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
-
1
+ # pgsql-parser
2
+
3
+ <p align="center" width="100%">
4
+ <a href="https://github.com/launchql/pgsql-parser/actions/workflows/run-tests.yaml">
5
+ <img height="20" src="https://github.com/launchql/pgsql-parser/actions/workflows/run-tests.yaml/badge.svg" />
6
+ </a>
7
+ <a href="https://www.npmjs.com/package/pgsql-parser"><img height="20" src="https://img.shields.io/npm/dt/pgsql-parser"></a>
8
+ <a href="https://www.npmjs.com/package/pgsql-parser"><img height="20" src="https://img.shields.io/npm/dw/pgsql-parser"/></a>
9
+ <a href="https://github.com/launchql/pgsql-parser/blob/main/LICENSE-MIT"><img height="20" src="https://img.shields.io/badge/license-MIT-blue.svg"/></a>
10
+ <a href="https://www.npmjs.com/package/pgsql-parser"><img height="20" src="https://img.shields.io/github/package-json/v/launchql/pgsql-parser?filename=packages%2Fparser%2Fpackage.json"/></a>
11
+ </p>
3
12
 
4
13
  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).
5
14
 
package/main/cli.js CHANGED
@@ -2,23 +2,32 @@
2
2
  "use strict";
3
3
 
4
4
  var _path = require("path");
5
+
5
6
  var _fs = require("fs");
7
+
6
8
  var _index = require("./index");
9
+
7
10
  var _utils = require("./utils");
11
+
8
12
  var argv = require('minimist')(process.argv.slice(2));
13
+
9
14
  var args = argv._;
15
+
10
16
  if (args.length !== 1) {
11
17
  console.log(argv);
12
18
  console.warn('Usage: pgsql-parser <sqlfile>');
13
19
  process.exit(1);
14
20
  }
21
+
15
22
  var pth = args[0].startsWith('/') ? args[0] : (0, _path.resolve)((0, _path.join)(process.cwd(), args[0]));
16
23
  var content = (0, _fs.readFileSync)(pth, 'utf-8');
17
24
  var query;
25
+
18
26
  if (argv.pl) {
19
27
  // plpgsql ONLY
20
28
  query = (0, _index.parseFunction)(content);
21
29
  } else {
22
30
  query = (0, _index.parse)(content);
23
31
  }
32
+
24
33
  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
- var _typeof = require("@babel/runtime/helpers/typeof");
4
+
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
@@ -23,22 +23,28 @@ Object.defineProperty(exports, "enums", {
23
23
  return _pgsqlEnums.enums;
24
24
  }
25
25
  });
26
- exports.parseAsync = exports.parse = void 0;
27
26
  Object.defineProperty(exports, "parseFunction", {
28
27
  enumerable: true,
29
28
  get: function get() {
30
29
  return _libpgQuery.parsePlPgSQLSync;
31
30
  }
32
31
  });
32
+ exports.parseAsync = exports.parse = void 0;
33
+
34
+ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
35
+
33
36
  var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
37
+
34
38
  var _pgsqlDeparser = require("pgsql-deparser");
39
+
35
40
  var _pgsqlEnums = require("pgsql-enums");
41
+
36
42
  var _libpgQuery = require("libpg-query");
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; }
43
+
38
44
  function mapStmt(_ref) {
39
45
  var stmt = _ref.stmt,
40
- stmt_len = _ref.stmt_len,
41
- stmt_location = _ref.stmt_location;
46
+ stmt_len = _ref.stmt_len,
47
+ stmt_location = _ref.stmt_location;
42
48
  return {
43
49
  RawStmt: {
44
50
  stmt: stmt,
@@ -47,37 +53,48 @@ function mapStmt(_ref) {
47
53
  }
48
54
  };
49
55
  }
56
+
50
57
  var parse = function parse(sql) {
51
58
  if (!sql) throw new Error('no SQL provided to parser');
52
59
  var result = (0, _libpgQuery.parseQuerySync)(sql);
53
60
  return result.stmts.map(mapStmt);
54
61
  };
62
+
55
63
  exports.parse = parse;
64
+
56
65
  var parseAsync = /*#__PURE__*/function () {
57
- var _ref2 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(sql) {
66
+ var _ref2 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(sql) {
58
67
  var result;
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();
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
+ }
76
91
  }
77
92
  }, _callee);
78
93
  }));
94
+
79
95
  return function parseAsync(_x) {
80
96
  return _ref2.apply(this, arguments);
81
97
  };
82
98
  }();
99
+
83
100
  exports.parseAsync = parseAsync;
@@ -1,13 +1,15 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
4
5
  Object.defineProperty(exports, "__esModule", {
5
6
  value: true
6
7
  });
7
- exports.transform = exports.cleanTreeWithStmt = exports.cleanTree = exports.cleanLines = void 0;
8
+ exports.cleanTreeWithStmt = exports.cleanTree = exports.transform = exports.cleanLines = void 0;
9
+
8
10
  var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
9
- /* eslint-disable no-restricted-syntax */
10
11
 
12
+ /* eslint-disable no-restricted-syntax */
11
13
  var cleanLines = function cleanLines(sql) {
12
14
  return sql.split('\n').map(function (l) {
13
15
  return l.trim();
@@ -15,33 +17,38 @@ var cleanLines = function cleanLines(sql) {
15
17
  return a;
16
18
  }).join('\n');
17
19
  };
20
+
18
21
  exports.cleanLines = cleanLines;
22
+
19
23
  var transform = function transform(obj, props) {
20
- var copy = null;
21
- // Handle the 3 simple types, and null or undefined
24
+ var copy = null; // Handle the 3 simple types, and null or undefined
25
+
22
26
  if (obj == null || (0, _typeof2["default"])(obj) !== 'object') {
23
27
  return obj;
24
- }
28
+ } // Handle Date
29
+
25
30
 
26
- // Handle Date
27
31
  if (obj instanceof Date) {
28
32
  copy = new Date();
29
33
  copy.setTime(obj.getTime());
30
34
  return copy;
31
- }
35
+ } // Handle Array
36
+
32
37
 
33
- // Handle Array
34
38
  if (obj instanceof Array) {
35
39
  copy = [];
40
+
36
41
  for (var i = 0, len = obj.length; i < len; i++) {
37
42
  copy[i] = transform(obj[i], props);
38
43
  }
44
+
39
45
  return copy;
40
- }
46
+ } // Handle Object
47
+
41
48
 
42
- // Handle Object
43
49
  if (obj instanceof Object || (0, _typeof2["default"])(obj) === 'object') {
44
50
  copy = {};
51
+
45
52
  for (var attr in obj) {
46
53
  if (obj.hasOwnProperty(attr)) {
47
54
  if (props.hasOwnProperty(attr)) {
@@ -59,14 +66,19 @@ var transform = function transform(obj, props) {
59
66
  copy[attr] = transform(obj[attr], props);
60
67
  }
61
68
  }
69
+
62
70
  return copy;
63
71
  }
72
+
64
73
  throw new Error("Unable to copy obj! Its type isn't supported.");
65
74
  };
75
+
66
76
  exports.transform = transform;
77
+
67
78
  var noop = function noop() {
68
79
  return undefined;
69
80
  };
81
+
70
82
  var cleanTree = function cleanTree(tree) {
71
83
  return transform(tree, {
72
84
  stmt_len: noop,
@@ -84,6 +96,7 @@ var cleanTree = function cleanTree(tree) {
84
96
  // do stmt
85
97
  obj.arg.String.str = obj.arg.String.str.trim();
86
98
  }
99
+
87
100
  return cleanTree(obj);
88
101
  } else {
89
102
  return cleanTree(obj);
@@ -91,11 +104,14 @@ var cleanTree = function cleanTree(tree) {
91
104
  }
92
105
  });
93
106
  };
107
+
94
108
  exports.cleanTree = cleanTree;
109
+
95
110
  var cleanTreeWithStmt = function cleanTreeWithStmt(tree) {
96
111
  return transform(tree, {
97
112
  stmt_location: noop,
98
113
  location: noop
99
114
  });
100
115
  };
116
+
101
117
  exports.cleanTreeWithStmt = cleanTreeWithStmt;
package/module/cli.js CHANGED
@@ -3,20 +3,26 @@ 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
+
6
7
  const argv = require('minimist')(process.argv.slice(2));
8
+
7
9
  const args = argv._;
10
+
8
11
  if (args.length !== 1) {
9
12
  console.log(argv);
10
13
  console.warn('Usage: pgsql-parser <sqlfile>');
11
14
  process.exit(1);
12
15
  }
16
+
13
17
  const pth = args[0].startsWith('/') ? args[0] : resolve(join(process.cwd(), args[0]));
14
18
  const content = readFileSync(pth, 'utf-8');
15
19
  let query;
20
+
16
21
  if (argv.pl) {
17
22
  // plpgsql ONLY
18
23
  query = parseFunction(content);
19
24
  } else {
20
25
  query = parse(content);
21
26
  }
27
+
22
28
  process.stdout.write(JSON.stringify(cleanTreeWithStmt(query), null, 2));
package/module/index.js CHANGED
@@ -1,6 +1,7 @@
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
+
4
5
  function mapStmt({
5
6
  stmt,
6
7
  stmt_len,
@@ -14,6 +15,7 @@ function mapStmt({
14
15
  }
15
16
  };
16
17
  }
18
+
17
19
  export const parse = sql => {
18
20
  if (!sql) throw new Error('no SQL provided to parser');
19
21
  const result = parseQuerySync(sql);
@@ -1,34 +1,36 @@
1
1
  /* eslint-disable no-restricted-syntax */
2
-
3
2
  export const cleanLines = sql => {
4
3
  return sql.split('\n').map(l => l.trim()).filter(a => a).join('\n');
5
4
  };
6
5
  export const transform = (obj, props) => {
7
- let copy = null;
8
- // Handle the 3 simple types, and null or undefined
6
+ let copy = null; // Handle the 3 simple types, and null or undefined
7
+
9
8
  if (obj == null || typeof obj !== 'object') {
10
9
  return obj;
11
- }
10
+ } // Handle Date
11
+
12
12
 
13
- // Handle Date
14
13
  if (obj instanceof Date) {
15
14
  copy = new Date();
16
15
  copy.setTime(obj.getTime());
17
16
  return copy;
18
- }
17
+ } // Handle Array
18
+
19
19
 
20
- // Handle Array
21
20
  if (obj instanceof Array) {
22
21
  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
+
26
27
  return copy;
27
- }
28
+ } // Handle Object
29
+
28
30
 
29
- // Handle Object
30
31
  if (obj instanceof Object || typeof obj === 'object') {
31
32
  copy = {};
33
+
32
34
  for (const attr in obj) {
33
35
  if (obj.hasOwnProperty(attr)) {
34
36
  if (props.hasOwnProperty(attr)) {
@@ -46,11 +48,15 @@ export const transform = (obj, props) => {
46
48
  copy[attr] = transform(obj[attr], props);
47
49
  }
48
50
  }
51
+
49
52
  return copy;
50
53
  }
54
+
51
55
  throw new Error("Unable to copy obj! Its type isn't supported.");
52
56
  };
57
+
53
58
  const noop = () => undefined;
59
+
54
60
  export const cleanTree = tree => {
55
61
  return transform(tree, {
56
62
  stmt_len: noop,
@@ -68,6 +74,7 @@ export const cleanTree = tree => {
68
74
  // do stmt
69
75
  obj.arg.String.str = obj.arg.String.str.trim();
70
76
  }
77
+
71
78
  return cleanTree(obj);
72
79
  } else {
73
80
  return cleanTree(obj);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pgsql-parser",
3
- "version": "13.6.0",
3
+ "version": "13.7.1",
4
4
  "description": "The real PostgreSQL query parser",
5
5
  "author": "Dan Lynch <pyramation@gmail.com>",
6
6
  "homepage": "https://github.com/launchql/pgsql-parser",
@@ -72,10 +72,9 @@
72
72
  },
73
73
  "dependencies": {
74
74
  "@babel/runtime": "^7.11.2",
75
- "libpg-query": "13.3.1",
75
+ "libpg-query": "13.3.2",
76
76
  "minimist": "^1.2.6",
77
- "pgsql-deparser": "^13.5.0",
77
+ "pgsql-deparser": "^13.6.1",
78
78
  "pgsql-enums": "^13.2.0"
79
- },
80
- "gitHead": "1e92743734b549c008f07c12b6972eeab7504ebe"
79
+ }
81
80
  }
package/CHANGELOG.md DELETED
@@ -1,456 +0,0 @@
1
- # Change Log
2
-
3
- All notable changes to this project will be documented in this file.
4
- See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
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
-
22
- ## [13.4.1](https://github.com/pyramation/pgsql-parser/compare/pgsql-parser@13.4.0...pgsql-parser@13.4.1) (2022-12-22)
23
-
24
- **Note:** Version bump only for package pgsql-parser
25
-
26
-
27
-
28
-
29
-
30
- # [13.4.0](https://github.com/pyramation/pgsql-parser/compare/pgsql-parser@13.3.14...pgsql-parser@13.4.0) (2022-11-08)
31
-
32
- **Note:** Version bump only for package pgsql-parser
33
-
34
-
35
-
36
-
37
-
38
- ## [13.3.14](https://github.com/pyramation/pgsql-parser/compare/pgsql-parser@13.3.13...pgsql-parser@13.3.14) (2022-09-14)
39
-
40
- **Note:** Version bump only for package pgsql-parser
41
-
42
-
43
-
44
-
45
-
46
- ## [13.3.13](https://github.com/pyramation/pgsql-parser/compare/pgsql-parser@13.3.12...pgsql-parser@13.3.13) (2022-08-31)
47
-
48
- **Note:** Version bump only for package pgsql-parser
49
-
50
-
51
-
52
-
53
-
54
- ## [13.3.12](https://github.com/pyramation/pgsql-parser/compare/pgsql-parser@13.3.11...pgsql-parser@13.3.12) (2022-07-29)
55
-
56
- **Note:** Version bump only for package pgsql-parser
57
-
58
-
59
-
60
-
61
-
62
- ## [13.3.11](https://github.com/pyramation/pgsql-parser/compare/pgsql-parser@13.3.10...pgsql-parser@13.3.11) (2022-05-20)
63
-
64
- **Note:** Version bump only for package pgsql-parser
65
-
66
-
67
-
68
-
69
-
70
- ## [13.3.10](https://github.com/pyramation/pgsql-parser/compare/pgsql-parser@13.3.9...pgsql-parser@13.3.10) (2022-05-19)
71
-
72
- **Note:** Version bump only for package pgsql-parser
73
-
74
-
75
-
76
-
77
-
78
- ## [13.3.9](https://github.com/pyramation/pgsql-parser/compare/pgsql-parser@13.3.8...pgsql-parser@13.3.9) (2022-04-19)
79
-
80
- **Note:** Version bump only for package pgsql-parser
81
-
82
-
83
-
84
-
85
-
86
- ## [13.3.8](https://github.com/pyramation/pgsql-parser/compare/pgsql-parser@13.3.7...pgsql-parser@13.3.8) (2022-04-19)
87
-
88
- **Note:** Version bump only for package pgsql-parser
89
-
90
-
91
-
92
-
93
-
94
- ## [13.3.7](https://github.com/pyramation/pgsql-parser/compare/pgsql-parser@13.3.6...pgsql-parser@13.3.7) (2022-04-19)
95
-
96
- **Note:** Version bump only for package pgsql-parser
97
-
98
-
99
-
100
-
101
-
102
- ## [13.3.6](https://github.com/pyramation/pgsql-parser/compare/pgsql-parser@13.3.5...pgsql-parser@13.3.6) (2022-04-19)
103
-
104
- **Note:** Version bump only for package pgsql-parser
105
-
106
-
107
-
108
-
109
-
110
- ## [13.3.5](https://github.com/pyramation/pgsql-parser/compare/pgsql-parser@13.3.4...pgsql-parser@13.3.5) (2022-04-19)
111
-
112
- **Note:** Version bump only for package pgsql-parser
113
-
114
-
115
-
116
-
117
-
118
- ## [13.3.4](https://github.com/pyramation/pgsql-parser/compare/pgsql-parser@13.3.3...pgsql-parser@13.3.4) (2022-04-19)
119
-
120
- **Note:** Version bump only for package pgsql-parser
121
-
122
-
123
-
124
-
125
-
126
- ## [13.3.3](https://github.com/pyramation/pgsql-parser/compare/pgsql-parser@13.3.2...pgsql-parser@13.3.3) (2022-04-19)
127
-
128
- **Note:** Version bump only for package pgsql-parser
129
-
130
-
131
-
132
-
133
-
134
- ## [13.3.2](https://github.com/pyramation/pgsql-parser/compare/pgsql-parser@13.3.1...pgsql-parser@13.3.2) (2022-04-19)
135
-
136
- **Note:** Version bump only for package pgsql-parser
137
-
138
-
139
-
140
-
141
-
142
- ## [13.3.1](https://github.com/pyramation/pgsql-parser/compare/pgsql-parser@13.3.0...pgsql-parser@13.3.1) (2022-04-13)
143
-
144
- **Note:** Version bump only for package pgsql-parser
145
-
146
-
147
-
148
-
149
-
150
- # [13.3.0](https://github.com/pyramation/pgsql-parser/compare/pgsql-parser@13.2.0...pgsql-parser@13.3.0) (2022-03-18)
151
-
152
- **Note:** Version bump only for package pgsql-parser
153
-
154
-
155
-
156
-
157
-
158
- # [13.2.0](https://github.com/pyramation/pgsql-parser/compare/pgsql-parser@13.1.13...pgsql-parser@13.2.0) (2022-02-24)
159
-
160
- **Note:** Version bump only for package pgsql-parser
161
-
162
-
163
-
164
-
165
-
166
- ## [13.1.13](https://github.com/pyramation/pgsql-parser/compare/pgsql-parser@13.1.12...pgsql-parser@13.1.13) (2022-01-07)
167
-
168
- **Note:** Version bump only for package pgsql-parser
169
-
170
-
171
-
172
-
173
-
174
- ## [13.1.12](https://github.com/pyramation/pgsql-parser/compare/pgsql-parser@13.1.11...pgsql-parser@13.1.12) (2022-01-05)
175
-
176
- **Note:** Version bump only for package pgsql-parser
177
-
178
-
179
-
180
-
181
-
182
- ## [13.1.11](https://github.com/pyramation/pgsql-parser/compare/pgsql-parser@13.1.10...pgsql-parser@13.1.11) (2021-10-19)
183
-
184
- **Note:** Version bump only for package pgsql-parser
185
-
186
-
187
-
188
-
189
-
190
- ## [13.1.10](https://github.com/pyramation/pgsql-parser/compare/pgsql-parser@13.1.9...pgsql-parser@13.1.10) (2021-10-19)
191
-
192
- **Note:** Version bump only for package pgsql-parser
193
-
194
-
195
-
196
-
197
-
198
- ## [13.1.9](https://github.com/pyramation/pgsql-parser/compare/pgsql-parser@13.1.8...pgsql-parser@13.1.9) (2021-10-13)
199
-
200
- **Note:** Version bump only for package pgsql-parser
201
-
202
-
203
-
204
-
205
-
206
- ## [13.1.8](https://github.com/pyramation/pgsql-parser/compare/pgsql-parser@13.1.7...pgsql-parser@13.1.8) (2021-09-09)
207
-
208
- **Note:** Version bump only for package pgsql-parser
209
-
210
-
211
-
212
-
213
-
214
- ## [13.1.7](https://github.com/pyramation/pgsql-parser/compare/pgsql-parser@13.1.6...pgsql-parser@13.1.7) (2021-09-09)
215
-
216
- **Note:** Version bump only for package pgsql-parser
217
-
218
-
219
-
220
-
221
-
222
- ## [13.1.6](https://github.com/pyramation/pgsql-parser/compare/pgsql-parser@13.1.5...pgsql-parser@13.1.6) (2021-06-25)
223
-
224
- **Note:** Version bump only for package pgsql-parser
225
-
226
-
227
-
228
-
229
-
230
- ## [13.1.5](https://github.com/pyramation/pgsql-parser/compare/pgsql-parser@13.1.4...pgsql-parser@13.1.5) (2021-06-02)
231
-
232
- **Note:** Version bump only for package pgsql-parser
233
-
234
-
235
-
236
-
237
-
238
- ## [13.1.4](https://github.com/pyramation/pgsql-parser/compare/pgsql-parser@13.1.3...pgsql-parser@13.1.4) (2021-04-26)
239
-
240
- **Note:** Version bump only for package pgsql-parser
241
-
242
-
243
-
244
-
245
-
246
- ## [13.1.3](https://github.com/pyramation/pgsql-parser/compare/pgsql-parser@13.1.2...pgsql-parser@13.1.3) (2021-04-07)
247
-
248
- **Note:** Version bump only for package pgsql-parser
249
-
250
-
251
-
252
-
253
-
254
- ## [13.1.2](https://github.com/pyramation/pgsql-parser/compare/pgsql-parser@13.1.1...pgsql-parser@13.1.2) (2021-03-27)
255
-
256
- **Note:** Version bump only for package pgsql-parser
257
-
258
-
259
-
260
-
261
-
262
- ## [13.1.1](https://github.com/pyramation/pgsql-parser/compare/pgsql-parser@13.1.0...pgsql-parser@13.1.1) (2021-03-26)
263
-
264
- **Note:** Version bump only for package pgsql-parser
265
-
266
-
267
-
268
-
269
-
270
- # [13.1.0](https://github.com/pyramation/pgsql-parser/compare/pgsql-parser@13.0.5...pgsql-parser@13.1.0) (2021-03-20)
271
-
272
- **Note:** Version bump only for package pgsql-parser
273
-
274
-
275
-
276
-
277
-
278
- ## [13.0.5](https://github.com/pyramation/pgsql-parser/compare/pgsql-parser@13.0.4...pgsql-parser@13.0.5) (2021-03-20)
279
-
280
- **Note:** Version bump only for package pgsql-parser
281
-
282
-
283
-
284
-
285
-
286
- ## [13.0.4](https://github.com/pyramation/pgsql-parser/compare/pgsql-parser@13.0.3...pgsql-parser@13.0.4) (2021-03-19)
287
-
288
- **Note:** Version bump only for package pgsql-parser
289
-
290
-
291
-
292
-
293
-
294
- ## [13.0.3](https://github.com/pyramation/pgsql-parser/compare/pgsql-parser@13.0.2...pgsql-parser@13.0.3) (2021-03-19)
295
-
296
- **Note:** Version bump only for package pgsql-parser
297
-
298
-
299
-
300
-
301
-
302
- ## [13.0.2](https://github.com/pyramation/pgsql-parser/compare/pgsql-parser@13.0.1...pgsql-parser@13.0.2) (2021-03-19)
303
-
304
- **Note:** Version bump only for package pgsql-parser
305
-
306
-
307
-
308
-
309
-
310
- ## [13.0.1](https://github.com/pyramation/pgsql-parser/compare/pgsql-parser@1.3.1...pgsql-parser@13.0.1) (2021-03-19)
311
-
312
- **Note:** Version bump only for package pgsql-parser
313
-
314
-
315
-
316
-
317
-
318
- ## [1.3.1](https://github.com/pyramation/pgsql-parser/compare/pgsql-parser@1.3.0...pgsql-parser@1.3.1) (2021-03-19)
319
-
320
- **Note:** Version bump only for package pgsql-parser
321
-
322
-
323
-
324
-
325
-
326
- # [1.3.0](https://github.com/pyramation/pgsql-parser/compare/pgsql-parser@1.2.5...pgsql-parser@1.3.0) (2021-03-18)
327
-
328
- **Note:** Version bump only for package pgsql-parser
329
-
330
-
331
-
332
-
333
-
334
- ## [1.2.5](https://github.com/pyramation/pgsql-parser/compare/pgsql-parser@1.2.4...pgsql-parser@1.2.5) (2021-03-13)
335
-
336
- **Note:** Version bump only for package pgsql-parser
337
-
338
-
339
-
340
-
341
-
342
- ## [1.2.4](https://github.com/pyramation/pgsql-parser/compare/pgsql-parser@1.2.3...pgsql-parser@1.2.4) (2021-03-13)
343
-
344
- **Note:** Version bump only for package pgsql-parser
345
-
346
-
347
-
348
-
349
-
350
- ## [1.2.3](https://github.com/pyramation/pgsql-parser/compare/pgsql-parser@1.2.2...pgsql-parser@1.2.3) (2020-11-08)
351
-
352
- **Note:** Version bump only for package pgsql-parser
353
-
354
-
355
-
356
-
357
-
358
- ## [1.2.2](https://github.com/pyramation/pgsql-parser/compare/pgsql-parser@1.2.1...pgsql-parser@1.2.2) (2020-11-04)
359
-
360
- **Note:** Version bump only for package pgsql-parser
361
-
362
-
363
-
364
-
365
-
366
- ## [1.2.1](https://github.com/pyramation/pgsql-parser/compare/pgsql-parser@1.2.0...pgsql-parser@1.2.1) (2020-11-04)
367
-
368
- **Note:** Version bump only for package pgsql-parser
369
-
370
-
371
-
372
-
373
-
374
- # [1.2.0](https://github.com/pyramation/pgsql-parser/compare/pgsql-parser@1.1.1...pgsql-parser@1.2.0) (2020-11-03)
375
-
376
- **Note:** Version bump only for package pgsql-parser
377
-
378
-
379
-
380
-
381
-
382
- ## [1.1.1](https://github.com/pyramation/pgsql-parser/compare/pgsql-parser@1.1.0...pgsql-parser@1.1.1) (2020-10-27)
383
-
384
- **Note:** Version bump only for package pgsql-parser
385
-
386
-
387
-
388
-
389
-
390
- # [1.1.0](https://github.com/pyramation/pgsql-parser/compare/pgsql-parser@1.0.7...pgsql-parser@1.1.0) (2020-10-27)
391
-
392
- **Note:** Version bump only for package pgsql-parser
393
-
394
-
395
-
396
-
397
-
398
- ## [1.0.7](https://github.com/pyramation/pgsql-parser/compare/pgsql-parser@1.0.6...pgsql-parser@1.0.7) (2020-10-27)
399
-
400
- **Note:** Version bump only for package pgsql-parser
401
-
402
-
403
-
404
-
405
-
406
- ## [1.0.6](https://github.com/pyramation/pgsql-parser/compare/pgsql-parser@1.0.5...pgsql-parser@1.0.6) (2020-10-26)
407
-
408
- **Note:** Version bump only for package pgsql-parser
409
-
410
-
411
-
412
-
413
-
414
- ## [1.0.5](https://github.com/pyramation/pgsql-parser/compare/pgsql-parser@1.0.4...pgsql-parser@1.0.5) (2020-10-25)
415
-
416
- **Note:** Version bump only for package pgsql-parser
417
-
418
-
419
-
420
-
421
-
422
- ## [1.0.4](https://github.com/pyramation/pgsql-parser/compare/pgsql-parser@1.0.3...pgsql-parser@1.0.4) (2020-10-23)
423
-
424
- **Note:** Version bump only for package pgsql-parser
425
-
426
-
427
-
428
-
429
-
430
- ## [1.0.3](https://github.com/pyramation/pgsql-parser/compare/pgsql-parser@1.0.2...pgsql-parser@1.0.3) (2020-10-23)
431
-
432
- **Note:** Version bump only for package pgsql-parser
433
-
434
-
435
-
436
-
437
-
438
- ## [1.0.2](https://github.com/pyramation/pgsql-parser/compare/pgsql-parser@1.0.1...pgsql-parser@1.0.2) (2020-10-23)
439
-
440
- **Note:** Version bump only for package pgsql-parser
441
-
442
-
443
-
444
-
445
-
446
- ## [1.0.1](https://github.com/pyramation/pgsql-parser/compare/pgsql-parser@1.0.0...pgsql-parser@1.0.1) (2020-10-22)
447
-
448
- **Note:** Version bump only for package pgsql-parser
449
-
450
-
451
-
452
-
453
-
454
- # 1.0.0 (2020-10-19)
455
-
456
- **Note:** Version bump only for package pgsql-parser