pgsql-deparser 17.6.2 → 17.7.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 CHANGED
@@ -14,7 +14,7 @@
14
14
  <a href="https://www.npmjs.com/package/pgsql-deparser"><img height="20" src="https://img.shields.io/github/package-json/v/launchql/pgsql-parser?filename=packages%2Fdeparser%2Fpackage.json"/></a>
15
15
  </p>
16
16
 
17
- `pgsql-deparser` is a streamlined tool designed to convert PostgreSQL Abstract Syntax Trees (AST) back into SQL queries. It is a companion module to [`pgsql-parser`](https://github.com/launchql/pgsql-parser), which is capable of both parsing SQL queries into ASTs and deparsing these ASTs back into SQL. However, unlike `pgsql-parser`, which incorporates the full PostgreSQL parser, `pgsql-deparser` focuses solely on the deparser functionality. This makes it an excellent choice for scenarios where only AST-to-SQL conversion is needed, avoiding the extra overhead associated with the full parsing capabilities.
17
+ `pgsql-deparser` is the lightning-fast, pure TypeScript solution for converting PostgreSQL ASTs back into SQL queries. Perfect companion to [`pgsql-parser`](https://github.com/launchql/pgsql-parser), this focused tool delivers SQL generation without any native dependencies or WebAssembly overhead.
18
18
 
19
19
  ## Installation
20
20
 
@@ -22,11 +22,12 @@
22
22
  npm install pgsql-deparser
23
23
  ```
24
24
 
25
- ## Key Features
25
+ ## Features
26
26
 
27
- - **Lightweight and Pure TypeScript**: Built entirely in TypeScript, `pgsql-deparser` is lightweight and doesn't rely on native dependencies, facilitating easier integration and deployment across various environments.
28
- - **Focused Functionality**: By concentrating on decompiling ASTs to SQL, `pgsql-deparser` offers a specialized, efficient solution for those who need to generate SQL statements from ASTs without the full parsing mechanism.
29
- - **Compatibility**: Ideal for use cases where the AST is already obtained from another source or process, allowing for seamless SQL generation from AST representations.
27
+ * **Pure TypeScript Performance** Zero dependencies, no WASM, no compilation - just blazing fast SQL generation
28
+ * 🪶 **Ultra Lightweight** Minimal footprint with laser-focused functionality for AST-to-SQL conversion only
29
+ * 🧪 **Battle-Tested Reliability** Validated against 23,000+ SQL statements ensuring production-grade stability
30
+ * 🌍 **Universal Compatibility** – Runs anywhere JavaScript does - browsers, Node.js, edge functions, you name it
30
31
 
31
32
  ## Deparser Example
32
33
 
@@ -35,20 +36,21 @@ The `pgsql-deparser` module serializes ASTs to SQL in pure TypeScript, avoiding
35
36
  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
37
 
37
38
  ```ts
38
- import ast, { SelectStmt } from '@pgsql/utils';
39
- import { deparse } from 'pgsql-deparser';
39
+ import * as t from '@pgsql/utils';
40
+ import { RangeVar, SelectStmt } from '@pgsql/types';
41
+ import { deparseSync as deparse } from 'pgsql-deparser';
40
42
 
41
43
  // This could have been obtained from any JSON or AST, not necessarily @pgsql/utils
42
- const stmt: SelectStmt = ast.selectStmt({
44
+ const stmt: { SelectStmt: SelectStmt } = t.nodes.selectStmt({
43
45
  targetList: [
44
- ast.resTarget({
45
- val: ast.columnRef({
46
- fields: [ast.aStar()]
46
+ t.nodes.resTarget({
47
+ val: t.nodes.columnRef({
48
+ fields: [t.nodes.aStar()]
47
49
  })
48
50
  })
49
51
  ],
50
52
  fromClause: [
51
- ast.rangeVar({
53
+ t.nodes.rangeVar({
52
54
  relname: 'some_table',
53
55
  inh: true,
54
56
  relpersistence: 'p'
@@ -58,11 +60,11 @@ const stmt: SelectStmt = ast.selectStmt({
58
60
  op: 'SETOP_NONE'
59
61
  });
60
62
 
61
- // Modify the AST if needed
62
- stmt.SelectStmt.fromClause[0].RangeVar.relname = 'another_table';
63
+ // Modify the AST if needed
64
+ (stmt.SelectStmt.fromClause[0] as {RangeVar: RangeVar}).RangeVar.relname = 'another_table';
63
65
 
64
66
  // Deparse the modified AST back to a SQL string
65
- console.log(deparse(stmts));
67
+ console.log(deparse(stmt));
66
68
 
67
69
  // Output: SELECT * FROM another_table
68
70
  ```
@@ -71,47 +73,29 @@ console.log(deparse(stmts));
71
73
 
72
74
  `pgsql-deparser` is particularly useful in development environments where native dependencies are problematic or in applications where only the deparser functionality is required. Its independence from the full `pgsql-parser` package allows for more focused and lightweight SQL generation tasks.
73
75
 
74
- ## Versions
75
-
76
- As of PG 13, PG majors versions maintained will have a matching dedicated major npm version. Only the latest Postgres stable release receives active updates.
77
-
78
- Our latest is built with `13-latest` branch from libpg_query
76
+ ## Credits
79
77
 
80
- | PostgreSQL Major Version | libpg_query | Status | npm
81
- |--------------------------|-------------|---------------------|---------|
82
- | 13 | 13-latest | Active development | `latest`
83
- | 12 | (n/a) | Not supported |
84
- | 11 | (n/a) | Not supported |
85
- | 10 | 10-latest | Not supported | `@1.3.1` ([tree](https://github.com/launchql/pgsql-parser/tree/39b7b1adc8914253226e286a48105785219a81ca)) |
78
+ Built on the excellent work of several contributors:
86
79
 
80
+ * **[Dan Lynch](https://github.com/pyramation)** — official maintainer since 2018 and architect of the current implementation
81
+ * **[Lukas Fittl](https://github.com/lfittl)** for [libpg_query](https://github.com/pganalyze/libpg_query) — the core PostgreSQL parser that powers this project
82
+ * **[Greg Richardson](https://github.com/gregnr)** for AST guidance and pushing the transition to WASM and multiple PG runtimes for better interoperability
83
+ * **[Ethan Resnick](https://github.com/ethanresnick)** for the original Node.js N-API bindings
84
+ * **[Zac McCormick](https://github.com/zhm)** for the foundational [node-pg-query-native](https://github.com/zhm/node-pg-query-native) parser
87
85
 
88
86
  ## Related
89
87
 
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.
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`.
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`
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.
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.
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.
96
- * [pg-proto-parser](https://github.com/launchql/pg-proto-parser): A TypeScript tool that parses PostgreSQL Protocol Buffers definitions to generate TypeScript interfaces, utility functions, and JSON mappings for enums.
88
+ * [pgsql-parser](https://www.npmjs.com/package/pgsql-parser): The real PostgreSQL parser for Node.js, providing symmetric parsing and deparsing of SQL statements with actual PostgreSQL parser integration.
89
+ * [pgsql-deparser](https://www.npmjs.com/package/pgsql-deparser): A streamlined tool designed for converting PostgreSQL ASTs back into SQL queries, focusing solely on deparser functionality to complement `pgsql-parser`.
90
+ * [@pgsql/parser](https://www.npmjs.com/package/@pgsql/parser): Multi-version PostgreSQL parser with dynamic version selection at runtime, supporting PostgreSQL 15, 16, and 17 in a single package.
91
+ * [@pgsql/types](https://www.npmjs.com/package/@pgsql/types): Offers TypeScript type definitions for PostgreSQL AST nodes, facilitating type-safe construction, analysis, and manipulation of ASTs.
92
+ * [@pgsql/enums](https://www.npmjs.com/package/@pgsql/enums): Provides TypeScript enum definitions for PostgreSQL constants, enabling type-safe usage of PostgreSQL enums and constants in your applications.
93
+ * [@pgsql/utils](https://www.npmjs.com/package/@pgsql/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.
94
+ * [pg-proto-parser](https://www.npmjs.com/package/pg-proto-parser): A TypeScript tool that parses PostgreSQL Protocol Buffers definitions to generate TypeScript interfaces, utility functions, and JSON mappings for enums.
97
95
  * [libpg-query](https://github.com/launchql/libpg-query-node): The real PostgreSQL parser exposed for Node.js, used primarily in `pgsql-parser` for parsing and deparsing SQL queries.
98
96
 
99
- Thanks [@lfittl](https://github.com/lfittl) for building the core `libpg_query` suite:
100
-
101
- * [libpg_query](https://github.com/pganalyze/libpg_query)
102
- * [pg_query](https://github.com/lfittl/pg_query)
103
- * [pg_query.go](https://github.com/lfittl/pg_query.go)
104
-
105
- ## Credits
106
-
107
- Thanks to [@zhm](https://github.com/zhm) for the OG parser that started it all:
108
-
109
- * [pg-query-parser](https://github.com/zhm/pg-query-parser)
110
- * [pg-query-native](https://github.com/zhm/node-pg-query-native)
111
- * [Original LICENSE](https://github.com/zhm/pg-query-parser/blob/master/LICENSE.md)
112
-
113
97
  ## Disclaimer
114
98
 
115
- AS DESCRIBED IN THE LICENSES, THE SOFTWARE IS PROVIDED AS IS”, AT YOUR OWN RISK, AND WITHOUT WARRANTIES OF ANY KIND.
99
+ AS DESCRIBED IN THE LICENSES, THE SOFTWARE IS PROVIDED "AS IS", AT YOUR OWN RISK, AND WITHOUT WARRANTIES OF ANY KIND.
116
100
 
117
101
  No developer or entity involved in creating Software will be liable for any claims or damages whatsoever associated with your use, inability to use, or your interaction with other users of the Software code or Software CLI, including any direct, indirect, incidental, special, exemplary, punitive or consequential damages, or loss of profits, cryptocurrencies, tokens, or anything else of value.
package/esm/index.js CHANGED
@@ -1,3 +1,9 @@
1
1
  import { Deparser } from "./deparser";
2
- const deparse = Deparser.deparse;
3
- export { deparse, Deparser };
2
+ const deparseMethod = Deparser.deparse;
3
+ // Export the original sync version as deparseSync
4
+ export const deparseSync = deparseMethod;
5
+ // Create an async wrapper for deparse
6
+ export const deparse = async (...args) => {
7
+ return deparseMethod(...args);
8
+ };
9
+ export { Deparser };
package/index.d.ts CHANGED
@@ -1,3 +1,5 @@
1
1
  import { Deparser, DeparserOptions } from "./deparser";
2
- declare const deparse: typeof Deparser.deparse;
3
- export { deparse, Deparser, DeparserOptions };
2
+ declare const deparseMethod: typeof Deparser.deparse;
3
+ export declare const deparseSync: typeof Deparser.deparse;
4
+ export declare const deparse: (...args: Parameters<typeof deparseMethod>) => Promise<ReturnType<typeof deparseMethod>>;
5
+ export { Deparser, DeparserOptions };
package/index.js CHANGED
@@ -1,7 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Deparser = exports.deparse = void 0;
3
+ exports.Deparser = exports.deparse = exports.deparseSync = void 0;
4
4
  const deparser_1 = require("./deparser");
5
5
  Object.defineProperty(exports, "Deparser", { enumerable: true, get: function () { return deparser_1.Deparser; } });
6
- const deparse = deparser_1.Deparser.deparse;
6
+ const deparseMethod = deparser_1.Deparser.deparse;
7
+ // Export the original sync version as deparseSync
8
+ exports.deparseSync = deparseMethod;
9
+ // Create an async wrapper for deparse
10
+ const deparse = async (...args) => {
11
+ return deparseMethod(...args);
12
+ };
7
13
  exports.deparse = deparse;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pgsql-deparser",
3
- "version": "17.6.2",
3
+ "version": "17.7.0",
4
4
  "author": "Dan Lynch <pyramation@gmail.com>",
5
5
  "description": "PostgreSQL AST Deparser",
6
6
  "main": "index.js",
@@ -46,10 +46,10 @@
46
46
  "database"
47
47
  ],
48
48
  "devDependencies": {
49
- "libpg-query": "17.3.3"
49
+ "libpg-query": "17.5.2"
50
50
  },
51
51
  "dependencies": {
52
- "@pgsql/types": "^17.5.2"
52
+ "@pgsql/types": "^17.6.1"
53
53
  },
54
- "gitHead": "dfffa6417d453373e59e6e57449ee813fb547403"
54
+ "gitHead": "e0f9b0579328f4206c315d499e0e2045d3b8f845"
55
55
  }