Skip to content

Commit e299321

Browse files
committed
Add pretty print options to deparser README.md
- Add concise Options section with table of main options - Include pretty formatting example showing before/after - Reference full documentation in DEPARSER_USAGE.md - Complete user-facing documentation for pretty print feature Co-Authored-By: Dan Lynch <[email protected]>
1 parent 5aa3cb4 commit e299321

File tree

1 file changed

+43
-1
lines changed

1 file changed

+43
-1
lines changed

packages/deparser/README.md

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,48 @@ console.log(deparse(stmt));
6969
// Output: SELECT * FROM another_table
7070
```
7171

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+
72114
## Why Use `pgsql-deparser`?
73115

74116
`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:
98140

99141
AS DESCRIBED IN THE LICENSES, THE SOFTWARE IS PROVIDED "AS IS", AT YOUR OWN RISK, AND WITHOUT WARRANTIES OF ANY KIND.
100142

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.

0 commit comments

Comments
 (0)