@maschwenk/libpg-query
TypeScript icon, indicating that this package has built-in type declarations

13.1.2 • Public • Published

libpg-query

The real PostgreSQL parser, exposed for nodejs.

Primarily used for the node.js parser and deparser pgsql-parser

Requirements

Install node-gyp globally

npm install node-gyp -g

How to re-buid

git clone -b 10-latest git://github.com/lfittl/libpg_query
cd libpg_query
make

Then get the .a file and drop it in the folder in this repo.

Installation

npm install libpg-query

Documentation

query.parseQuery(sql)/parseQuerySync

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).

query.parsePlPgSQL(funcsSql)/query.parsePlPgSQLSync(funcsSql)

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.

Example

const parser = require('libpg-query');
parser.parseQuery('select 1').then(console.log);

Related

Credit

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.

Additional thanks for node binding Ethan Resnick.

Original Code and License

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 13.1.2
    1
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 13.1.2
    1

Package Sidebar

Install

npm i @maschwenk/libpg-query

Weekly Downloads

1

Version

13.1.2

License

LICENSE IN LICENSE

Unpacked Size

30.5 kB

Total Files

25

Last publish

Collaborators

  • maschwenk