Socket
Socket
Sign inDemoInstall

@floatingisland/fork-pg-query-parser

Package Overview
Dependencies
98
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @floatingisland/fork-pg-query-parser

a hacky fork of pg-query-parser


Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

pg-query-parser Build Status

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.

The main functionality provided by this module is deparsing, which PostgreSQL does not have internally.

Installation

npm install pg-query-parser

Example

Rewrite part of a SQL query:

const parser = require('pg-query-parser');

const query = parser.parse('SELECT * FROM test_table').query;

query[0].SelectStmt.fromClause[0].RangeVar.relname = 'another_table';

console.log(parser.deparse(query));

// SELECT * FROM "another_table"

Documentation

parser.parse(sql)

Parses the query and returns a parse object.

Parameters

parametertypedescription
queryStringSQL query

Returns an object in the format:

{ query: <query|Object>,
  error: { message: <message|String>,
           fileName: <fileName|String>,
           lineNumber: <line|Number>,
           cursorPosition: <cursor|Number> }

parser.deparse(query)

Deparses the query tree and returns a formatted SQL statement. This function takes as input a query AST in the same format as the query property of on the result of the parse method. This is the primary functionality of this module.

Parameters

parametertypedescription
queryObjectQuery tree obtained from parse

Returns a normalized formatted SQL string.

Keywords

FAQs

Last updated on 04 Nov 2017

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc