pgsql-parser 14.0.0 → 15.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pgsql-parser",
3
- "version": "14.0.0",
3
+ "version": "15.0.0",
4
4
  "author": "Dan Lynch <pyramation@gmail.com>",
5
5
  "description": "The real PostgreSQL query parser",
6
6
  "main": "index.js",
@@ -22,13 +22,8 @@
22
22
  "scripts": {
23
23
  "copy": "copyfiles -f ../../../../LICENSE README.md package.json dist",
24
24
  "clean": "rimraf dist",
25
- "prepare": "npm run build",
26
25
  "build": "npm run clean && tsc && tsc -p tsconfig.esm.json && npm run copy",
27
- "build:dev": "npm run clean && tsc --declarationMap && tsc -p tsconfig.esm.json && npm run copy",
28
- "lint": "eslint . --fix",
29
- "test": "jest",
30
- "test:watch": "jest --watch",
31
- "publish:pkg": "npm publish --tag pg14"
26
+ "publish:pkg": "npm publish --tag pg15"
32
27
  },
33
28
  "keywords": [
34
29
  "sql",
@@ -40,8 +35,8 @@
40
35
  "database"
41
36
  ],
42
37
  "dependencies": {
43
- "@pgsql/types": "14.1.1",
44
- "libpg-query": "14.2.5",
45
- "pgsql-deparser": "14.0.0"
38
+ "@pgsql/types": "15.1.1",
39
+ "libpg-query": "15.4.8",
40
+ "pgsql-deparser": "15.0.0"
46
41
  }
47
42
  }
package/dist/README.md DELETED
@@ -1,150 +0,0 @@
1
- # pgsql-parser
2
-
3
- <p align="center" width="100%">
4
- <img height="120" src="https://github.com/launchql/pgsql-parser/assets/545047/6440fa7d-918b-4a3b-8d1b-755d85de8bea" />
5
- </p>
6
-
7
- <p align="center" width="100%">
8
- <a href="https://github.com/launchql/pgsql-parser/actions/workflows/run-tests.yaml">
9
- <img height="20" src="https://github.com/launchql/pgsql-parser/actions/workflows/run-tests.yaml/badge.svg" />
10
- </a>
11
- <a href="https://www.npmjs.com/package/pgsql-parser"><img height="20" src="https://img.shields.io/npm/dt/pgsql-parser"></a>
12
- <a href="https://www.npmjs.com/package/pgsql-parser"><img height="20" src="https://img.shields.io/npm/dw/pgsql-parser"/></a>
13
- <a href="https://github.com/launchql/pgsql-parser/blob/main/LICENSE-MIT"><img height="20" src="https://img.shields.io/badge/license-MIT-blue.svg"/></a>
14
- <a href="https://www.npmjs.com/package/pgsql-parser"><img height="20" src="https://img.shields.io/github/package-json/v/launchql/pgsql-parser?filename=packages%2Fparser%2Fpackage.json"/></a>
15
- </p>
16
-
17
- The real PostgreSQL parser for Node.js. Built with the actual [PostgreSQL parser](https://github.com/pganalyze/libpg_query), `pgsql-parser` delivers true-to-spec SQL parsing and reconstruction. Transform SQL queries into ASTs, modify them programmatically, and convert them back to SQL with complete fidelity.
18
-
19
- ## Installation
20
-
21
- ```sh
22
- npm install pgsql-parser
23
- ```
24
-
25
- ## Features
26
-
27
- * 🔄 **Symmetric Parsing & Deparsing** – Parse SQL to AST and reconstruct it back to SQL with perfect round-trip accuracy
28
- * 🧪 **Battle-Tested Reliability** – Validated against 23,000+ SQL statements ensuring production-grade stability
29
- * 🔧 **Direct from PostgreSQL** – Uses the official Postgres C parser compiled to WebAssembly for 100% spec compliance
30
- * 🚀 **WebAssembly Powered:** - Cross-platform compatibility without native dependencies.
31
- * 🛠️ **AST Manipulation:** - Easily modify parts of a SQL statement through the AST.
32
-
33
- ## API
34
-
35
- The package exports both async and sync methods. Async methods handle initialization automatically, while sync methods require explicit initialization.
36
-
37
- ⚠️ If you don't need the parser functionality, consider using the TS-only (no WASM, zero runtime dependencies) [`pgsql-deparser`](https://github.com/launchql/pgsql-parser/tree/main/packages/deparser) for a super fast, lightweight deparser. Battle-tested with 23,000+ SQL statements 🚀
38
-
39
- ### Async Methods (Recommended)
40
-
41
- ```typescript
42
- import { parse, deparse } from 'pgsql-parser';
43
-
44
- // Parse SQL to AST
45
- const stmts = await parse('SELECT * FROM test_table');
46
-
47
- // Deparse AST back to SQL
48
- const sql = await deparse(stmts);
49
- ```
50
-
51
- ### Sync Methods
52
-
53
- Sync methods require explicit initialization using `loadModule()`:
54
-
55
- ```typescript
56
- import { loadModule, parseSync, deparseSync } from 'pgsql-parser';
57
-
58
- // Initialize first (required for sync methods)
59
- await loadModule();
60
-
61
- // Now safe to use sync methods
62
- const stmts = parseSync('SELECT * FROM test_table');
63
- const sql = deparseSync(stmts);
64
- ```
65
-
66
- **Note:** We recommend using async methods as they handle initialization automatically. Use sync methods only when necessary, and always call `loadModule()` first.
67
-
68
- ## Parser Example
69
-
70
- Rewrite part of a SQL query:
71
-
72
- ```js
73
- import { parse, deparse } from 'pgsql-parser';
74
-
75
- const stmts = await parse('SELECT * FROM test_table');
76
-
77
- // Assuming the structure of stmts is known and matches the expected type
78
- stmts[0].RawStmt.stmt.SelectStmt.fromClause[0].RangeVar.relname = 'another_table';
79
-
80
- console.log(await deparse(stmts));
81
-
82
- // SELECT * FROM "another_table"
83
- ```
84
-
85
- ## Deparser Example
86
-
87
- The `pgsql-deparser` module serializes ASTs to SQL in pure TypeScript, avoiding the full parser's native dependencies. It's useful when only SQL string conversion from ASTs is needed, and is written in pure TypeScript for easy cross-environment deployment.
88
-
89
- 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`:
90
-
91
- ```ts
92
- import * as t from '@pgsql/utils';
93
- import { RangeVar, SelectStmt } from '@pgsql/types';
94
- import { deparse } from 'pgsql-deparser';
95
-
96
- // This could have been obtained from any JSON or AST, not necessarily @pgsql/utils
97
- const stmt: { SelectStmt: SelectStmt } = t.nodes.selectStmt({
98
- targetList: [
99
- t.nodes.resTarget({
100
- val: t.nodes.columnRef({
101
- fields: [t.nodes.aStar()]
102
- })
103
- })
104
- ],
105
- fromClause: [
106
- t.nodes.rangeVar({
107
- relname: 'some_table',
108
- inh: true,
109
- relpersistence: 'p'
110
- })
111
- ],
112
- limitOption: 'LIMIT_OPTION_DEFAULT',
113
- op: 'SETOP_NONE'
114
- });
115
-
116
- // Modify the AST if needed
117
- (stmt.SelectStmt.fromClause[0] as {RangeVar: RangeVar}).RangeVar.relname = 'another_table';
118
-
119
- // Deparse the modified AST back to a SQL string
120
- console.log(await deparse(stmt));
121
-
122
- // Output: SELECT * FROM another_table
123
- ```
124
-
125
- ## Credits
126
-
127
- Built on the excellent work of several contributors:
128
-
129
- * **[Dan Lynch](https://github.com/pyramation)** — official maintainer since 2018 and architect of the current implementation
130
- * **[Lukas Fittl](https://github.com/lfittl)** for [libpg_query](https://github.com/pganalyze/libpg_query) — the core PostgreSQL parser that powers this project
131
- * **[Greg Richardson](https://github.com/gregnr)** for AST guidance and pushing the transition to WASM and multiple PG runtimes for better interoperability
132
- * **[Ethan Resnick](https://github.com/ethanresnick)** for the original Node.js N-API bindings
133
- * **[Zac McCormick](https://github.com/zhm)** for the foundational [node-pg-query-native](https://github.com/zhm/node-pg-query-native) parser
134
-
135
- ## Related
136
-
137
- * [pgsql-parser](https://www.npmjs.com/package/pgsql-parser): The real PostgreSQL parser for Node.js, providing symmetric parsing and deparsing of SQL statements with actual PostgreSQL parser integration.
138
- * [pgsql-deparser](https://www.npmjs.com/package/pgsql-deparser): A streamlined tool designed for converting PostgreSQL ASTs back into SQL queries, focusing solely on deparser functionality to complement `pgsql-parser`.
139
- * [@pgsql/parser](https://www.npmjs.com/package/@pgsql/parser): Multi-version PostgreSQL parser with dynamic version selection at runtime, supporting PostgreSQL 15, 16, and 17 in a single package.
140
- * [@pgsql/types](https://www.npmjs.com/package/@pgsql/types): Offers TypeScript type definitions for PostgreSQL AST nodes, facilitating type-safe construction, analysis, and manipulation of ASTs.
141
- * [@pgsql/enums](https://www.npmjs.com/package/@pgsql/enums): Provides TypeScript enum definitions for PostgreSQL constants, enabling type-safe usage of PostgreSQL enums and constants in your applications.
142
- * [@pgsql/utils](https://www.npmjs.com/package/@pgsql/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.
143
- * [pg-proto-parser](https://www.npmjs.com/package/pg-proto-parser): A TypeScript tool that parses PostgreSQL Protocol Buffers definitions to generate TypeScript interfaces, utility functions, and JSON mappings for enums.
144
- * [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.
145
-
146
- ## Disclaimer
147
-
148
- AS DESCRIBED IN THE LICENSES, THE SOFTWARE IS PROVIDED "AS IS", AT YOUR OWN RISK, AND WITHOUT WARRANTIES OF ANY KIND.
149
-
150
- 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.
package/dist/package.json DELETED
@@ -1,47 +0,0 @@
1
- {
2
- "name": "pgsql-parser",
3
- "version": "14.0.0",
4
- "author": "Dan Lynch <pyramation@gmail.com>",
5
- "description": "The real PostgreSQL query parser",
6
- "main": "index.js",
7
- "module": "esm/index.js",
8
- "types": "index.d.ts",
9
- "homepage": "https://github.com/launchql/pgsql-parser",
10
- "license": "MIT",
11
- "publishConfig": {
12
- "access": "public",
13
- "directory": "dist"
14
- },
15
- "repository": {
16
- "type": "git",
17
- "url": "https://github.com/launchql/pgsql-parser"
18
- },
19
- "bugs": {
20
- "url": "https://github.com/launchql/pgsql-parser/issues"
21
- },
22
- "scripts": {
23
- "copy": "copyfiles -f ../../../../LICENSE README.md package.json dist",
24
- "clean": "rimraf dist",
25
- "prepare": "npm run build",
26
- "build": "npm run clean && tsc && tsc -p tsconfig.esm.json && npm run copy",
27
- "build:dev": "npm run clean && tsc --declarationMap && tsc -p tsconfig.esm.json && npm run copy",
28
- "lint": "eslint . --fix",
29
- "test": "jest",
30
- "test:watch": "jest --watch",
31
- "publish:pkg": "npm publish --tag pg14"
32
- },
33
- "keywords": [
34
- "sql",
35
- "postgres",
36
- "postgresql",
37
- "pg",
38
- "parser",
39
- "query",
40
- "database"
41
- ],
42
- "dependencies": {
43
- "@pgsql/types": "14.1.1",
44
- "libpg-query": "14.2.5",
45
- "pgsql-deparser": "14.0.0"
46
- }
47
- }
package/src/index.ts DELETED
@@ -1,12 +0,0 @@
1
- export {
2
- parse as parse,
3
- parseSync as parseSync,
4
- loadModule as loadModule
5
- } from 'libpg-query';
6
-
7
- export {
8
- deparse,
9
- deparseSync,
10
- } from 'pgsql-deparser';
11
-
12
- export * from '@pgsql/types';
package/tsconfig.esm.json DELETED
@@ -1,9 +0,0 @@
1
- {
2
- "extends": "./tsconfig.json",
3
- "compilerOptions": {
4
- "outDir": "dist/esm",
5
- "module": "es2022",
6
- "rootDir": "src/",
7
- "declaration": false
8
- }
9
- }
package/tsconfig.json DELETED
@@ -1,26 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "outDir": "dist",
4
- "rootDir": "src/",
5
- "target": "es2022",
6
- "module": "commonjs",
7
- "esModuleInterop": true,
8
- "forceConsistentCasingInFileNames": true,
9
- "strict": true,
10
- "strictNullChecks": false,
11
- "skipLibCheck": true,
12
- "sourceMap": false,
13
- "declaration": true,
14
- "resolveJsonModule": true,
15
- "moduleResolution": "node"
16
- },
17
- "include": [
18
- "src/**/*.ts"
19
- ],
20
- "exclude": [
21
- "dist",
22
- "node_modules",
23
- "**/*.spec.*",
24
- "**/*.test.*"
25
- ]
26
- }
File without changes
File without changes
File without changes
File without changes