• Stars
    star
    143
  • Rank 257,007 (Top 6 %)
  • Language
    JavaScript
  • License
    BSD 3-Clause "New...
  • Created about 9 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

PostgreSQL Query Parser for Node.js

pg-query-parser

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

parameter type description
query String SQL 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

parameter type description
query Object Query tree obtained from parse

Returns a normalized formatted SQL string.

Related

More Repositories

1

symbola

An icon font made for TileMill and Mapnik
JavaScript
88
star
2

node-spatialite

Standalone, cross-platform SpatiaLite 4.0 binding for node.js with all features enabled
C
66
star
3

icu-ios

Static universal build of ICU compatible with the simulator, armv7, armv7s, and arm64
C++
65
star
4

geobox

A hackbox for geo stuff
Ruby
53
star
5

gdal-ruby

GDAL/OGR bindings for ruby
C++
35
star
6

node-ogr

OGR bindings for node
C++
30
star
7

node-pg-query-native

PostgreSQL Query Parser for Node.js
C++
29
star
8

osmchanges-postgres

OpenStreetMap changeset sync to PostgreSQL using the minute diffs
Ruby
12
star
9

filegdb-osx

FileGDB plugin for the GDAL/OGR framework on Mac OSX
Shell
11
star
10

macvimhax

My vim setup
Vim Script
10
star
11

ffmpeg-ubuntu

FFmpeg install script for Ubuntu
Shell
8
star
12

pg-postgis-types

PostGIS Data Types for Node.js / node-postgres
JavaScript
8
star
13

tinystring

A tiny wrapper around std::stringstream for efficient string building in Nodejs
C++
7
star
14

fulcrum-cli

Fulcrum CLI
TypeScript
7
star
15

kw

Kill dead whitespace
JavaScript
5
star
16

minidb

Tiny ORM for PostgreSQL and SQLite
JavaScript
4
star
17

great-circles

Great Circles on iPad
Objective-C
4
star
18

csvtool

A little tiny web tool to build lists for Fulcrum from CSV data
JavaScript
4
star
19

osmstats

An experiment with d3js and the Overpass API
JavaScript
4
star
20

lwgeom

liblwgeom from PostGIS with gyp build system and Windows MSVC support
C
4
star
21

zsh

My zsh / iTerm2 configuration
Shell
3
star
22

cartodb-tools

Command line tool for uploading data to CartoDB
Ruby
3
star
23

togeotiff

Create a GeoTIFF from a tile server given a GeoJSON bounding box and desired zoom level.
Ruby
3
star
24

foxsoccer.tv

minify script for foxsoccer.tv
JavaScript
2
star
25

tiger

TIGER review plugin for JOSM
Java
2
star
26

xls2fulcrum

XLSForm to Fulcrum Converter
JavaScript
2
star
27

video-player

Georeferenced Video Player
JavaScript
2
star
28

pg-query-deparser

Format PostgreSQL Queries
JavaScript
2
star
29

steth

TypeScript
2
star
30

TagHighlight

A git mirror of https://bitbucket.org/abudden/taghighlight
Vim Script
2
star
31

osmchanges

OpenStreetMap changeset sync to MongoDB using the minute diffs
Ruby
2
star
32

soccertv

Soccer TV schedule from the command line using nodejs
JavaScript
2
star
33

foursquare-osm-alerts

Get a push notification when you checkin on Foursquare at a place that's not mapped on OSM
JavaScript
1
star
34

bash

My bash profile
Shell
1
star
35

minisqlite

SQLite bindings for nodejs
C++
1
star
36

grow

Auto-growing textareas
JavaScript
1
star
37

ogrbar

OSX menubar application for ogr2ogr
Objective-C
1
star
38

zhm.github.com

JavaScript
1
star
39

osm-areas

Areas of OSM that have good imagery but not much data
1
star
40

dotfiles

My dotfiles
JavaScript
1
star
41

airbrake-mongo

Sync Airbrake errors to a local mongo database for searching.
Ruby
1
star
42

s3cmd

s3cmd wrapper
Python
1
star
43

minipg

High performance libpq bindings for Nodejs using single-row mode
C++
1
star
44

pg-type-names

PostgreSQL Type Names for Nodejs
JavaScript
1
star
45

video-coverage

Compute polygons from GPS referenced video tracks
Ruby
1
star
46

gss-test

Testing out GSS
1
star
47

s3_cmd_bin

Embedded version of s3cmd you can install using bundler
Python
1
star
48

nginx-ubuntu-build

nginx deb package for Ubuntu that includes the upload module
Shell
1
star