pgsql-parser 13.13.0 → 13.15.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 +26 -10
- package/package.json +4 -4
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
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pgsql-parser",
|
|
3
|
-
"version": "13.
|
|
3
|
+
"version": "13.15.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,8 @@
|
|
|
86
86
|
"dependencies": {
|
|
87
87
|
"libpg-query": "13.3.2",
|
|
88
88
|
"minimist": "^1.2.6",
|
|
89
|
-
"pgsql-deparser": "^13.
|
|
90
|
-
"pgsql-enums": "^13.
|
|
89
|
+
"pgsql-deparser": "^13.14.0",
|
|
90
|
+
"pgsql-enums": "^13.9.0"
|
|
91
91
|
},
|
|
92
|
-
"gitHead": "
|
|
92
|
+
"gitHead": "1358b34422c45c2111dc0b1764155a720ab7fd73"
|
|
93
93
|
}
|