pgsql-parser 13.14.0 → 13.16.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/README.md +27 -11
- package/package.json +4 -5
package/README.md
CHANGED
|
@@ -47,25 +47,41 @@ console.log(deparse(stmts));
|
|
|
47
47
|
|
|
48
48
|
## Deparser Example
|
|
49
49
|
|
|
50
|
-
The deparser
|
|
50
|
+
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.
|
|
51
51
|
|
|
52
|
-
Here's how you can use the deparser in your TypeScript code
|
|
52
|
+
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
53
|
|
|
54
54
|
```ts
|
|
55
|
+
import ast, { SelectStmt } from '@pgsql/utils';
|
|
55
56
|
import { deparse } from 'pgsql-deparser';
|
|
56
57
|
|
|
57
|
-
//
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
58
|
+
// This could have been obtained from any JSON or AST, not necessarily @pgsql/utils
|
|
59
|
+
const stmt: SelectStmt = ast.selectStmt({
|
|
60
|
+
targetList: [
|
|
61
|
+
ast.resTarget({
|
|
62
|
+
val: ast.columnRef({
|
|
63
|
+
fields: [ast.aStar()]
|
|
64
|
+
})
|
|
65
|
+
})
|
|
66
|
+
],
|
|
67
|
+
fromClause: [
|
|
68
|
+
ast.rangeVar({
|
|
69
|
+
relname: 'some_table',
|
|
70
|
+
inh: true,
|
|
71
|
+
relpersistence: 'p'
|
|
72
|
+
})
|
|
73
|
+
],
|
|
74
|
+
limitOption: 'LIMIT_OPTION_DEFAULT',
|
|
75
|
+
op: 'SETOP_NONE'
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
// Modify the AST if needed
|
|
79
|
+
stmt.SelectStmt.fromClause[0].RangeVar.relname = 'another_table';
|
|
63
80
|
|
|
64
81
|
// Deparse the modified AST back to a SQL string
|
|
65
82
|
console.log(deparse(stmts));
|
|
66
83
|
|
|
67
|
-
// Output: SELECT * FROM
|
|
68
|
-
|
|
84
|
+
// Output: SELECT * FROM another_table
|
|
69
85
|
```
|
|
70
86
|
|
|
71
87
|
## CLI
|
|
@@ -134,7 +150,7 @@ Our latest is built with `13-latest` branch from libpg_query
|
|
|
134
150
|
|
|
135
151
|
* [pgsql-parser](https://github.com/launchql/pgsql-parser): The real PostgreSQL parser for Node.js, providing symmetric parsing and deparsing of SQL statements with actual PostgreSQL parser integration.
|
|
136
152
|
* [pgsql-deparser](https://github.com/launchql/pgsql-parser/tree/main/packages/deparser): A streamlined tool designed for converting PostgreSQL ASTs back into SQL queries, focusing solely on deparser functionality to complement `pgsql-parser`.
|
|
137
|
-
* [pgsql-enums](https://github.com/launchql/pgsql-parser/tree/main/packages/enums
|
|
153
|
+
* [pgsql-enums](https://github.com/launchql/pgsql-parser/tree/main/packages/pgsql-enums): A utility package offering easy access to PostgreSQL enumeration types in JSON format, aiding in string and integer conversions of enums used within ASTs to compliment `pgsql-parser`
|
|
138
154
|
* [@pgsql/enums](https://github.com/launchql/pgsql-parser/tree/main/packages/enums): Provides PostgreSQL AST enums in TypeScript, enhancing type safety and usability in projects interacting with PostgreSQL AST nodes.
|
|
139
155
|
* [@pgsql/types](https://github.com/launchql/pgsql-parser/tree/main/packages/types): Offers TypeScript type definitions for PostgreSQL AST nodes, facilitating type-safe construction, analysis, and manipulation of ASTs.
|
|
140
156
|
* [@pgsql/utils](https://github.com/launchql/pgsql-parser/tree/main/packages/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.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pgsql-parser",
|
|
3
|
-
"version": "13.
|
|
3
|
+
"version": "13.16.0",
|
|
4
4
|
"description": "The real PostgreSQL query parser",
|
|
5
5
|
"author": "Dan Lynch <pyramation@gmail.com>",
|
|
6
6
|
"homepage": "https://github.com/launchql/pgsql-parser",
|
|
@@ -86,8 +86,7 @@
|
|
|
86
86
|
"dependencies": {
|
|
87
87
|
"libpg-query": "13.3.2",
|
|
88
88
|
"minimist": "^1.2.6",
|
|
89
|
-
"pgsql-deparser": "^13.
|
|
90
|
-
"pgsql-enums": "^13.
|
|
91
|
-
}
|
|
92
|
-
"gitHead": "453a53729df906c6eb5a095dc0fa985babab4d51"
|
|
89
|
+
"pgsql-deparser": "^13.15.0",
|
|
90
|
+
"pgsql-enums": "^13.10.0"
|
|
91
|
+
}
|
|
93
92
|
}
|