rawsql-ts 0.11.9-beta → 0.11.11-beta
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/dist/esm/index.min.js +10 -10
- package/dist/esm/index.min.js.map +3 -3
- package/dist/esm/src/transformers/SqlFormatter.d.ts +8 -0
- package/dist/esm/src/transformers/SqlFormatter.js.map +1 -1
- package/dist/esm/src/transformers/SqlPrinter.d.ts +62 -14
- package/dist/esm/src/transformers/SqlPrinter.js +153 -67
- package/dist/esm/src/transformers/SqlPrinter.js.map +1 -1
- package/dist/esm/tsconfig.browser.tsbuildinfo +1 -1
- package/dist/index.min.js +10 -10
- package/dist/index.min.js.map +3 -3
- package/dist/src/transformers/SqlFormatter.d.ts +8 -0
- package/dist/src/transformers/SqlFormatter.js.map +1 -1
- package/dist/src/transformers/SqlPrinter.d.ts +62 -14
- package/dist/src/transformers/SqlPrinter.js +153 -67
- package/dist/src/transformers/SqlPrinter.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -3,6 +3,13 @@ import { IndentCharOption, NewlineOption } from './LinePrinter';
|
|
|
3
3
|
import { SqlComponent } from '../models/SqlComponent';
|
|
4
4
|
export declare const VALID_PRESETS: readonly ["mysql", "postgres", "sqlserver", "sqlite"];
|
|
5
5
|
export type PresetName = (typeof VALID_PRESETS)[number];
|
|
6
|
+
/**
|
|
7
|
+
* WithClauseStyle determines how WITH clauses are formatted.
|
|
8
|
+
* - 'standard': Normal formatting with proper indentation
|
|
9
|
+
* - 'cte-oneline': Individual CTEs are formatted as one-liners
|
|
10
|
+
* - 'full-oneline': Entire WITH clause is formatted as one line
|
|
11
|
+
*/
|
|
12
|
+
export type WithClauseStyle = 'standard' | 'cte-oneline' | 'full-oneline';
|
|
6
13
|
/**
|
|
7
14
|
* SqlFormatter class combines parsing and printing of SQL queries into a single interface.
|
|
8
15
|
*/
|
|
@@ -28,6 +35,7 @@ export declare class SqlFormatter {
|
|
|
28
35
|
andBreak?: AndBreakStyle;
|
|
29
36
|
exportComment?: boolean;
|
|
30
37
|
strictCommentPlacement?: boolean;
|
|
38
|
+
withClauseStyle?: WithClauseStyle;
|
|
31
39
|
}); /**
|
|
32
40
|
* Formats a SQL query string with the given parameters.
|
|
33
41
|
* @param sqlText The SQL query string to format.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SqlFormatter.js","sourceRoot":"","sources":["../../../../src/transformers/SqlFormatter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAmB,OAAO,EAAE,MAAM,gCAAgC,CAAC;AAC/F,OAAO,EAAE,UAAU,EAAkC,MAAM,cAAc,CAAC;AAK1E,4CAA4C;AAC5C,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,QAAQ,CAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"SqlFormatter.js","sourceRoot":"","sources":["../../../../src/transformers/SqlFormatter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAmB,OAAO,EAAE,MAAM,gCAAgC,CAAC;AAC/F,OAAO,EAAE,UAAU,EAAkC,MAAM,cAAc,CAAC;AAK1E,4CAA4C;AAC5C,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,QAAQ,CAAU,CAAC;AAWnF;;GAEG;AACH,MAAM,OAAO,YAAY;IAIrB,YAAY,UAcR,EAAE;;QAEF,MAAM,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;QAE1E,IAAI,OAAO,CAAC,MAAM,IAAI,CAAC,YAAY,EAAE,CAAC;YAClC,MAAM,IAAI,KAAK,CAAC,mBAAmB,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,iCAAiC;QAC3F,CAAC;QAED,MAAM,aAAa,mCACZ,YAAY,KACf,gBAAgB,EAAE,MAAA,OAAO,CAAC,gBAAgB,mCAAI,YAAY,aAAZ,YAAY,uBAAZ,YAAY,CAAE,gBAAgB,EAC5E,eAAe,EAAE,MAAA,OAAO,CAAC,eAAe,mCAAI,YAAY,aAAZ,YAAY,uBAAZ,YAAY,CAAE,eAAe,EACzE,cAAc,EAAE,MAAA,OAAO,CAAC,cAAc,mCAAI,YAAY,aAAZ,YAAY,uBAAZ,YAAY,CAAE,cAAc,GACzE,CAAC;QAEF,IAAI,CAAC,MAAM,GAAG,IAAI,mBAAmB,CAAC,aAAa,CAAC,CAAC;QACrD,IAAI,CAAC,OAAO,GAAG,IAAI,UAAU,CAAC,OAAO,CAAC,CAAC;IAC3C,CAAC,CAAI;;;;;OAKF;IACH,MAAM,CAAC,GAAiB;QACpB,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QACjD,MAAM,YAAY,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QAE/C,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,CAAC;IACpC,CAAC;CACJ"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { SqlPrintToken } from "../models/SqlPrintToken";
|
|
1
|
+
import { SqlPrintToken, SqlPrintTokenContainerType } from "../models/SqlPrintToken";
|
|
2
2
|
import { IndentCharOption, NewlineOption } from "./LinePrinter";
|
|
3
|
+
import { WithClauseStyle } from "./SqlFormatter";
|
|
3
4
|
/**
|
|
4
5
|
* CommaBreakStyle determines how commas are placed in formatted SQL output.
|
|
5
6
|
* - 'none': No line break for commas
|
|
@@ -14,8 +15,50 @@ export type CommaBreakStyle = 'none' | 'before' | 'after';
|
|
|
14
15
|
* - 'after': Line break after AND
|
|
15
16
|
*/
|
|
16
17
|
export type AndBreakStyle = 'none' | 'before' | 'after';
|
|
18
|
+
/**
|
|
19
|
+
* Options for configuring SqlPrinter formatting behavior
|
|
20
|
+
*/
|
|
21
|
+
export interface SqlPrinterOptions {
|
|
22
|
+
/** Indent character (e.g., ' ' or '\t') */
|
|
23
|
+
indentChar?: IndentCharOption;
|
|
24
|
+
/** Indent size (number of indentChar repetitions per level) */
|
|
25
|
+
indentSize?: number;
|
|
26
|
+
/** Newline character (e.g., '\n' or '\r\n') */
|
|
27
|
+
newline?: NewlineOption;
|
|
28
|
+
/** Comma break style: 'none', 'before', or 'after' */
|
|
29
|
+
commaBreak?: CommaBreakStyle;
|
|
30
|
+
/** AND break style: 'none', 'before', or 'after' */
|
|
31
|
+
andBreak?: AndBreakStyle;
|
|
32
|
+
/** Keyword case style: 'none', 'upper' | 'lower' */
|
|
33
|
+
keywordCase?: 'none' | 'upper' | 'lower';
|
|
34
|
+
/** Whether to export comments in the output (default: false for compatibility) */
|
|
35
|
+
exportComment?: boolean;
|
|
36
|
+
/** Whether to use strict comment placement (only clause-level comments, default: false) */
|
|
37
|
+
strictCommentPlacement?: boolean;
|
|
38
|
+
/** Container types that should increase indentation level */
|
|
39
|
+
indentIncrementContainerTypes?: SqlPrintTokenContainerType[];
|
|
40
|
+
/** WITH clause formatting style (default: 'standard') */
|
|
41
|
+
withClauseStyle?: WithClauseStyle;
|
|
42
|
+
}
|
|
17
43
|
/**
|
|
18
44
|
* SqlPrinter formats a SqlPrintToken tree into a SQL string with flexible style options.
|
|
45
|
+
*
|
|
46
|
+
* This class provides various formatting options including:
|
|
47
|
+
* - Indentation control (character and size)
|
|
48
|
+
* - Line break styles for commas and AND operators
|
|
49
|
+
* - Keyword case transformation
|
|
50
|
+
* - Comment handling
|
|
51
|
+
* - WITH clause formatting styles
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* const printer = new SqlPrinter({
|
|
55
|
+
* indentChar: ' ',
|
|
56
|
+
* indentSize: 1,
|
|
57
|
+
* keywordCase: 'upper',
|
|
58
|
+
* commaBreak: 'after',
|
|
59
|
+
* withClauseStyle: 'cte-oneline'
|
|
60
|
+
* });
|
|
61
|
+
* const formatted = printer.print(sqlToken);
|
|
19
62
|
*/
|
|
20
63
|
export declare class SqlPrinter {
|
|
21
64
|
/** Indent character (e.g., ' ' or '\\t') */
|
|
@@ -34,27 +77,32 @@ export declare class SqlPrinter {
|
|
|
34
77
|
exportComment: boolean;
|
|
35
78
|
/** Whether to use strict comment placement (only clause-level comments, default: false) */
|
|
36
79
|
strictCommentPlacement: boolean;
|
|
80
|
+
/** WITH clause formatting style (default: 'standard') */
|
|
81
|
+
withClauseStyle: WithClauseStyle;
|
|
37
82
|
private linePrinter;
|
|
38
83
|
private indentIncrementContainers;
|
|
39
84
|
/**
|
|
40
85
|
* @param options Optional style settings for pretty printing
|
|
41
86
|
*/
|
|
42
|
-
constructor(options?:
|
|
43
|
-
indentChar?: IndentCharOption;
|
|
44
|
-
indentSize?: number;
|
|
45
|
-
newline?: NewlineOption;
|
|
46
|
-
commaBreak?: CommaBreakStyle;
|
|
47
|
-
andBreak?: AndBreakStyle;
|
|
48
|
-
keywordCase?: 'none' | 'upper' | 'lower';
|
|
49
|
-
exportComment?: boolean;
|
|
50
|
-
strictCommentPlacement?: boolean;
|
|
51
|
-
indentIncrementContainerTypes?: string[];
|
|
52
|
-
});
|
|
87
|
+
constructor(options?: SqlPrinterOptions);
|
|
53
88
|
/**
|
|
54
89
|
* Converts a SqlPrintToken tree to a formatted SQL string.
|
|
55
|
-
* @param token The root SqlPrintToken
|
|
56
|
-
* @param level
|
|
90
|
+
* @param token The root SqlPrintToken to format
|
|
91
|
+
* @param level Initial indentation level (default: 0)
|
|
92
|
+
* @returns Formatted SQL string
|
|
93
|
+
* @example
|
|
94
|
+
* const printer = new SqlPrinter({ indentChar: ' ', keywordCase: 'upper' });
|
|
95
|
+
* const formatted = printer.print(sqlToken);
|
|
57
96
|
*/
|
|
58
97
|
print(token: SqlPrintToken, level?: number): string;
|
|
59
98
|
private appendToken;
|
|
99
|
+
private shouldSkipToken;
|
|
100
|
+
private applyKeywordCase;
|
|
101
|
+
private handleKeywordToken;
|
|
102
|
+
private handleCommaToken;
|
|
103
|
+
private handleAndOperatorToken;
|
|
104
|
+
private handleJoinClauseToken;
|
|
105
|
+
private handleCommentToken;
|
|
106
|
+
private handleCteOnelineToken;
|
|
107
|
+
private handleWithClauseOnelineToken;
|
|
60
108
|
}
|
|
@@ -2,13 +2,30 @@ import { SqlPrintTokenType, SqlPrintTokenContainerType } from "../models/SqlPrin
|
|
|
2
2
|
import { LinePrinter } from "./LinePrinter";
|
|
3
3
|
/**
|
|
4
4
|
* SqlPrinter formats a SqlPrintToken tree into a SQL string with flexible style options.
|
|
5
|
+
*
|
|
6
|
+
* This class provides various formatting options including:
|
|
7
|
+
* - Indentation control (character and size)
|
|
8
|
+
* - Line break styles for commas and AND operators
|
|
9
|
+
* - Keyword case transformation
|
|
10
|
+
* - Comment handling
|
|
11
|
+
* - WITH clause formatting styles
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* const printer = new SqlPrinter({
|
|
15
|
+
* indentChar: ' ',
|
|
16
|
+
* indentSize: 1,
|
|
17
|
+
* keywordCase: 'upper',
|
|
18
|
+
* commaBreak: 'after',
|
|
19
|
+
* withClauseStyle: 'cte-oneline'
|
|
20
|
+
* });
|
|
21
|
+
* const formatted = printer.print(sqlToken);
|
|
5
22
|
*/
|
|
6
23
|
export class SqlPrinter {
|
|
7
24
|
/**
|
|
8
25
|
* @param options Optional style settings for pretty printing
|
|
9
26
|
*/
|
|
10
27
|
constructor(options) {
|
|
11
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
28
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
12
29
|
this.indentChar = (_a = options === null || options === void 0 ? void 0 : options.indentChar) !== null && _a !== void 0 ? _a : '';
|
|
13
30
|
this.indentSize = (_b = options === null || options === void 0 ? void 0 : options.indentSize) !== null && _b !== void 0 ? _b : 0;
|
|
14
31
|
// The default newline character is set to a blank space (' ') to enable one-liner formatting.
|
|
@@ -19,9 +36,10 @@ export class SqlPrinter {
|
|
|
19
36
|
this.keywordCase = (_f = options === null || options === void 0 ? void 0 : options.keywordCase) !== null && _f !== void 0 ? _f : 'none';
|
|
20
37
|
this.exportComment = (_g = options === null || options === void 0 ? void 0 : options.exportComment) !== null && _g !== void 0 ? _g : false;
|
|
21
38
|
this.strictCommentPlacement = (_h = options === null || options === void 0 ? void 0 : options.strictCommentPlacement) !== null && _h !== void 0 ? _h : false;
|
|
39
|
+
this.withClauseStyle = (_j = options === null || options === void 0 ? void 0 : options.withClauseStyle) !== null && _j !== void 0 ? _j : 'standard';
|
|
22
40
|
this.linePrinter = new LinePrinter(this.indentChar, this.indentSize, this.newline);
|
|
23
41
|
// Initialize
|
|
24
|
-
this.indentIncrementContainers = new Set((
|
|
42
|
+
this.indentIncrementContainers = new Set((_k = options === null || options === void 0 ? void 0 : options.indentIncrementContainerTypes) !== null && _k !== void 0 ? _k : [
|
|
25
43
|
SqlPrintTokenContainerType.SelectClause,
|
|
26
44
|
SqlPrintTokenContainerType.FromClause,
|
|
27
45
|
SqlPrintTokenContainerType.WhereClause,
|
|
@@ -48,8 +66,12 @@ export class SqlPrinter {
|
|
|
48
66
|
}
|
|
49
67
|
/**
|
|
50
68
|
* Converts a SqlPrintToken tree to a formatted SQL string.
|
|
51
|
-
* @param token The root SqlPrintToken
|
|
52
|
-
* @param level
|
|
69
|
+
* @param token The root SqlPrintToken to format
|
|
70
|
+
* @param level Initial indentation level (default: 0)
|
|
71
|
+
* @returns Formatted SQL string
|
|
72
|
+
* @example
|
|
73
|
+
* const printer = new SqlPrinter({ indentChar: ' ', keywordCase: 'upper' });
|
|
74
|
+
* const formatted = printer.print(sqlToken);
|
|
53
75
|
*/
|
|
54
76
|
print(token, level = 0) {
|
|
55
77
|
// initialize
|
|
@@ -60,76 +82,34 @@ export class SqlPrinter {
|
|
|
60
82
|
this.appendToken(token, level);
|
|
61
83
|
return this.linePrinter.print();
|
|
62
84
|
}
|
|
63
|
-
appendToken(token, level) {
|
|
64
|
-
if (
|
|
65
|
-
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
85
|
+
appendToken(token, level, parentContainerType) {
|
|
86
|
+
if (this.shouldSkipToken(token)) {
|
|
87
|
+
return;
|
|
68
88
|
}
|
|
69
89
|
const current = this.linePrinter.getCurrentLine();
|
|
90
|
+
// Handle different token types
|
|
70
91
|
if (token.type === SqlPrintTokenType.keyword) {
|
|
71
|
-
|
|
72
|
-
if (this.keywordCase === 'upper') {
|
|
73
|
-
text = text.toUpperCase();
|
|
74
|
-
}
|
|
75
|
-
else if (this.keywordCase === 'lower') {
|
|
76
|
-
text = text.toLowerCase();
|
|
77
|
-
}
|
|
78
|
-
this.linePrinter.appendText(text);
|
|
92
|
+
this.handleKeywordToken(token, level);
|
|
79
93
|
}
|
|
80
94
|
else if (token.type === SqlPrintTokenType.comma) {
|
|
81
|
-
|
|
82
|
-
if (this.commaBreak === 'before') {
|
|
83
|
-
this.linePrinter.appendNewline(level);
|
|
84
|
-
this.linePrinter.appendText(text);
|
|
85
|
-
}
|
|
86
|
-
else if (this.commaBreak === 'after') {
|
|
87
|
-
this.linePrinter.appendText(text);
|
|
88
|
-
this.linePrinter.appendNewline(level);
|
|
89
|
-
}
|
|
90
|
-
else {
|
|
91
|
-
this.linePrinter.appendText(text);
|
|
92
|
-
}
|
|
95
|
+
this.handleCommaToken(token, level, parentContainerType);
|
|
93
96
|
}
|
|
94
97
|
else if (token.type === SqlPrintTokenType.operator && token.text.toLowerCase() === 'and') {
|
|
95
|
-
|
|
96
|
-
if (this.keywordCase === 'upper') {
|
|
97
|
-
text = text.toUpperCase();
|
|
98
|
-
}
|
|
99
|
-
else if (this.keywordCase === 'lower') {
|
|
100
|
-
text = text.toLowerCase();
|
|
101
|
-
}
|
|
102
|
-
if (this.andBreak === 'before') {
|
|
103
|
-
this.linePrinter.appendNewline(level);
|
|
104
|
-
this.linePrinter.appendText(text);
|
|
105
|
-
}
|
|
106
|
-
else if (this.andBreak === 'after') {
|
|
107
|
-
this.linePrinter.appendText(text);
|
|
108
|
-
this.linePrinter.appendNewline(level);
|
|
109
|
-
}
|
|
110
|
-
else {
|
|
111
|
-
this.linePrinter.appendText(text);
|
|
112
|
-
}
|
|
98
|
+
this.handleAndOperatorToken(token, level);
|
|
113
99
|
}
|
|
114
100
|
else if (token.containerType === "JoinClause") {
|
|
115
|
-
|
|
116
|
-
if (this.keywordCase === 'upper') {
|
|
117
|
-
text = text.toUpperCase();
|
|
118
|
-
}
|
|
119
|
-
else if (this.keywordCase === 'lower') {
|
|
120
|
-
text = text.toLowerCase();
|
|
121
|
-
}
|
|
122
|
-
// before join clause, add newline
|
|
123
|
-
this.linePrinter.appendNewline(level);
|
|
124
|
-
this.linePrinter.appendText(text);
|
|
101
|
+
this.handleJoinClauseToken(token, level);
|
|
125
102
|
}
|
|
126
103
|
else if (token.type === SqlPrintTokenType.comment) {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
104
|
+
this.handleCommentToken(token);
|
|
105
|
+
}
|
|
106
|
+
else if (token.containerType === SqlPrintTokenContainerType.CommonTable && this.withClauseStyle === 'cte-oneline') {
|
|
107
|
+
this.handleCteOnelineToken(token, level);
|
|
108
|
+
return; // Return early to avoid processing innerTokens
|
|
109
|
+
}
|
|
110
|
+
else if (token.containerType === SqlPrintTokenContainerType.WithClause && this.withClauseStyle === 'full-oneline') {
|
|
111
|
+
this.handleWithClauseOnelineToken(token, level);
|
|
112
|
+
return; // Return early to avoid processing innerTokens
|
|
133
113
|
}
|
|
134
114
|
else {
|
|
135
115
|
this.linePrinter.appendText(token.text);
|
|
@@ -138,23 +118,129 @@ export class SqlPrinter {
|
|
|
138
118
|
if (token.keywordTokens && token.keywordTokens.length > 0) {
|
|
139
119
|
for (let i = 0; i < token.keywordTokens.length; i++) {
|
|
140
120
|
const keywordToken = token.keywordTokens[i];
|
|
141
|
-
this.appendToken(keywordToken, level);
|
|
121
|
+
this.appendToken(keywordToken, level, token.containerType);
|
|
142
122
|
}
|
|
143
123
|
}
|
|
144
124
|
let innerLevel = level;
|
|
145
125
|
// indent level up
|
|
146
126
|
if (this.newline !== ' ' && current.text !== '' && this.indentIncrementContainers.has(token.containerType)) { // Changed condition
|
|
147
|
-
|
|
148
|
-
this.
|
|
127
|
+
// Skip newline for WithClause when withClauseStyle is 'full-oneline'
|
|
128
|
+
if (!(token.containerType === SqlPrintTokenContainerType.WithClause && this.withClauseStyle === 'full-oneline')) {
|
|
129
|
+
innerLevel++;
|
|
130
|
+
this.linePrinter.appendNewline(innerLevel);
|
|
131
|
+
}
|
|
149
132
|
}
|
|
150
133
|
for (let i = 0; i < token.innerTokens.length; i++) {
|
|
151
134
|
const child = token.innerTokens[i];
|
|
152
|
-
this.appendToken(child, innerLevel);
|
|
135
|
+
this.appendToken(child, innerLevel, token.containerType);
|
|
153
136
|
}
|
|
154
137
|
// indent level down
|
|
155
138
|
if (innerLevel !== level) {
|
|
139
|
+
// Skip newline for WithClause when withClauseStyle is 'full-oneline'
|
|
140
|
+
if (!(parentContainerType === SqlPrintTokenContainerType.WithClause && this.withClauseStyle === 'full-oneline')) {
|
|
141
|
+
this.linePrinter.appendNewline(level);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
shouldSkipToken(token) {
|
|
146
|
+
return (!token.innerTokens || token.innerTokens.length === 0) && token.text === '';
|
|
147
|
+
}
|
|
148
|
+
applyKeywordCase(text) {
|
|
149
|
+
if (this.keywordCase === 'upper') {
|
|
150
|
+
return text.toUpperCase();
|
|
151
|
+
}
|
|
152
|
+
else if (this.keywordCase === 'lower') {
|
|
153
|
+
return text.toLowerCase();
|
|
154
|
+
}
|
|
155
|
+
return text;
|
|
156
|
+
}
|
|
157
|
+
handleKeywordToken(token, level) {
|
|
158
|
+
const text = this.applyKeywordCase(token.text);
|
|
159
|
+
this.linePrinter.appendText(text);
|
|
160
|
+
}
|
|
161
|
+
handleCommaToken(token, level, parentContainerType) {
|
|
162
|
+
const text = token.text;
|
|
163
|
+
// Special handling for commas in WithClause when withClauseStyle is 'cte-oneline'
|
|
164
|
+
if (this.withClauseStyle === 'cte-oneline' && parentContainerType === SqlPrintTokenContainerType.WithClause) {
|
|
165
|
+
this.linePrinter.appendText(text);
|
|
156
166
|
this.linePrinter.appendNewline(level);
|
|
157
167
|
}
|
|
168
|
+
else if (this.commaBreak === 'before') {
|
|
169
|
+
this.linePrinter.appendNewline(level);
|
|
170
|
+
this.linePrinter.appendText(text);
|
|
171
|
+
}
|
|
172
|
+
else if (this.commaBreak === 'after') {
|
|
173
|
+
this.linePrinter.appendText(text);
|
|
174
|
+
this.linePrinter.appendNewline(level);
|
|
175
|
+
}
|
|
176
|
+
else {
|
|
177
|
+
this.linePrinter.appendText(text);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
handleAndOperatorToken(token, level) {
|
|
181
|
+
const text = this.applyKeywordCase(token.text);
|
|
182
|
+
if (this.andBreak === 'before') {
|
|
183
|
+
this.linePrinter.appendNewline(level);
|
|
184
|
+
this.linePrinter.appendText(text);
|
|
185
|
+
}
|
|
186
|
+
else if (this.andBreak === 'after') {
|
|
187
|
+
this.linePrinter.appendText(text);
|
|
188
|
+
this.linePrinter.appendNewline(level);
|
|
189
|
+
}
|
|
190
|
+
else {
|
|
191
|
+
this.linePrinter.appendText(text);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
handleJoinClauseToken(token, level) {
|
|
195
|
+
const text = this.applyKeywordCase(token.text);
|
|
196
|
+
// before join clause, add newline
|
|
197
|
+
this.linePrinter.appendNewline(level);
|
|
198
|
+
this.linePrinter.appendText(text);
|
|
199
|
+
}
|
|
200
|
+
handleCommentToken(token) {
|
|
201
|
+
// Handle comments - only output if exportComment is true
|
|
202
|
+
if (this.exportComment) {
|
|
203
|
+
this.linePrinter.appendText(token.text);
|
|
204
|
+
// Always add a space after comment to ensure SQL structure safety
|
|
205
|
+
this.linePrinter.appendText(' ');
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
handleCteOnelineToken(token, level) {
|
|
209
|
+
// Handle CTE with one-liner formatting when withClauseStyle is 'cte-oneline'
|
|
210
|
+
const onelinePrinter = new SqlPrinter({
|
|
211
|
+
indentChar: '',
|
|
212
|
+
indentSize: 0,
|
|
213
|
+
newline: ' ',
|
|
214
|
+
commaBreak: this.commaBreak,
|
|
215
|
+
andBreak: this.andBreak,
|
|
216
|
+
keywordCase: this.keywordCase,
|
|
217
|
+
exportComment: this.exportComment,
|
|
218
|
+
strictCommentPlacement: this.strictCommentPlacement,
|
|
219
|
+
withClauseStyle: 'standard', // Prevent recursive processing
|
|
220
|
+
});
|
|
221
|
+
const onelineResult = onelinePrinter.print(token, level);
|
|
222
|
+
this.linePrinter.appendText(onelineResult);
|
|
223
|
+
}
|
|
224
|
+
handleWithClauseOnelineToken(token, level) {
|
|
225
|
+
// Handle entire WITH clause as one-liner when withClauseStyle is 'full-oneline'
|
|
226
|
+
// Create a completely oneline printer for the entire WITH clause
|
|
227
|
+
const onelinePrinter = new SqlPrinter({
|
|
228
|
+
indentChar: '',
|
|
229
|
+
indentSize: 0,
|
|
230
|
+
newline: ' ',
|
|
231
|
+
commaBreak: 'none',
|
|
232
|
+
andBreak: this.andBreak,
|
|
233
|
+
keywordCase: this.keywordCase,
|
|
234
|
+
exportComment: this.exportComment,
|
|
235
|
+
strictCommentPlacement: this.strictCommentPlacement,
|
|
236
|
+
withClauseStyle: 'standard', // Prevent recursive processing
|
|
237
|
+
indentIncrementContainerTypes: [], // Disable all indentation
|
|
238
|
+
});
|
|
239
|
+
// Print the entire WITH clause as one line
|
|
240
|
+
const onelineResult = onelinePrinter.print(token, 0);
|
|
241
|
+
this.linePrinter.appendText(onelineResult);
|
|
242
|
+
// Add newline after WITH clause
|
|
243
|
+
this.linePrinter.appendNewline(level);
|
|
158
244
|
}
|
|
159
245
|
}
|
|
160
246
|
//# sourceMappingURL=SqlPrinter.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SqlPrinter.js","sourceRoot":"","sources":["../../../../src/transformers/SqlPrinter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,iBAAiB,EAAE,0BAA0B,EAAE,MAAM,yBAAyB,CAAC;AACvG,OAAO,EAAoB,WAAW,EAAiB,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"SqlPrinter.js","sourceRoot":"","sources":["../../../../src/transformers/SqlPrinter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,iBAAiB,EAAE,0BAA0B,EAAE,MAAM,yBAAyB,CAAC;AACvG,OAAO,EAAoB,WAAW,EAAiB,MAAM,eAAe,CAAC;AA6C7E;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,OAAO,UAAU;IA2BnB;;OAEG;IACH,YAAY,OAA2B;;QACnC,IAAI,CAAC,UAAU,GAAG,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,UAAU,mCAAI,EAAE,CAAC;QAC5C,IAAI,CAAC,UAAU,GAAG,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,UAAU,mCAAI,CAAC,CAAC;QAE3C,8FAA8F;QAC9F,0EAA0E;QAC1E,IAAI,CAAC,OAAO,GAAG,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,OAAO,mCAAI,GAAG,CAAC;QAEvC,IAAI,CAAC,UAAU,GAAG,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,UAAU,mCAAI,MAAM,CAAC;QAChD,IAAI,CAAC,QAAQ,GAAG,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,QAAQ,mCAAI,MAAM,CAAC;QAC5C,IAAI,CAAC,WAAW,GAAG,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,WAAW,mCAAI,MAAM,CAAC;QAClD,IAAI,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