You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+38-87Lines changed: 38 additions & 87 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -23,14 +23,19 @@ This is the official PostgreSQL parser, compiled to WebAssembly (WASM) for seaml
23
23
24
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.
25
25
26
-
###Features
26
+
## Features
27
27
28
28
* π§ **Powered by PostgreSQL** β Uses the official Postgres C parser compiled to WebAssembly
29
29
* π₯οΈ **Cross-Platform** β Runs smoothly on macOS, Linux, and Windows
30
30
* π **Node.js & Browser Support** β Consistent behavior in any JS environment
31
31
* π¦ **No Native Builds Required** β No compilation, no system-specific dependencies
* π **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.
34
39
35
40
## Installation
36
41
@@ -47,105 +52,51 @@ const result = await parse('SELECT * FROM users WHERE active = true');
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 =awaitparse('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
85
56
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:
87
58
88
-
### Initialization
59
+
### Available Packages & Versions
89
60
90
-
The library provides both async and sync methods. Async methods handle initialization automatically, while sync methods require explicit initialization.
|**[@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)|
91
67
92
-
#### Async Methods (Recommended)
68
+
###Version Tags
93
69
94
-
Async methods handle initialization automatically and are always safe to use:
70
+
Each versioned package uses npm dist-tags for PostgreSQL version selection:
95
71
96
-
```typescript
97
-
import { parse } from'libpg-query';
98
-
99
-
// These handle initialization automatically
100
-
const result =awaitparse('SELECT * FROM users');
101
-
```
102
-
103
-
#### Sync Methods
104
-
105
-
Sync methods require explicit initialization using `loadModule()`:
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
130
93
131
-
### Type Definitions
132
-
133
-
```typescript
134
-
interfaceParseResult {
135
-
version:number;
136
-
stmts:Statement[];
137
-
}
138
-
139
-
interfaceStatement {
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:
147
95
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)
* π **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.
* π **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.
* π **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.
* π **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.
* π **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.
* π **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.
0 commit comments