Skip to content

Commit 865f337

Browse files
authored
Merge pull request #114 from launchql/r/versions
R/versions
2 parents 595040a + 0c7e19e commit 865f337

File tree

142 files changed

+36548
-1146
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

142 files changed

+36548
-1146
lines changed

.github/workflows/build-wasm-no-docker.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: Build Wasm No Docker 🛠
22
'on':
33
workflow_dispatch: null
44
jobs:
5-
build-wasm:
5+
build-wasm-no-docker:
66
runs-on: ubuntu-latest
77
steps:
88
- name: Checkout Repository 📥

.github/workflows/build-wasm.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ on:
55

66
jobs:
77
build-wasm:
8-
runs-on: ubuntu-latest
8+
runs-on: macos-latest
99
steps:
1010
- name: Checkout Repository 📥
1111
uses: actions/checkout@v4

.github/workflows/ci.yml

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,18 @@ on:
99

1010
jobs:
1111
build-wasm:
12-
name: Build WASM 🔧
12+
name: Build WASM ${{ matrix.package }} 🔧
1313
runs-on: ubuntu-latest
14+
strategy:
15+
matrix:
16+
package:
17+
- { name: 'libpg-query', path: 'libpg-query', version: '17' }
18+
- { name: 'v13', path: 'versions/13', version: '13' }
19+
- { name: 'v14', path: 'versions/14', version: '14' }
20+
- { name: 'v15', path: 'versions/15', version: '15' }
21+
- { name: 'v16', path: 'versions/16', version: '16' }
22+
- { name: 'v17', path: 'versions/17', version: '17' }
23+
fail-fast: false
1424
steps:
1525
- name: Checkout Repository 📥
1626
uses: actions/checkout@v4
@@ -23,7 +33,7 @@ jobs:
2333
- name: Setup pnpm 📦
2434
uses: pnpm/action-setup@v2
2535
with:
26-
version: 8.15.0
36+
version: 8.15.1
2737

2838
- name: Get pnpm store directory 📁
2939
shell: bash
@@ -42,22 +52,38 @@ jobs:
4252
run: pnpm install
4353

4454
- name: Build WASM 🏗
45-
run: pnpm run build
46-
working-directory: libpg-query
55+
run: |
56+
if [ "${{ matrix.package.name }}" = "v13" ]; then
57+
# Download prebuilt WASM for v13 since it can't build in CI
58+
mkdir -p wasm
59+
curl -o v13.tgz "https://registry.npmjs.org/@libpg-query/v13/-/v13-13.0.0.tgz"
60+
tar -xzf v13.tgz --strip-components=1 package/wasm
61+
rm v13.tgz
62+
else
63+
pnpm run build
64+
fi
65+
working-directory: ${{ matrix.package.path }}
4766

4867
- name: Upload WASM Artifacts 📦
4968
uses: actions/upload-artifact@v4
5069
with:
51-
name: wasm-artifacts
52-
path: libpg-query/wasm/
70+
name: wasm-artifacts-${{ matrix.package.name }}
71+
path: ${{ matrix.package.path }}/wasm/
5372
retention-days: 1
5473

5574
test:
56-
name: Test on ${{ matrix.os }} ${{ matrix.os == 'ubuntu-latest' && '🐧' || matrix.os == 'macos-latest' && '🍎' || '🪟' }}
75+
name: Test ${{ matrix.package.name }} on ${{ matrix.os }} ${{ matrix.os == 'ubuntu-latest' && '🐧' || matrix.os == 'macos-latest' && '🍎' || '🪟' }}
5776
needs: build-wasm
5877
strategy:
5978
matrix:
6079
os: [ubuntu-latest, macos-latest, windows-latest]
80+
package:
81+
- { name: 'libpg-query', path: 'libpg-query', version: '17' }
82+
- { name: 'v13', path: 'versions/13', version: '13' }
83+
- { name: 'v14', path: 'versions/14', version: '14' }
84+
- { name: 'v15', path: 'versions/15', version: '15' }
85+
- { name: 'v16', path: 'versions/16', version: '16' }
86+
- { name: 'v17', path: 'versions/17', version: '17' }
6187
fail-fast: false
6288
runs-on: ${{ matrix.os }}
6389
steps:
@@ -72,7 +98,7 @@ jobs:
7298
- name: Setup pnpm 📦
7399
uses: pnpm/action-setup@v2
74100
with:
75-
version: 8.15.0
101+
version: 8.15.1
76102

77103
- name: Get pnpm store directory 📁
78104
shell: bash
@@ -93,8 +119,9 @@ jobs:
93119
- name: Download WASM Artifacts 📥
94120
uses: actions/download-artifact@v4
95121
with:
96-
name: wasm-artifacts
97-
path: libpg-query/wasm/
122+
name: wasm-artifacts-${{ matrix.package.name }}
123+
path: ${{ matrix.package.path }}/wasm/
98124

99125
- name: Run Tests 🔍
100126
run: pnpm run test
127+
working-directory: ${{ matrix.package.path }}

.gitignore

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,27 @@
1+
# Dependencies
12
node_modules/
3+
.pnpm-store/
4+
5+
# Build artifacts
26
build/
37
libs/
4-
npm-debug.log
5-
libpg_query/**/*.proto
6-
wasm/libpg-query.js
7-
*.wasm
8-
.cache
98
esm/
109
cjs/
11-
.claude
10+
dist/
1211

13-
# pnpm
14-
.pnpm-store/
12+
# WASM build outputs
13+
wasm/
14+
versions/*/wasm/
15+
*.wasm
16+
wasm/libpg-query.js
17+
18+
# Build cache and temporary files
19+
.cache
20+
21+
# Generated files
22+
libpg_query/**/*.proto
23+
24+
# Development tools and logs
25+
npm-debug.log
26+
.claude
27+
.openhands/

.npmrc

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# PNPM workspace optimization settings
2+
3+
# Use hard links to save disk space (when possible)
4+
node-linker=hoisted
5+
6+
# Strict peer dependency resolution
7+
strict-peer-dependencies=true
8+
9+
# Auto-install peers (useful for workspace packages)
10+
auto-install-peers=true
11+
12+
# Save exact versions in package.json
13+
save-exact=true
14+
15+
# Use workspace protocol for local dependencies
16+
link-workspace-packages=true
17+
18+
# Prefer workspace packages over registry
19+
prefer-workspace-packages=true
20+
21+
# Hoist pattern for shared dependencies
22+
# This helps reduce duplication
23+
public-hoist-pattern[]=*types*
24+
public-hoist-pattern[]=*eslint*
25+
public-hoist-pattern[]=*prettier*
26+
27+
# Shamefully hoist these common dev dependencies
28+
shamefully-hoist=false
29+
30+
# Enable workspace protocol
31+
enable-pre-post-scripts=true

BUILD_SIZE_REPORT.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Build Size Analysis Report
2+
3+
Generated on: 2025-06-22T06:22:35.227Z
4+
5+
## Summary
6+
7+
| Package | Total Size | Total Gzipped | Reduction |
8+
|---------|------------|---------------|-----------|
9+
| libpg-query (Original) | 2.07 MB | 428.77 KB | Baseline |
10+
| @libpg-query/v17 | 2.05 MB | 427.95 KB | 0.7% |
11+
12+
## Detailed Breakdown
13+
14+
### libpg-query (Original)
15+
16+
| File | Size | Gzipped | Gzip Ratio |
17+
|------|------|---------|------------|
18+
| WASM Binary | 1.99 MB | 409.96 KB | 79.9% |
19+
| WASM Loader | 58.66 KB | 16.24 KB | 72.3% |
20+
| ES Module | 9.48 KB | 1.07 KB | 88.8% |
21+
| CommonJS | 10.75 KB | 1.5 KB | 86.1% |
22+
23+
### @libpg-query/v17
24+
25+
| File | Size | Gzipped | Gzip Ratio |
26+
|------|------|---------|------------|
27+
| WASM Binary | 1.99 MB | 409.96 KB | 79.9% |
28+
| WASM Loader | 58.66 KB | 16.24 KB | 72.3% |
29+
| ES Module | 2.29 KB | 694 Bytes | 70.4% |
30+
| CommonJS | 3.29 KB | 1.06 KB | 67.7% |
31+
32+
## Size Comparison
33+
34+
### WASM Binary Comparison
35+
36+
| Package | WASM Size | Difference |
37+
|---------|-----------|------------|
38+
| libpg-query (Original) | 1.99 MB | Baseline |
39+
| @libpg-query/v17 | 1.99 MB | 0.0 KB (0.0%) |
40+
41+
### JavaScript Bundle Comparison
42+
43+
| Package | ES Module | CommonJS | Combined |
44+
|---------|-----------|----------|----------|
45+
| libpg-query (Original) | 9.48 KB | 10.75 KB | 20.23 KB |
46+
| @libpg-query/v17 | 2.29 KB | 3.29 KB | 5.57 KB |
47+
48+
## Notes
49+
50+
- Gzipped sizes represent the approximate size when served with compression
51+
- The WASM binary is the largest component and is shared across all API methods
52+
- JavaScript wrapper size varies based on the number of exported functions
53+
- @libpg-query/v17 only exports parse/parseSync, reducing JavaScript bundle size

PUBLISH.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Publishing Guide
2+
3+
## Types Packages
4+
5+
```bash
6+
# Set the version (e.g. 17, 16, 15, etc.)
7+
VERSION=17
8+
9+
cd types/${VERSION}
10+
pnpm version patch
11+
git add . && git commit -m "release: bump @pgsql/types${VERSION} version"
12+
pnpm build
13+
pnpm prepare:types
14+
pnpm publish --tag pg${VERSION}
15+
```
16+
17+
Promote to latest (optional)
18+
19+
```bash
20+
# Set the version (e.g. 17, 16, 15, etc.)
21+
VERSION=17
22+
23+
# Promote pg${VERSION} tag to latest
24+
npm dist-tag add @pgsql/types@pg${VERSION} latest
25+
```
26+
27+
### What it does
28+
- Transforms `@libpg-query/types17``@pgsql/types` with tag `pg17`
29+
- Transforms `@libpg-query/types16``@pgsql/types` with tag `pg16`
30+
- etc.
31+
32+
## Version Packages
33+
34+
### Quick Publish
35+
```bash
36+
# Set the version (e.g. 17, 16, 15, etc.)
37+
VERSION=17
38+
39+
# Build and publish a specific version
40+
cd versions/${VERSION}
41+
pnpm version patch
42+
git add . && git commit -m "release: bump libpg-query${VERSION} version"
43+
pnpm build
44+
pnpm test
45+
pnpm run publish:pkg
46+
```
47+
48+
### What it does
49+
- Transforms `@libpg-query/v17``libpg-query` with tag `pg17`
50+
- Transforms `@libpg-query/v16``libpg-query` with tag `pg16`
51+
- Uses `x-publish.publishName` and `x-publish.distTag` from package.json
52+
- Temporarily modifies package.json during publish, then restores it
53+
54+
### Install published packages
55+
```bash
56+
npm install libpg-query@pg17 # PostgreSQL 17 specific
57+
npm install libpg-query@pg16 # PostgreSQL 16 specific
58+
npm install libpg-query # Latest/default version
59+
```

README.md

Lines changed: 37 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,22 @@
1515
<a href="https://github.com/launchql/libpg-query-node/actions/workflows/ci.yml"><img height="20" src="https://img.shields.io/badge/Linux-available-333333?logo=linux&logoColor=white" /></a>
1616
</p>
1717

18-
The real PostgreSQL parser for Node.js, powered by **WebAssembly (WASM)** for true cross-platform compatibility.
18+
# The Real PostgreSQL Parser for JavaScript
1919

20-
A WASM-based PostgreSQL query parser that provides the same functionality as the native PostgreSQL parser without requiring native compilation or platform-specific binaries. Primarily used for the node.js parser and deparser [pgsql-parser](https://github.com/pyramation/pgsql-parser).
20+
### Bring the power of PostgreSQL’s native parser to your JavaScript projects — no native builds, no platform headaches.
2121

22+
This is the official PostgreSQL parser, compiled to WebAssembly (WASM) for seamless, cross-platform compatibility. Use it in Node.js or the browser, on Linux, Windows, or anywhere JavaScript runs.
2223

23-
## Table of Contents
24+
Built to power [pgsql-parser](https://github.com/pyramation/pgsql-parser), this library delivers full fidelity with the Postgres C codebase — no rewrites, no shortcuts.
2425

25-
1. [Installation](#installation)
26-
2. [Usage](#usage)
27-
3. [Build Instructions](#build-instructions)
28-
4. [Testing](#testing)
29-
5. [Versions](#versions)
30-
6. [Related Projects](#related-projects)
31-
7. [Credit](#credit)
26+
### Features
3227

28+
* 🔧 **Powered by PostgreSQL** – Uses the official Postgres C parser compiled to WebAssembly
29+
* 🖥️ **Cross-Platform** – Runs smoothly on macOS, Linux, and Windows
30+
* 🌐 **Node.js & Browser Support** – Consistent behavior in any JS environment
31+
* 📦 **No Native Builds Required** – No compilation, no system-specific dependencies
32+
* 🧠 **Spec-Accurate Parsing** – Produces faithful, standards-compliant ASTs
33+
* 🚀 **Production-Grade** – Powers tools like [`pgsql-parser`](https://github.com/pyramation/pgsql-parser)
3334

3435
## Installation
3536

@@ -322,13 +323,13 @@ pnpm run test
322323
Our latest is built with `17-latest` branch from libpg_query
323324

324325

325-
| PG Major Version | libpg_query | Branch | npm
326-
|--------------------------|-------------|------------------------------------------------------------------------------------------------|---------|
327-
| 17 | 17-latest | [`17-latest`](https://github.com/launchql/libpg-query-node/tree/17-latest) | [`[email protected]`](https://www.npmjs.com/package/libpg-query/v/latest)
328-
| 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/16.2.0)
329-
| 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.1.0)
330-
| 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)
331-
| 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)
326+
| PG Major Version | libpg_query | npm dist-tag
327+
|--------------------------|-------------|---------|
328+
| 17 | 17-6.1.0 | [`pg17`](https://www.npmjs.com/package/libpg-query/v/latest)
329+
| 16 | 16-5.2.0 | [`pg16`](https://www.npmjs.com/package/libpg-query/v/pg16)
330+
| 15 | 15-4.2.4 | [`pg15`](https://www.npmjs.com/package/libpg-query/v/pg15)
331+
| 14 | 14-3.0.0 | [`pg14`](https://www.npmjs.com/package/libpg-query/v/pg14)
332+
| 13 | 13-2.2.0 | [`pg13`](https://www.npmjs.com/package/libpg-query/v/pg13)
332333
| 12 | (n/a) | |
333334
| 11 | (n/a) | |
334335
| 10 | 10-latest | | `@1.3.1` ([tree](https://github.com/pyramation/pgsql-parser/tree/39b7b1adc8914253226e286a48105785219a81ca)) |
@@ -367,10 +368,25 @@ The build process generates these files:
367368

368369
## Credit
369370

370-
This is based on the output of [libpg_query](https://github.com/pganalyze/libpg_query). This wraps the static library output and links it into a node module for use in js.
371+
* This is based on the output of [libpg_query](https://github.com/pganalyze/libpg_query). This wraps the static library output and links it into a node module for use in js.
371372

372-
All credit for the hard problems goes to [Lukas Fittl](https://github.com/lfittl).
373+
* All credit for the hard problems goes to [Lukas Fittl](https://github.com/lfittl).
373374

374-
Additional thanks for the original Node.js integration work by [Ethan Resnick](https://github.com/ethanresnick).
375+
* Additional thanks for the original Node.js integration work by [Ethan Resnick](https://github.com/ethanresnick).
375376

376-
Original [Code](https://github.com/zhm/node-pg-query-native) and [License](https://github.com/zhm/node-pg-query-native/blob/master/LICENSE.md)
377+
* Original [Code](https://github.com/zhm/node-pg-query-native) and [License](https://github.com/zhm/node-pg-query-native/blob/master/LICENSE.md)
378+
379+
## Related
380+
381+
* [pgsql-parser](https://github.com/launchql/pgsql-parser): The real PostgreSQL parser for Node.js, providing symmetric parsing and deparsing of SQL statements with actual PostgreSQL parser integration.
382+
* [pgsql-deparser](https://github.com/launchql/pgsql-parser/tree/main/packages/deparser): A streamlined tool designed for converting PostgreSQL ASTs back into SQL queries, focusing solely on deparser functionality to complement `pgsql-parser`.
383+
* [@pgsql/types](https://github.com/launchql/pgsql-parser/tree/main/packages/types): Offers TypeScript type definitions for PostgreSQL AST nodes, facilitating type-safe construction, analysis, and manipulation of ASTs.
384+
* [@pgsql/utils](https://github.com/launchql/pgsql-parser/tree/main/packages/utils): A comprehensive utility library for PostgreSQL, offering type-safe AST node creation and enum value conversions, simplifying the construction and manipulation of PostgreSQL ASTs.
385+
* [pg-proto-parser](https://github.com/launchql/pg-proto-parser): A TypeScript tool that parses PostgreSQL Protocol Buffers definitions to generate TypeScript interfaces, utility functions, and JSON mappings for enums.
386+
* [libpg-query](https://github.com/launchql/libpg-query-node): The real PostgreSQL parser exposed for Node.js, used primarily in `pgsql-parser` for parsing and deparsing SQL queries.
387+
388+
## Disclaimer
389+
390+
AS DESCRIBED IN THE LICENSES, THE SOFTWARE IS PROVIDED “AS IS”, AT YOUR OWN RISK, AND WITHOUT WARRANTIES OF ANY KIND.
391+
392+
No developer or entity involved in creating Software will be liable for any claims or damages whatsoever associated with your use, inability to use, or your interaction with other users of the Software code or Software CLI, including any direct, indirect, incidental, special, exemplary, punitive or consequential damages, or loss of profits, cryptocurrencies, tokens, or anything else of value.

libpg-query/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ $(LIBPG_QUERY_ARCHIVE): $(LIBPG_QUERY_DIR)
5050
# Build libpg-query-node WASM module
5151
$(OUT_FILES): $(LIBPG_QUERY_ARCHIVE) $(LIBPG_QUERY_HEADER) $(SRC_FILES)
5252
ifdef EMSCRIPTEN
53+
mkdir -p $(WASM_OUT_DIR)
5354
$(CC) \
5455
-v \
5556
$(CXXFLAGS) \

0 commit comments

Comments
 (0)