Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
d0f7e97
v17 wip
pyramation Jun 22, 2025
a938ef8
md
pyramation Jun 22, 2025
e806c7d
tests
pyramation Jun 22, 2025
9dfbe3d
v17
pyramation Jun 22, 2025
5bf9014
v16
pyramation Jun 22, 2025
d22056f
versions
pyramation Jun 22, 2025
95b3277
workflow
pyramation Jun 22, 2025
39c3326
build scripts
pyramation Jun 22, 2025
b1ad912
spinlock patch
pyramation Jun 22, 2025
136bedd
updates
pyramation Jun 22, 2025
25ed5f0
tests
pyramation Jun 22, 2025
2ddb4ed
spin locks patch updated
pyramation Jun 22, 2025
937fb10
PG13
pyramation Jun 22, 2025
6c6ce7c
ignore
pyramation Jun 22, 2025
20026f3
update build
pyramation Jun 22, 2025
7ae0b7f
types
pyramation Jun 22, 2025
dd8f27c
dist
pyramation Jun 22, 2025
0da71a9
ignore
pyramation Jun 22, 2025
832e159
remove jest
pyramation Jun 22, 2025
569af4f
lock
pyramation Jun 22, 2025
a1c9b3c
ci
pyramation Jun 22, 2025
01c95ab
pkgs
pyramation Jun 22, 2025
92d69c2
types
pyramation Jun 22, 2025
0bccfeb
windows compat
pyramation Jun 22, 2025
bf9bf30
lock
pyramation Jun 22, 2025
2fdc53f
types
pyramation Jun 22, 2025
40cfe29
version
pyramation Jun 22, 2025
cb6bf22
updates
pyramation Jun 22, 2025
b54b524
release: bump @pgsql/types16 version
pyramation Jun 22, 2025
2beef7c
release: bump @pgsql/types17 version
pyramation Jun 22, 2025
cd8b425
publish
pyramation Jun 22, 2025
b2dde90
release: bump @pgsql/types15 version
pyramation Jun 22, 2025
a5d1778
release: bump @pgsql/types14 version
pyramation Jun 22, 2025
70192ad
release: bump @pgsql/types13 version
pyramation Jun 22, 2025
19d7578
versions
pyramation Jun 22, 2025
0c7e19e
readme
pyramation Jun 22, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build-wasm-no-docker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Build Wasm No Docker 🛠
'on':
workflow_dispatch: null
jobs:
build-wasm:
build-wasm-no-docker:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository 📥
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build-wasm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:

jobs:
build-wasm:
runs-on: ubuntu-latest
runs-on: macos-latest
steps:
- name: Checkout Repository 📥
uses: actions/checkout@v4
Expand Down
47 changes: 37 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,18 @@ on:

jobs:
build-wasm:
name: Build WASM 🔧
name: Build WASM ${{ matrix.package }} 🔧
runs-on: ubuntu-latest
strategy:
matrix:
package:
- { name: 'libpg-query', path: 'libpg-query', version: '17' }
- { name: 'v13', path: 'versions/13', version: '13' }
- { name: 'v14', path: 'versions/14', version: '14' }
- { name: 'v15', path: 'versions/15', version: '15' }
- { name: 'v16', path: 'versions/16', version: '16' }
- { name: 'v17', path: 'versions/17', version: '17' }
fail-fast: false
steps:
- name: Checkout Repository 📥
uses: actions/checkout@v4
Expand All @@ -23,7 +33,7 @@ jobs:
- name: Setup pnpm 📦
uses: pnpm/action-setup@v2
with:
version: 8.15.0
version: 8.15.1

- name: Get pnpm store directory 📁
shell: bash
Expand All @@ -42,22 +52,38 @@ jobs:
run: pnpm install

- name: Build WASM 🏗
run: pnpm run build
working-directory: libpg-query
run: |
if [ "${{ matrix.package.name }}" = "v13" ]; then
# Download prebuilt WASM for v13 since it can't build in CI
mkdir -p wasm
curl -o v13.tgz "https://registry.npmjs.org/@libpg-query/v13/-/v13-13.0.0.tgz"
tar -xzf v13.tgz --strip-components=1 package/wasm
rm v13.tgz
else
pnpm run build
fi
working-directory: ${{ matrix.package.path }}

- name: Upload WASM Artifacts 📦
uses: actions/upload-artifact@v4
with:
name: wasm-artifacts
path: libpg-query/wasm/
name: wasm-artifacts-${{ matrix.package.name }}
path: ${{ matrix.package.path }}/wasm/
retention-days: 1

test:
name: Test on ${{ matrix.os }} ${{ matrix.os == 'ubuntu-latest' && '🐧' || matrix.os == 'macos-latest' && '🍎' || '🪟' }}
name: Test ${{ matrix.package.name }} on ${{ matrix.os }} ${{ matrix.os == 'ubuntu-latest' && '🐧' || matrix.os == 'macos-latest' && '🍎' || '🪟' }}
needs: build-wasm
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
package:
- { name: 'libpg-query', path: 'libpg-query', version: '17' }
- { name: 'v13', path: 'versions/13', version: '13' }
- { name: 'v14', path: 'versions/14', version: '14' }
- { name: 'v15', path: 'versions/15', version: '15' }
- { name: 'v16', path: 'versions/16', version: '16' }
- { name: 'v17', path: 'versions/17', version: '17' }
fail-fast: false
runs-on: ${{ matrix.os }}
steps:
Expand All @@ -72,7 +98,7 @@ jobs:
- name: Setup pnpm 📦
uses: pnpm/action-setup@v2
with:
version: 8.15.0
version: 8.15.1

- name: Get pnpm store directory 📁
shell: bash
Expand All @@ -93,8 +119,9 @@ jobs:
- name: Download WASM Artifacts 📥
uses: actions/download-artifact@v4
with:
name: wasm-artifacts
path: libpg-query/wasm/
name: wasm-artifacts-${{ matrix.package.name }}
path: ${{ matrix.package.path }}/wasm/

- name: Run Tests 🔍
run: pnpm run test
working-directory: ${{ matrix.package.path }}
29 changes: 21 additions & 8 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
# Dependencies
node_modules/
.pnpm-store/

# Build artifacts
build/
libs/
npm-debug.log
libpg_query/**/*.proto
wasm/libpg-query.js
*.wasm
.cache
esm/
cjs/
.claude
dist/

# pnpm
.pnpm-store/
# WASM build outputs
wasm/
versions/*/wasm/
*.wasm
wasm/libpg-query.js

# Build cache and temporary files
.cache

# Generated files
libpg_query/**/*.proto

# Development tools and logs
npm-debug.log
.claude
.openhands/
31 changes: 31 additions & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# PNPM workspace optimization settings

# Use hard links to save disk space (when possible)
node-linker=hoisted

# Strict peer dependency resolution
strict-peer-dependencies=true

# Auto-install peers (useful for workspace packages)
auto-install-peers=true

# Save exact versions in package.json
save-exact=true

# Use workspace protocol for local dependencies
link-workspace-packages=true

# Prefer workspace packages over registry
prefer-workspace-packages=true

# Hoist pattern for shared dependencies
# This helps reduce duplication
public-hoist-pattern[]=*types*
public-hoist-pattern[]=*eslint*
public-hoist-pattern[]=*prettier*

# Shamefully hoist these common dev dependencies
shamefully-hoist=false

# Enable workspace protocol
enable-pre-post-scripts=true
53 changes: 53 additions & 0 deletions BUILD_SIZE_REPORT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Build Size Analysis Report

Generated on: 2025-06-22T06:22:35.227Z

## Summary

| Package | Total Size | Total Gzipped | Reduction |
|---------|------------|---------------|-----------|
| libpg-query (Original) | 2.07 MB | 428.77 KB | Baseline |
| @libpg-query/v17 | 2.05 MB | 427.95 KB | 0.7% |

## Detailed Breakdown

### libpg-query (Original)

| File | Size | Gzipped | Gzip Ratio |
|------|------|---------|------------|
| WASM Binary | 1.99 MB | 409.96 KB | 79.9% |
| WASM Loader | 58.66 KB | 16.24 KB | 72.3% |
| ES Module | 9.48 KB | 1.07 KB | 88.8% |
| CommonJS | 10.75 KB | 1.5 KB | 86.1% |

### @libpg-query/v17

| File | Size | Gzipped | Gzip Ratio |
|------|------|---------|------------|
| WASM Binary | 1.99 MB | 409.96 KB | 79.9% |
| WASM Loader | 58.66 KB | 16.24 KB | 72.3% |
| ES Module | 2.29 KB | 694 Bytes | 70.4% |
| CommonJS | 3.29 KB | 1.06 KB | 67.7% |

## Size Comparison

### WASM Binary Comparison

| Package | WASM Size | Difference |
|---------|-----------|------------|
| libpg-query (Original) | 1.99 MB | Baseline |
| @libpg-query/v17 | 1.99 MB | 0.0 KB (0.0%) |

### JavaScript Bundle Comparison

| Package | ES Module | CommonJS | Combined |
|---------|-----------|----------|----------|
| libpg-query (Original) | 9.48 KB | 10.75 KB | 20.23 KB |
| @libpg-query/v17 | 2.29 KB | 3.29 KB | 5.57 KB |

## Notes

- Gzipped sizes represent the approximate size when served with compression
- The WASM binary is the largest component and is shared across all API methods
- JavaScript wrapper size varies based on the number of exported functions
- @libpg-query/v17 only exports parse/parseSync, reducing JavaScript bundle size
59 changes: 59 additions & 0 deletions PUBLISH.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Publishing Guide

## Types Packages

```bash
# Set the version (e.g. 17, 16, 15, etc.)
VERSION=17

cd types/${VERSION}
pnpm version patch
git add . && git commit -m "release: bump @pgsql/types${VERSION} version"
pnpm build
pnpm prepare:types
pnpm publish --tag pg${VERSION}
```

Promote to latest (optional)

```bash
# Set the version (e.g. 17, 16, 15, etc.)
VERSION=17

# Promote pg${VERSION} tag to latest
npm dist-tag add @pgsql/types@pg${VERSION} latest
```

### What it does
- Transforms `@libpg-query/types17` → `@pgsql/types` with tag `pg17`
- Transforms `@libpg-query/types16` → `@pgsql/types` with tag `pg16`
- etc.

## Version Packages

### Quick Publish
```bash
# Set the version (e.g. 17, 16, 15, etc.)
VERSION=17

# Build and publish a specific version
cd versions/${VERSION}
pnpm version patch
git add . && git commit -m "release: bump libpg-query${VERSION} version"
pnpm build
pnpm test
pnpm run publish:pkg
```

### What it does
- Transforms `@libpg-query/v17` → `libpg-query` with tag `pg17`
- Transforms `@libpg-query/v16` → `libpg-query` with tag `pg16`
- Uses `x-publish.publishName` and `x-publish.distTag` from package.json
- Temporarily modifies package.json during publish, then restores it

### Install published packages
```bash
npm install libpg-query@pg17 # PostgreSQL 17 specific
npm install libpg-query@pg16 # PostgreSQL 16 specific
npm install libpg-query # Latest/default version
```
58 changes: 37 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,22 @@
<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>
</p>

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

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).
### Bring the power of PostgreSQL’s native parser to your JavaScript projects — no native builds, no platform headaches.

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.

## Table of Contents
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.

1. [Installation](#installation)
2. [Usage](#usage)
3. [Build Instructions](#build-instructions)
4. [Testing](#testing)
5. [Versions](#versions)
6. [Related Projects](#related-projects)
7. [Credit](#credit)
### Features

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

## Installation

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


| PG Major Version | libpg_query | Branch | npm
|--------------------------|-------------|------------------------------------------------------------------------------------------------|---------|
| 17 | 17-latest | [`17-latest`](https://github.com/launchql/libpg-query-node/tree/17-latest) | [`libpg-query@17.2.0`](https://www.npmjs.com/package/libpg-query/v/latest)
| 16 | 16-latest | [`16-latest`](https://github.com/launchql/libpg-query-node/tree/16-latest) | [`libpg-query@16.2.0`](https://www.npmjs.com/package/libpg-query/v/16.2.0)
| 15 | 15-latest | [`15-latest`](https://github.com/launchql/libpg-query-node/tree/15-latest) | [`libpg-query@15.1.0`](https://www.npmjs.com/package/libpg-query/v/15.1.0)
| 14 | 14-latest | [`14-latest`](https://github.com/launchql/libpg-query-node/tree/14-latest) | [`libpg-query@14.0.0`](https://www.npmjs.com/package/libpg-query/v/14.0.0)
| 13 | 13-latest | [`13-latest`](https://github.com/launchql/libpg-query-node/tree/13-latest) | [`libpg-query@13.3.1`](https://www.npmjs.com/package/libpg-query/v/13.3.1)
| PG Major Version | libpg_query | npm dist-tag
|--------------------------|-------------|---------|
| 17 | 17-6.1.0 | [`pg17`](https://www.npmjs.com/package/libpg-query/v/latest)
| 16 | 16-5.2.0 | [`pg16`](https://www.npmjs.com/package/libpg-query/v/pg16)
| 15 | 15-4.2.4 | [`pg15`](https://www.npmjs.com/package/libpg-query/v/pg15)
| 14 | 14-3.0.0 | [`pg14`](https://www.npmjs.com/package/libpg-query/v/pg14)
| 13 | 13-2.2.0 | [`pg13`](https://www.npmjs.com/package/libpg-query/v/pg13)
| 12 | (n/a) | |
| 11 | (n/a) | |
| 10 | 10-latest | | `@1.3.1` ([tree](https://github.com/pyramation/pgsql-parser/tree/39b7b1adc8914253226e286a48105785219a81ca)) |
Expand Down Expand Up @@ -367,10 +368,25 @@ The build process generates these files:

## Credit

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

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

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

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

## Related

* [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.
* [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`.
* [@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.
* [@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.
* [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.
* [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.

## Disclaimer

AS DESCRIBED IN THE LICENSES, THE SOFTWARE IS PROVIDED “AS IS”, AT YOUR OWN RISK, AND WITHOUT WARRANTIES OF ANY KIND.

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.
1 change: 1 addition & 0 deletions libpg-query/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ $(LIBPG_QUERY_ARCHIVE): $(LIBPG_QUERY_DIR)
# Build libpg-query-node WASM module
$(OUT_FILES): $(LIBPG_QUERY_ARCHIVE) $(LIBPG_QUERY_HEADER) $(SRC_FILES)
ifdef EMSCRIPTEN
mkdir -p $(WASM_OUT_DIR)
$(CC) \
-v \
$(CXXFLAGS) \
Expand Down
Loading