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
+57-51Lines changed: 57 additions & 51 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -27,6 +27,51 @@ npm install pgsql-parser
27
27
-**True PostgreSQL Parsing:** Utilizes the real PostgreSQL source code for accurate parsing.
28
28
-**Symmetric Parsing and Deparsing:** Convert SQL to AST and back, enabling query manipulation.
29
29
-**AST Manipulation:** Easily modify parts of a SQL statement through the AST.
30
+
-**WebAssembly Powered:** Cross-platform compatibility without native dependencies.
31
+
32
+
## API
33
+
34
+
The package exports both async and sync methods. Async methods handle initialization automatically, while sync methods require explicit initialization.
35
+
36
+
⚠️ We recommend using `@pgsql/deparser` instead of `deparse` from `pgsql-parser`. The deparser package is more complete, supports sub-expressions, and doesn't require the WebAssembly module, making it lighter and more flexible for most use cases. It will soon be deprecated, in a minor version bump.
const stmts =parseSync('SELECT * FROM test_table');
71
+
const sql =deparseSync(stmts);
72
+
```
73
+
74
+
**Note:** We recommend using async methods as they handle initialization automatically. Use sync methods only when necessary, and always call `loadModule()` first.
30
75
31
76
## Parser Example
32
77
@@ -35,12 +80,12 @@ Rewrite part of a SQL query:
35
80
```js
36
81
import { parse, deparse } from'pgsql-parser';
37
82
38
-
conststmts=parse('SELECT * FROM test_table');
83
+
conststmts=awaitparse('SELECT * FROM test_table');
39
84
40
85
// Assuming the structure of stmts is known and matches the expected type
@@ -52,11 +97,11 @@ The `pgsql-deparser` module serializes ASTs to SQL in pure TypeScript, avoiding
52
97
Here's how you can use the deparser in your TypeScript code, using [`@pgsql/utils`](https://github.com/launchql/pgsql-parser/tree/main/packages/utils) to create an AST for `deparse`:
53
98
54
99
```ts
55
-
importast, { SelectStmt }from'@pgsql/utils';
100
+
importastfrom'@pgsql/utils';
56
101
import { deparse } from'pgsql-deparser';
57
102
58
103
// This could have been obtained from any JSON or AST, not necessarily @pgsql/utils
|`query`| Object | Query tree obtained from `parse`|
132
-
133
-
Returns a normalized formatted SQL string.
134
-
135
144
## Versions
136
145
137
146
As of PG 13, PG majors versions maintained will have a matching dedicated major npm version. Only the latest Postgres stable release receives active updates.
138
147
139
-
Our latest is built with `13-latest` branch from libpg_query
148
+
Our latest is built with `17-latest` branch from libpg_query
140
149
141
-
| PostgreSQL Major Version | libpg_query | Status | npm
150
+
| PostgreSQL Major Version | libpg_query | Status | npm tag |
| 13 | 13-latest | Only Critical Fixes |`13.16.0`|
144
154
| 12 | (n/a) | Not supported |
145
155
| 11 | (n/a) | Not supported |
146
156
| 10 | 10-latest | Not supported |`@1.3.1` ([tree](https://github.com/launchql/pgsql-parser/tree/39b7b1adc8914253226e286a48105785219a81ca)) |
@@ -157,22 +167,18 @@ Our latest is built with `13-latest` branch from libpg_query
157
167
*[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.
158
168
*[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.
159
169
170
+
## Credits
171
+
160
172
Thanks [@lfittl](https://github.com/lfittl) for building the core `libpg_query` suite:
Thanks to [@zhm](https://github.com/zhm) for the [OG Parser](https://github.com/zhm/pg-query-parser/blob/master/LICENSE.md) that started it all.
173
179
174
180
## Disclaimer
175
181
176
-
AS DESCRIBED IN THE LICENSES, THE SOFTWARE IS PROVIDED “AS IS”, AT YOUR OWN RISK, AND WITHOUT WARRANTIES OF ANY KIND.
182
+
AS DESCRIBED IN THE LICENSES, THE SOFTWARE IS PROVIDED "AS IS", AT YOUR OWN RISK, AND WITHOUT WARRANTIES OF ANY KIND.
177
183
178
184
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.
0 commit comments