Skip to content

Commit 5cf69aa

Browse files
authored
Merge pull request #122 from launchql/versions
Versions
2 parents 3684aaa + 8a06903 commit 5cf69aa

26 files changed

+246
-137
lines changed

README.md

Lines changed: 38 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,19 @@ This is the official PostgreSQL parser, compiled to WebAssembly (WASM) for seaml
2323

2424
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.
2525

26-
### Features
26+
## Features
2727

2828
* 🔧 **Powered by PostgreSQL** – Uses the official Postgres C parser compiled to WebAssembly
2929
* 🖥️ **Cross-Platform** – Runs smoothly on macOS, Linux, and Windows
3030
* 🌐 **Node.js & Browser Support** – Consistent behavior in any JS environment
3131
* 📦 **No Native Builds Required** – No compilation, no system-specific dependencies
3232
* 🧠 **Spec-Accurate Parsing** – Produces faithful, standards-compliant ASTs
33-
* 🚀 **Production-Grade** – Powers tools like [`pgsql-parser`](https://github.com/pyramation/pgsql-parser)
33+
* 🚀 **Production-Grade** – Millions of downloads powering 1000s of projects
34+
35+
## 🚀 For Round-trip Codegen
36+
37+
> 🎯 **Want to parse + deparse (full round trip)?**
38+
> We highly recommend using [`pgsql-parser`](https://github.com/launchql/pgsql-parser) which leverages a pure TypeScript deparser that has been battle-tested against 21,000+ SQL statements and is built on top of libpg-query.
3439
3540
## Installation
3641

@@ -47,105 +52,51 @@ const result = await parse('SELECT * FROM users WHERE active = true');
4752
// {"version":170004,"stmts":[{"stmt":{"SelectStmt":{"targetList":[{"ResTarget" ... "op":"SETOP_NONE"}}}]}
4853
```
4954

50-
## Versions
51-
52-
Our latest is built with `17-latest` branch from libpg_query
53-
54-
| PG Major Version | libpg_query | npm dist-tag
55-
|--------------------------|-------------|---------|
56-
| 17 | 17-6.1.0 | [`pg17`](https://www.npmjs.com/package/libpg-query/v/latest)
57-
| 16 | 16-5.2.0 | [`pg16`](https://www.npmjs.com/package/libpg-query/v/pg16)
58-
| 15 | 15-4.2.4 | [`pg15`](https://www.npmjs.com/package/libpg-query/v/pg15)
59-
| 14 | 14-3.0.0 | [`pg14`](https://www.npmjs.com/package/libpg-query/v/pg14)
60-
| 13 | 13-2.2.0 | [`pg13`](https://www.npmjs.com/package/libpg-query/v/pg13)
61-
62-
## Usage
63-
64-
### `parse(query: string): Promise<ParseResult>`
65-
66-
Parses the SQL and returns a Promise for the parse tree. May reject with a parse error.
67-
68-
```typescript
69-
import { parse } from 'libpg-query';
70-
71-
const result = await parse('SELECT * FROM users WHERE active = true');
72-
// Returns: ParseResult - parsed query object
73-
```
74-
75-
### `parseSync(query: string): ParseResult`
76-
77-
Synchronous version that returns the parse tree directly. May throw a parse error.
78-
79-
```typescript
80-
import { parseSync } from 'libpg-query';
81-
82-
const result = parseSync('SELECT * FROM users WHERE active = true');
83-
// Returns: ParseResult - parsed query object
84-
```
55+
## 📦 Packages
8556

86-
**Note:** If you need additional functionality like `fingerprint`, `scan`, `deparse`, or `normalize`, check out the full package (`@libpg-query/parser`) in the [./full](https://github.com/launchql/libpg-query-node/tree/main/full) folder of the repo.
57+
This repository contains multiple packages to support different PostgreSQL versions and use cases:
8758

88-
### Initialization
59+
### Available Packages & Versions
8960

90-
The library provides both async and sync methods. Async methods handle initialization automatically, while sync methods require explicit initialization.
61+
| Package | Description | PostgreSQL Versions | npm Package |
62+
|---------|-------------|---------------------|-------------|
63+
| **[libpg-query](https://github.com/launchql/libpg-query-node/tree/main/versions)** | Lightweight parser (parse only) | 13, 14, 15, 16, 17 | [`libpg-query`](https://www.npmjs.com/package/libpg-query) |
64+
| **[@pgsql/types](https://github.com/launchql/libpg-query-node/tree/main/types)** | TypeScript type definitions | 13, 14, 15, 16, 17 | [`@pgsql/types`](https://www.npmjs.com/package/@pgsql/types) |
65+
| **[@pgsql/enums](https://github.com/launchql/libpg-query-node/tree/main/enums)** | TypeScript enum definitions | 13, 14, 15, 16, 17 | [`@pgsql/enums`](https://www.npmjs.com/package/@pgsql/enums) |
66+
| **[@libpg-query/parser](https://github.com/launchql/libpg-query-node/tree/main/full)** | Full parser with all features | 17 only | [`@libpg-query/parser`](https://www.npmjs.com/package/@libpg-query/parser) |
9167

92-
#### Async Methods (Recommended)
68+
### Version Tags
9369

94-
Async methods handle initialization automatically and are always safe to use:
70+
Each versioned package uses npm dist-tags for PostgreSQL version selection:
9571

96-
```typescript
97-
import { parse } from 'libpg-query';
98-
99-
// These handle initialization automatically
100-
const result = await parse('SELECT * FROM users');
101-
```
102-
103-
#### Sync Methods
104-
105-
Sync methods require explicit initialization using `loadModule()`:
106-
107-
```typescript
108-
import { loadModule, parseSync } from 'libpg-query';
109-
110-
// Initialize first
111-
await loadModule();
72+
```bash
73+
# Install specific PostgreSQL version
74+
npm install libpg-query@pg17 # PostgreSQL 17 (latest)
75+
npm install libpg-query@pg16 # PostgreSQL 16
76+
npm install @pgsql/types@pg17 # Types for PostgreSQL 17
77+
npm install @pgsql/enums@pg15 # Enums for PostgreSQL 15
11278

113-
// Now safe to use sync methods
114-
const result = parseSync('SELECT * FROM users');
79+
# Install latest (defaults to pg17)
80+
npm install libpg-query
81+
npm install @pgsql/types
82+
npm install @pgsql/enums
11583
```
11684

117-
### `loadModule(): Promise<void>`
85+
### Which Package Should I Use?
11886

119-
Explicitly initializes the WASM module. Required before using any sync methods.
87+
- **Just need to parse SQL?** → Use `libpg-query` (lightweight, all PG versions)
88+
- **Need TypeScript types?** → Add `@pgsql/types` and/or `@pgsql/enums`
89+
- **Need fingerprint, normalize, or deparse?** → Use `@libpg-query/parser` (PG 17 only)
12090

121-
```typescript
122-
import { loadModule, parseSync } from 'libpg-query';
123-
124-
// Initialize before using sync methods
125-
await loadModule();
126-
const result = parseSync('SELECT * FROM users');
127-
```
12891

129-
Note: We recommend using async methods as they handle initialization automatically. Use sync methods only when necessary, and always call `loadModule()` first.
92+
## API Documentation
13093

131-
### Type Definitions
132-
133-
```typescript
134-
interface ParseResult {
135-
version: number;
136-
stmts: Statement[];
137-
}
138-
139-
interface Statement {
140-
stmt_type: string;
141-
stmt_len: number;
142-
stmt_location: number;
143-
query: string;
144-
}
145-
146-
```
94+
For detailed API documentation and usage examples, see the package-specific READMEs:
14795

148-
**Note:** The return value is an array, as multiple queries may be provided in a single string (semicolon-delimited, as PostgreSQL expects).
96+
- **libpg-query** - [Parser API Documentation](https://github.com/launchql/libpg-query-node/tree/main/versions/17)
97+
- **@pgsql/types** - [Types Documentation](https://github.com/launchql/libpg-query-node/tree/main/types/17)
98+
- **@pgsql/enums** - [Enums Documentation](https://github.com/launchql/libpg-query-node/tree/main/enums/17)
99+
- **@libpg-query/parser** - [Full Parser Documentation](https://github.com/launchql/libpg-query-node/tree/main/full)
149100

150101
## Build Instructions
151102

enums/13/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/enums13",
3-
"version": "13.12.0",
3+
"version": "13.13.0",
44
"author": "Dan Lynch <[email protected]>",
55
"description": "PostgreSQL AST enums from the real Postgres parser",
66
"main": "index.js",

enums/14/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/enums14",
3-
"version": "14.8.0",
3+
"version": "14.9.0",
44
"author": "Dan Lynch <[email protected]>",
55
"description": "PostgreSQL AST enums from the real Postgres parser",
66
"main": "index.js",

enums/15/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/enums15",
3-
"version": "15.8.0",
3+
"version": "15.9.0",
44
"author": "Dan Lynch <[email protected]>",
55
"description": "PostgreSQL AST enums from the real Postgres parser",
66
"main": "index.js",

enums/16/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/enums16",
3-
"version": "16.8.0",
3+
"version": "16.9.0",
44
"author": "Dan Lynch <[email protected]>",
55
"description": "PostgreSQL AST enums from the real Postgres parser",
66
"main": "index.js",

enums/17/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/enums17",
3-
"version": "17.8.0",
3+
"version": "17.9.0",
44
"author": "Dan Lynch <[email protected]>",
55
"description": "PostgreSQL AST enums from the real Postgres parser",
66
"main": "index.js",

full/README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,12 @@ Built to power [pgsql-parser](https://github.com/pyramation/pgsql-parser), this
3030
* 🌐 **Node.js & Browser Support** – Consistent behavior in any JS environment
3131
* 📦 **No Native Builds Required** – No compilation, no system-specific dependencies
3232
* 🧠 **Spec-Accurate Parsing** – Produces faithful, standards-compliant ASTs
33-
* 🚀 **Production-Grade** – Powers tools like [`pgsql-parser`](https://github.com/pyramation/pgsql-parser)
33+
* 🚀 **Production-Grade** – Millions of downloads powering 1000s of projects
34+
35+
## 🚀 For Round-trip Codegen
36+
37+
> 🎯 **Want to parse + deparse (full round trip)?**
38+
> We highly recommend using [`pgsql-parser`](https://github.com/launchql/pgsql-parser) which leverages a pure TypeScript deparser that has been battle-tested against 21,000+ SQL statements and is built on top of libpg-query.
3439
3540
## Installation
3641

full/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"@yamlize/cli": "^0.8.0"
3838
},
3939
"dependencies": {
40-
"@pgsql/types": "^17.4.2",
40+
"@pgsql/types": "^17.6.0",
4141
"@launchql/protobufjs": "7.2.6"
4242
},
4343
"keywords": [

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
"build:enums": "node scripts/build-enums.js",
1818
"prepare:enums": "node scripts/prepare-enums.js",
1919
"publish:types": "node scripts/publish-types.js",
20-
"publish:enums": "node scripts/publish-enums.js"
20+
"publish:enums": "node scripts/publish-enums.js",
21+
"update:versions-types": "node scripts/update-versions-types.js"
2122
},
2223
"devDependencies": {
2324
"@types/node": "^20.0.0",

pnpm-lock.yaml

Lines changed: 22 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)