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.
Files changed (2) hide show
  1. package/README.md +27 -11
  2. 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 functionality is provided as a standalone module, enabling you to serialize AST (Abstract Syntax Tree) objects back to SQL statements without the need for the full parsing engine. This separation is particularly beneficial for environments where the native dependencies of the full parser are problematic or unnecessary. For instance, if you already have an AST representation of your SQL query and merely need to convert it back to a SQL string, you can use the pgsql-deparser module directly. This module is implemented in pure TypeScript, avoiding the need for native bindings and thereby simplifying deployment and compatibility across different environments.
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
- // Assuming `stmts` is an AST object for the query 'SELECT * FROM test_table'
41
- // This could have been obtained from any source, not necessarily the pgsql-parser
42
- const stmts = getAstFromSomewhere();
43
-
44
- // Modify the AST as needed
45
- stmts[0].RawStmt.stmt.SelectStmt.fromClause[0].RangeVar.relname = 'another_table';
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 "another_table"
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-json): 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`
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.13.0",
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.14.0",
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.8.0",
85
+ "@pgsql/types": "^13.9.0",
86
86
  "dotty": "^0.1.0",
87
- "pgsql-enums": "^13.9.0"
88
- },
89
- "gitHead": "453a53729df906c6eb5a095dc0fa985babab4d51"
87
+ "pgsql-enums": "^13.10.0"
88
+ }
90
89
  }