The real PostgreSQL query parser
npm install pg-plpgsql-query-nativeThe real PostgreSQL parser for nodejs.
This is based on the output of libpg_query. This wraps the static library output and links it into a node module for use in js.
All credit for the hard problems goes to Lukas Fittl.
Instal node-gyp globally
``sh`
npm install node-gyp -g
`sh`
npm install pg-plpgsql-query-native
Parses the sql and returns a Promise for the parse tree (or returns the parse tree directly in the sync version). May reject with/throw a parse error.
The return value is an array, as multiple queries may be provided in a single string (semicolon-delimited, as Postgres expects).
Parses the contents of a PL/PGSql function, from a CREATE FUNCTION declaration, and returns a Promise for the parse tree (or returns the parse tree directly in the sync version). May reject with/throw a parse error.
`js``
var parse = require('pg-query-native').parseQuery;
parse('select 1').then(console.log);