Skip to content

Commit d22bece

Browse files
committed
readme, addon
1 parent 9c0101d commit d22bece

File tree

3 files changed

+70
-35
lines changed

3 files changed

+70
-35
lines changed

README.md

Lines changed: 52 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,45 @@
11
# libpg-query
22

3+
<p align="center" width="100%">
4+
<img src="https://github.com/launchql/libpg-query-node/assets/545047/7f7053b8-9f52-4f4e-95b0-201d656902ed" alt="webincubator" width="100">
5+
</p>
6+
7+
<p align="center" width="100%">
8+
<a href="https://www.npmjs.com/package/libpg-query"><img height="20" src="https://img.shields.io/npm/dt/libpg-query"></a>
9+
<a href="https://www.npmjs.com/package/libpg-query"><img height="20" src="https://img.shields.io/npm/dw/libpg-query"/></a>
10+
<a href="https://github.com/launchql/libpg-query/blob/main/LICENSE-MIT"><img height="20" src="https://img.shields.io/badge/license-MIT-blue.svg"/></a>
11+
<a href="https://www.npmjs.com/package/libpg-query"><img height="20" src="https://img.shields.io/github/package-json/v/launchql/libpg-query-node"/></a>
12+
</p>
13+
314
The real PostgreSQL parser, exposed for nodejs.
415

516
Primarily used for the node.js parser and deparser [pgsql-parser](https://github.com/pyramation/pgsql-parser)
617

7-
## Building a binary distribution
818

9-
- Install requirements (`npm i`)
10-
- `npx node-pre-gyp rebuild package`
11-
- With appropriate AWS credentials configured, `npx node-pre-gyp publish`
19+
## Table of Contents
1220

13-
Or you can run the scripts
21+
1. [Installation](#installation)
22+
2. [Example](#example)
23+
5. [Documentation](#documentation)
24+
3. [Versions](#versions)
25+
4. [Building a binary distribution](#building-a-binary-distribution)
26+
6. [Related Projects](#related-projects)
27+
7. [Credit](#credit)
1428

15-
```
16-
npm run binary:build
17-
npm run binary:publish
18-
```
1929

2030
## Installation
2131

2232
```sh
2333
npm install libpg-query
2434
```
2535

36+
## Example
37+
38+
```js
39+
const parser = require('libpg-query');
40+
parser.parseQuery('select 1').then(console.log);
41+
```
42+
2643
### Documentation
2744

2845
### `query.parseQuery(sql)`/`parseQuerySync`
@@ -35,27 +52,36 @@ The return value is an array, as multiple queries may be provided in a single st
3552

3653
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.
3754

38-
## Example
55+
## Versions
3956

40-
```js
41-
const parser = require('libpg-query');
42-
parser.parseQuery('select 1').then(console.log);
43-
```
57+
Our latest is built with `16-latest` branch from libpg_query
4458

45-
## Versions
4659

47-
Our latest is built with `15-latest` branch from libpg_query
60+
| PG Major Version | libpg_query | Branch | npm
61+
|--------------------------|-------------|------------------------------------------------------------------------------------------------|---------|
62+
| 16 | 16-latest | [`16-latest`](https://github.com/launchql/libpg-query-node/tree/16-latest) | [`[email protected]`](https://www.npmjs.com/package/libpg-query/v/latest)
63+
| 15 | 15-latest | [`15-latest`](https://github.com/launchql/libpg-query-node/tree/15-latest) | [`[email protected]`](https://www.npmjs.com/package/libpg-query/v/15.0.0)
64+
| 14 | 14-latest | [`14-latest`](https://github.com/launchql/libpg-query-node/tree/14-latest) | [`[email protected]`](https://www.npmjs.com/package/libpg-query/v/14.0.0)
65+
| 13 | 13-latest | [`13-latest`](https://github.com/launchql/libpg-query-node/tree/13-latest) | [`[email protected]`](https://www.npmjs.com/package/libpg-query/v/13.3.1)
66+
| 12 | (n/a) | |
67+
| 11 | (n/a) | |
68+
| 10 | 10-latest | | `@1.3.1` ([tree](https://github.com/pyramation/pgsql-parser/tree/39b7b1adc8914253226e286a48105785219a81ca)) |
69+
4870

49-
| PostgreSQL Major Version | libpg_query | Status | npm
50-
|--------------------------|-------------|---------------------|---------|
51-
| 15 | 15-latest | Supported | [`latest`](https://www.npmjs.com/package/libpg-query/v/latest)
52-
| 14 | 14-latest | Supported | [`[email protected]`](https://www.npmjs.com/package/libpg-query/v/14.0.0)
53-
| 13 | 13-latest | Supported | [`[email protected]`](https://www.npmjs.com/package/libpg-query/v/13.3.1)
54-
| 12 | (n/a) | Not supported |
55-
| 11 | (n/a) | Not supported |
56-
| 10 | 10-latest | Not supported | `@1.3.1` ([tree](https://github.com/pyramation/pgsql-parser/tree/39b7b1adc8914253226e286a48105785219a81ca)) |
71+
## Building a binary distribution
72+
73+
- Install requirements (`npm i`)
74+
- `npx node-pre-gyp rebuild package`
75+
- With appropriate AWS credentials configured, `npx node-pre-gyp publish`
76+
77+
Or you can run the scripts
78+
79+
```
80+
npm run binary:build
81+
npm run binary:publish
82+
```
5783

58-
## Related
84+
## Related Projects
5985

6086
* [libpg_query](https://github.com/pganalyze/libpg_query)
6187
* [pgsql-parser](https://github.com/pyramation/pgsql-parser)
@@ -68,6 +94,6 @@ This is based on the output of [libpg_query](https://github.com/pganalyze/libpg_
6894

6995
All credit for the hard problems goes to [Lukas Fittl](https://github.com/lfittl).
7096

71-
Additional thanks for node binding [Ethan Resnick](github.com/ethanresnick).
97+
Additional thanks for node binding [Ethan Resnick](https://github.com/ethanresnick).
7298

7399
Original [Code](https://github.com/zhm/node-pg-query-native) and [License](https://github.com/zhm/node-pg-query-native/blob/master/LICENSE.md)

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "libpg-query",
3-
"version": "15.0.2",
3+
"version": "15.0.3",
44
"description": "The real PostgreSQL query parser",
55
"homepage": "https://github.com/pyramation/libpg-query-node",
66
"main": "index.js",

script/buildAddon.sh

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,67 @@
11
#!/usr/bin/env bash
22

3-
commit=1ada550d901ed4edbfb6bce2163d21f4b948ab2d
3+
# Set the desired commit hash and branch
4+
commit=db39825bc7c1ddd45962ec6a626d740b7f8f027a
5+
branch=15-latest
46

7+
# Remember current directory and create a new, unique, temporary directory
58
rDIR=$(pwd)
69
tmpDir=$(mktemp -d 2>/dev/null || mktemp -d -t 'tmpdir.XXXX')
10+
11+
# Define the make target
712
makeTarget=build
813

14+
# Change to the newly created temp directory
915
cd "$tmpDir"
1016

11-
git clone -b 15-latest --single-branch https://github.com/pganalyze/libpg_query.git
17+
# Clone the selected branch of the libpg_query Git repo
18+
git clone -b $branch --single-branch https://github.com/pganalyze/libpg_query.git
1219
cd libpg_query
1320

21+
# Checkout the desired commit
1422
git checkout $commit
1523

1624
# needed if being invoked from within gyp
1725
unset MAKEFLAGS
1826
unset MFLAGS
1927

28+
# Adaptively build for macOS or Linux
2029
if [ "$(uname)" == "Darwin" ]; then
2130
make CFLAGS='-mmacosx-version-min=10.7' PG_CFLAGS='-mmacosx-version-min=10.7' $makeTarget
2231
elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then
2332
make CFLAGS='' PG_CFLAGS='' $makeTarget
2433
fi
2534

35+
# Terminate if build fails
2636
if [ $? -ne 0 ]; then
2737
echo "ERROR: 'make' command failed";
2838
exit 1;
2939
fi
3040

41+
# Search for libpg_query.a, error if not found
3142
file=$(ls | grep 'libpg_query.a')
32-
3343
if [ ! $file ]; then
3444
echo "ERROR: libpg_query.a not found";
3545
exit 1;
3646
fi
3747

48+
# Error if pg_query.h is missing
3849
file=$(ls | grep 'pg_query.h')
39-
4050
if [ ! $file ]; then
4151
echo "ERROR: pg_query.h not found";
4252
exit 1;
4353
fi
4454

45-
#copy queryparser.cc, binding.gyp to current directory
46-
#
47-
#
48-
55+
# Copy queryparser.cc, binding.gyp to current directory
4956
if [ "$(uname)" == "Darwin" ]; then
5057
cp $(pwd)/libpg_query.a $rDIR/libpg_query/osx/
5158
elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then
5259
cp $(pwd)/libpg_query.a $rDIR/libpg_query/linux/
5360
fi
5461

62+
# Copy header
5563
cp $(pwd)/pg_query.h $rDIR/libpg_query/include/
5664

65+
# Cleanup: revert to original directory and remove the temp
5766
cd "$rDIR"
5867
rm -rf "$tmpDir"

0 commit comments

Comments
 (0)