pgsql-deparser 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 +27 -11
- package/package.json +5 -6
package/README.md
CHANGED
|
@@ -30,25 +30,41 @@ npm install pgsql-deparser
|
|
|
30
30
|
|
|
31
31
|
## Deparser Example
|
|
32
32
|
|
|
33
|
-
The deparser
|
|
33
|
+
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.
|
|
34
34
|
|
|
35
|
-
Here's how you can use the deparser in your TypeScript code
|
|
35
|
+
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`:
|
|
36
36
|
|
|
37
37
|
```ts
|
|
38
|
+
import ast, { SelectStmt } from '@pgsql/utils';
|
|
38
39
|
import { deparse } from 'pgsql-deparser';
|
|
39
40
|
|
|
40
|
-
//
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
41
|
+
// This could have been obtained from any JSON or AST, not necessarily @pgsql/utils
|
|
42
|
+
const stmt: SelectStmt = ast.selectStmt({
|
|
43
|
+
targetList: [
|
|
44
|
+
ast.resTarget({
|
|
45
|
+
val: ast.columnRef({
|
|
46
|
+
fields: [ast.aStar()]
|
|
47
|
+
})
|
|
48
|
+
})
|
|
49
|
+
],
|
|
50
|
+
fromClause: [
|
|
51
|
+
ast.rangeVar({
|
|
52
|
+
relname: 'some_table',
|
|
53
|
+
inh: true,
|
|
54
|
+
relpersistence: 'p'
|
|
55
|
+
})
|
|
56
|
+
],
|
|
57
|
+
limitOption: 'LIMIT_OPTION_DEFAULT',
|
|
58
|
+
op: 'SETOP_NONE'
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
// Modify the AST if needed
|
|
62
|
+
stmt.SelectStmt.fromClause[0].RangeVar.relname = 'another_table';
|
|
46
63
|
|
|
47
64
|
// Deparse the modified AST back to a SQL string
|
|
48
65
|
console.log(deparse(stmts));
|
|
49
66
|
|
|
50
|
-
// Output: SELECT * FROM
|
|
51
|
-
|
|
67
|
+
// Output: SELECT * FROM another_table
|
|
52
68
|
```
|
|
53
69
|
|
|
54
70
|
## Why Use `pgsql-deparser`?
|
|
@@ -73,7 +89,7 @@ Our latest is built with `13-latest` branch from libpg_query
|
|
|
73
89
|
|
|
74
90
|
* [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.
|
|
75
91
|
* [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`.
|
|
76
|
-
* [pgsql-enums](https://github.com/launchql/pgsql-parser/tree/main/packages/enums
|
|
92
|
+
* [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`
|
|
77
93
|
* [@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.
|
|
78
94
|
* [@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.
|
|
79
95
|
* [@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-deparser",
|
|
3
|
-
"version": "13.
|
|
3
|
+
"version": "13.15.0",
|
|
4
4
|
"description": "PostgreSQL AST Deparser",
|
|
5
5
|
"author": "Dan Lynch <pyramation@gmail.com>",
|
|
6
6
|
"homepage": "https://github.com/launchql/pgsql-parser",
|
|
@@ -74,7 +74,7 @@
|
|
|
74
74
|
"esprima": "4.0.1",
|
|
75
75
|
"glob": "8.0.3",
|
|
76
76
|
"jest": "^29.7.0",
|
|
77
|
-
"pgsql-parser": "^13.
|
|
77
|
+
"pgsql-parser": "^13.16.0",
|
|
78
78
|
"prettier": "^2.8.7",
|
|
79
79
|
"rimraf": "5.0.5",
|
|
80
80
|
"ts-jest": "^29.1.0",
|
|
@@ -82,9 +82,8 @@
|
|
|
82
82
|
"typescript": "^5.0.4"
|
|
83
83
|
},
|
|
84
84
|
"dependencies": {
|
|
85
|
-
"@pgsql/types": "^13.
|
|
85
|
+
"@pgsql/types": "^13.9.0",
|
|
86
86
|
"dotty": "^0.1.0",
|
|
87
|
-
"pgsql-enums": "^13.
|
|
88
|
-
}
|
|
89
|
-
"gitHead": "453a53729df906c6eb5a095dc0fa985babab4d51"
|
|
87
|
+
"pgsql-enums": "^13.10.0"
|
|
88
|
+
}
|
|
90
89
|
}
|