Skip to content

Commit 3ed3713

Browse files
committed
readmes
1 parent 4edda65 commit 3ed3713

File tree

7 files changed

+74
-93
lines changed

7 files changed

+74
-93
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

β€Ž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

β€Žversions/13/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

β€Žversions/14/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

β€Žversions/15/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

β€Žversions/16/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

β€Žversions/17/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

0 commit comments

Comments
Β (0)