pgsql-deparser 17.7.2 → 17.8.1
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 +44 -2
- package/deparser.d.ts +2 -0
- package/deparser.js +363 -86
- package/esm/deparser.js +363 -86
- package/esm/utils/sql-formatter.js +11 -2
- package/package.json +2 -2
- package/utils/sql-formatter.d.ts +3 -1
- package/utils/sql-formatter.js +11 -2
package/README.md
CHANGED
|
@@ -24,7 +24,7 @@ npm install pgsql-deparser
|
|
|
24
24
|
|
|
25
25
|
## Features
|
|
26
26
|
|
|
27
|
-
* ⚡ **Pure TypeScript Performance** – Zero dependencies, no WASM, no compilation - just blazing fast SQL generation
|
|
27
|
+
* ⚡ **Pure TypeScript Performance** – Zero runtime dependencies, no WASM, no compilation - just blazing fast SQL generation
|
|
28
28
|
* 🪶 **Ultra Lightweight** – Minimal footprint with laser-focused functionality for AST-to-SQL conversion only
|
|
29
29
|
* 🧪 **Battle-Tested Reliability** – Validated against 23,000+ SQL statements ensuring production-grade stability
|
|
30
30
|
* 🌍 **Universal Compatibility** – Runs anywhere JavaScript does - browsers, Node.js, edge functions, you name it
|
|
@@ -69,6 +69,48 @@ console.log(deparse(stmt));
|
|
|
69
69
|
// Output: SELECT * FROM another_table
|
|
70
70
|
```
|
|
71
71
|
|
|
72
|
+
## Options
|
|
73
|
+
|
|
74
|
+
The deparser accepts optional configuration for formatting and output control:
|
|
75
|
+
|
|
76
|
+
```ts
|
|
77
|
+
import { deparseSync as deparse } from 'pgsql-deparser';
|
|
78
|
+
|
|
79
|
+
const options = {
|
|
80
|
+
pretty: true, // Enable pretty formatting (default: false)
|
|
81
|
+
newline: '\n', // Newline character (default: '\n')
|
|
82
|
+
tab: ' ', // Tab/indentation character (default: ' ')
|
|
83
|
+
semicolons: true // Add semicolons to statements (default: true)
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
const sql = deparse(ast, options);
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
| Option | Type | Default | Description |
|
|
90
|
+
|--------|------|---------|-------------|
|
|
91
|
+
| `pretty` | `boolean` | `false` | Enable pretty formatting with indentation and line breaks |
|
|
92
|
+
| `newline` | `string` | `'\n'` | Character(s) used for line breaks |
|
|
93
|
+
| `tab` | `string` | `' '` | Character(s) used for indentation |
|
|
94
|
+
| `semicolons` | `boolean` | `true` | Add semicolons to SQL statements |
|
|
95
|
+
|
|
96
|
+
**Pretty formatting example:**
|
|
97
|
+
```ts
|
|
98
|
+
// Without pretty formatting
|
|
99
|
+
const sql1 = deparse(selectAst, { pretty: false });
|
|
100
|
+
// "SELECT id, name FROM users WHERE active = true;"
|
|
101
|
+
|
|
102
|
+
// With pretty formatting
|
|
103
|
+
const sql2 = deparse(selectAst, { pretty: true });
|
|
104
|
+
// SELECT
|
|
105
|
+
// id,
|
|
106
|
+
// name
|
|
107
|
+
// FROM users
|
|
108
|
+
// WHERE
|
|
109
|
+
// active = true;
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
For complete documentation and advanced options, see [DEPARSER_USAGE.md](../../DEPARSER_USAGE.md).
|
|
113
|
+
|
|
72
114
|
## Why Use `pgsql-deparser`?
|
|
73
115
|
|
|
74
116
|
`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.
|
|
@@ -98,4 +140,4 @@ Built on the excellent work of several contributors:
|
|
|
98
140
|
|
|
99
141
|
AS DESCRIBED IN THE LICENSES, THE SOFTWARE IS PROVIDED "AS IS", AT YOUR OWN RISK, AND WITHOUT WARRANTIES OF ANY KIND.
|
|
100
142
|
|
|
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.
|
|
143
|
+
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/deparser.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ export interface DeparserOptions {
|
|
|
6
6
|
tab?: string;
|
|
7
7
|
functionDelimiter?: string;
|
|
8
8
|
functionDelimiterFallback?: string;
|
|
9
|
+
pretty?: boolean;
|
|
9
10
|
}
|
|
10
11
|
/**
|
|
11
12
|
* Deparser - Converts PostgreSQL AST nodes back to SQL strings
|
|
@@ -294,4 +295,5 @@ export declare class Deparser implements DeparserVisitor {
|
|
|
294
295
|
AlterObjectSchemaStmt(node: t.AlterObjectSchemaStmt, context: DeparserContext): string;
|
|
295
296
|
AlterRoleSetStmt(node: t.AlterRoleSetStmt, context: DeparserContext): string;
|
|
296
297
|
CreateForeignTableStmt(node: t.CreateForeignTableStmt, context: DeparserContext): string;
|
|
298
|
+
private containsMultilineStringLiteral;
|
|
297
299
|
}
|