pgsql-parser 13.14.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 +26 -10
  2. package/package.json +3 -3
package/README.md CHANGED
@@ -47,25 +47,41 @@ console.log(deparse(stmts));
47
47
 
48
48
  ## Deparser Example
49
49
 
50
- 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.
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
- // Assuming `stmts` is an AST object for the query 'SELECT * FROM test_table'
58
- // This could have been obtained from any source, not necessarily the pgsql-parser
59
- const stmts = getAstFromSomewhere();
60
-
61
- // Modify the AST as needed
62
- stmts[0].RawStmt.stmt.SelectStmt.fromClause[0].RangeVar.relname = 'another_table';
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 "another_table"
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.14.0",
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.13.0",
89
+ "pgsql-deparser": "^13.14.0",
90
90
  "pgsql-enums": "^13.9.0"
91
91
  },
92
- "gitHead": "453a53729df906c6eb5a095dc0fa985babab4d51"
92
+ "gitHead": "1358b34422c45c2111dc0b1764155a720ab7fd73"
93
93
  }