@@ -108,6 +108,75 @@ const options = {
108108const sql = deparse (parseResult , options );
109109```
110110
111+ ### Pretty Formatting Options
112+
113+ The deparser supports pretty formatting to make SQL output more readable with proper indentation and line breaks:
114+
115+ ``` typescript
116+ const options = {
117+ pretty: true , // Enable pretty formatting (default: false)
118+ newline: ' \n ' , // Newline character (default: '\n')
119+ tab: ' ' , // Tab/indentation character (default: ' ')
120+ functionDelimiter: ' $$' , // Function body delimiter (default: '$$')
121+ functionDelimiterFallback: ' $EOFCODE$' // Fallback delimiter (default: '$EOFCODE$')
122+ };
123+
124+ const sql = deparse (parseResult , options );
125+ ```
126+
127+ | Option | Type | Default | Description |
128+ | --------| ------| ---------| -------------|
129+ | ` pretty ` | ` boolean ` | ` false ` | Enable pretty formatting with indentation and line breaks |
130+ | ` newline ` | ` string ` | ` '\n' ` | Character(s) used for line breaks |
131+ | ` tab ` | ` string ` | ` ' ' ` | Character(s) used for indentation (2 spaces by default) |
132+ | ` functionDelimiter ` | ` string ` | ` '$$' ` | Delimiter used for function bodies |
133+ | ` functionDelimiterFallback ` | ` string ` | ` '$EOFCODE$' ` | Alternative delimiter when default is found in function body |
134+
135+ #### Pretty Formatting Examples
136+
137+ ** Basic SELECT with pretty formatting:**
138+ ``` typescript
139+ // Without pretty formatting
140+ const sql1 = deparse (selectAst , { pretty: false });
141+ // Output: "SELECT id, name, email FROM users WHERE active = true;"
142+
143+ // With pretty formatting
144+ const sql2 = deparse (selectAst , { pretty: true });
145+ // Output:
146+ // SELECT
147+ // id,
148+ // name,
149+ // email
150+ // FROM users
151+ // WHERE
152+ // active = true;
153+ ```
154+
155+ ** Custom formatting characters:**
156+ ``` typescript
157+ const options = {
158+ pretty: true ,
159+ newline: ' \r\n ' , // Windows line endings
160+ tab: ' ' // 4-space indentation
161+ };
162+
163+ const sql = deparse (parseResult , options );
164+ ```
165+
166+ ** Supported Statements:**
167+ Pretty formatting is supported for:
168+ - ` SELECT ` statements with proper clause alignment
169+ - ` CREATE TABLE ` statements with column definitions
170+ - ` CREATE POLICY ` statements with clause formatting
171+ - Common Table Expressions (CTEs)
172+ - Constraint definitions
173+ - JOIN operations with proper alignment
174+
175+ ** Important Notes:**
176+ - Pretty formatting preserves SQL semantics - the formatted SQL parses to the same AST
177+ - Multi-line string literals are preserved without indentation to maintain their content
178+ - Complex expressions maintain proper parentheses and operator precedence
179+
111180## Instance Usage
112181
113182You can also create a deparser instance:
@@ -185,4 +254,4 @@ const customSelect = {
185254
186255const sql = deparse (customSelect );
187256// Output: "SELECT * FROM users"
188- ```
257+ ```
0 commit comments