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,wEAA+F;AAC/F,6CAA0E;AAK1E,4CAA4C;AAC/B,QAAA,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,wEAA+F;AAC/F,6CAA0E;AAK1E,4CAA4C;AAC/B,QAAA,aAAa,GAAG,CAAC,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,QAAQ,CAAU,CAAC;AAWnF;;GAEG;AACH,MAAa,YAAY;IAIrB,YAAY,UAcR,EAAE;;QAEF,MAAM,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,6BAAO,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,GAAG;YAClB,GAAG,YAAY,EAAE,6BAA6B;YAC9C,gBAAgB,EAAE,MAAA,OAAO,CAAC,gBAAgB,mCAAI,YAAY,aAAZ,YAAY,uBAAZ,YAAY,CAAE,gBAAgB;YAC5E,eAAe,EAAE,MAAA,OAAO,CAAC,eAAe,mCAAI,YAAY,aAAZ,YAAY,uBAAZ,YAAY,CAAE,eAAe;YACzE,cAAc,EAAE,MAAA,OAAO,CAAC,cAAc,mCAAI,YAAY,aAAZ,YAAY,uBAAZ,YAAY,CAAE,cAAc;SACzE,CAAC;QAEF,IAAI,CAAC,MAAM,GAAG,IAAI,yCAAmB,CAAC,aAAa,CAAC,CAAC;QACrD,IAAI,CAAC,OAAO,GAAG,IAAI,uBAAU,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;AA/CD,oCA+CC"}
|
|
@@ -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
|
}
|
|
@@ -5,13 +5,30 @@ const SqlPrintToken_1 = require("../models/SqlPrintToken");
|
|
|
5
5
|
const LinePrinter_1 = require("./LinePrinter");
|
|
6
6
|
/**
|
|
7
7
|
* SqlPrinter formats a SqlPrintToken tree into a SQL string with flexible style options.
|
|
8
|
+
*
|
|
9
|
+
* This class provides various formatting options including:
|
|
10
|
+
* - Indentation control (character and size)
|
|
11
|
+
* - Line break styles for commas and AND operators
|
|
12
|
+
* - Keyword case transformation
|
|
13
|
+
* - Comment handling
|
|
14
|
+
* - WITH clause formatting styles
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* const printer = new SqlPrinter({
|
|
18
|
+
* indentChar: ' ',
|
|
19
|
+
* indentSize: 1,
|
|
20
|
+
* keywordCase: 'upper',
|
|
21
|
+
* commaBreak: 'after',
|
|
22
|
+
* withClauseStyle: 'cte-oneline'
|
|
23
|
+
* });
|
|
24
|
+
* const formatted = printer.print(sqlToken);
|
|
8
25
|
*/
|
|
9
26
|
class SqlPrinter {
|
|
10
27
|
/**
|
|
11
28
|
* @param options Optional style settings for pretty printing
|
|
12
29
|
*/
|
|
13
30
|
constructor(options) {
|
|
14
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
31
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
15
32
|
this.indentChar = (_a = options === null || options === void 0 ? void 0 : options.indentChar) !== null && _a !== void 0 ? _a : '';
|
|
16
33
|
this.indentSize = (_b = options === null || options === void 0 ? void 0 : options.indentSize) !== null && _b !== void 0 ? _b : 0;
|
|
17
34
|
// The default newline character is set to a blank space (' ') to enable one-liner formatting.
|
|
@@ -22,9 +39,10 @@ class SqlPrinter {
|
|
|
22
39
|
this.keywordCase = (_f = options === null || options === void 0 ? void 0 : options.keywordCase) !== null && _f !== void 0 ? _f : 'none';
|
|
23
40
|
this.exportComment = (_g = options === null || options === void 0 ? void 0 : options.exportComment) !== null && _g !== void 0 ? _g : false;
|
|
24
41
|
this.strictCommentPlacement = (_h = options === null || options === void 0 ? void 0 : options.strictCommentPlacement) !== null && _h !== void 0 ? _h : false;
|
|
42
|
+
this.withClauseStyle = (_j = options === null || options === void 0 ? void 0 : options.withClauseStyle) !== null && _j !== void 0 ? _j : 'standard';
|
|
25
43
|
this.linePrinter = new LinePrinter_1.LinePrinter(this.indentChar, this.indentSize, this.newline);
|
|
26
44
|
// Initialize
|
|
27
|
-
this.indentIncrementContainers = new Set((
|
|
45
|
+
this.indentIncrementContainers = new Set((_k = options === null || options === void 0 ? void 0 : options.indentIncrementContainerTypes) !== null && _k !== void 0 ? _k : [
|
|
28
46
|
SqlPrintToken_1.SqlPrintTokenContainerType.SelectClause,
|
|
29
47
|
SqlPrintToken_1.SqlPrintTokenContainerType.FromClause,
|
|
30
48
|
SqlPrintToken_1.SqlPrintTokenContainerType.WhereClause,
|
|
@@ -51,8 +69,12 @@ class SqlPrinter {
|
|
|
51
69
|
}
|
|
52
70
|
/**
|
|
53
71
|
* Converts a SqlPrintToken tree to a formatted SQL string.
|
|
54
|
-
* @param token The root SqlPrintToken
|
|
55
|
-
* @param level
|
|
72
|
+
* @param token The root SqlPrintToken to format
|
|
73
|
+
* @param level Initial indentation level (default: 0)
|
|
74
|
+
* @returns Formatted SQL string
|
|
75
|
+
* @example
|
|
76
|
+
* const printer = new SqlPrinter({ indentChar: ' ', keywordCase: 'upper' });
|
|
77
|
+
* const formatted = printer.print(sqlToken);
|
|
56
78
|
*/
|
|
57
79
|
print(token, level = 0) {
|
|
58
80
|
// initialize
|
|
@@ -63,76 +85,34 @@ class SqlPrinter {
|
|
|
63
85
|
this.appendToken(token, level);
|
|
64
86
|
return this.linePrinter.print();
|
|
65
87
|
}
|
|
66
|
-
appendToken(token, level) {
|
|
67
|
-
if (
|
|
68
|
-
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
88
|
+
appendToken(token, level, parentContainerType) {
|
|
89
|
+
if (this.shouldSkipToken(token)) {
|
|
90
|
+
return;
|
|
71
91
|
}
|
|
72
92
|
const current = this.linePrinter.getCurrentLine();
|
|
93
|
+
// Handle different token types
|
|
73
94
|
if (token.type === SqlPrintToken_1.SqlPrintTokenType.keyword) {
|
|
74
|
-
|
|
75
|
-
if (this.keywordCase === 'upper') {
|
|
76
|
-
text = text.toUpperCase();
|
|
77
|
-
}
|
|
78
|
-
else if (this.keywordCase === 'lower') {
|
|
79
|
-
text = text.toLowerCase();
|
|
80
|
-
}
|
|
81
|
-
this.linePrinter.appendText(text);
|
|
95
|
+
this.handleKeywordToken(token, level);
|
|
82
96
|
}
|
|
83
97
|
else if (token.type === SqlPrintToken_1.SqlPrintTokenType.comma) {
|
|
84
|
-
|
|
85
|
-
if (this.commaBreak === 'before') {
|
|
86
|
-
this.linePrinter.appendNewline(level);
|
|
87
|
-
this.linePrinter.appendText(text);
|
|
88
|
-
}
|
|
89
|
-
else if (this.commaBreak === 'after') {
|
|
90
|
-
this.linePrinter.appendText(text);
|
|
91
|
-
this.linePrinter.appendNewline(level);
|
|
92
|
-
}
|
|
93
|
-
else {
|
|
94
|
-
this.linePrinter.appendText(text);
|
|
95
|
-
}
|
|
98
|
+
this.handleCommaToken(token, level, parentContainerType);
|
|
96
99
|
}
|
|
97
100
|
else if (token.type === SqlPrintToken_1.SqlPrintTokenType.operator && token.text.toLowerCase() === 'and') {
|
|
98
|
-
|
|
99
|
-
if (this.keywordCase === 'upper') {
|
|
100
|
-
text = text.toUpperCase();
|
|
101
|
-
}
|
|
102
|
-
else if (this.keywordCase === 'lower') {
|
|
103
|
-
text = text.toLowerCase();
|
|
104
|
-
}
|
|
105
|
-
if (this.andBreak === 'before') {
|
|
106
|
-
this.linePrinter.appendNewline(level);
|
|
107
|
-
this.linePrinter.appendText(text);
|
|
108
|
-
}
|
|
109
|
-
else if (this.andBreak === 'after') {
|
|
110
|
-
this.linePrinter.appendText(text);
|
|
111
|
-
this.linePrinter.appendNewline(level);
|
|
112
|
-
}
|
|
113
|
-
else {
|
|
114
|
-
this.linePrinter.appendText(text);
|
|
115
|
-
}
|
|
101
|
+
this.handleAndOperatorToken(token, level);
|
|
116
102
|
}
|
|
117
103
|
else if (token.containerType === "JoinClause") {
|
|
118
|
-
|
|
119
|
-
if (this.keywordCase === 'upper') {
|
|
120
|
-
text = text.toUpperCase();
|
|
121
|
-
}
|
|
122
|
-
else if (this.keywordCase === 'lower') {
|
|
123
|
-
text = text.toLowerCase();
|
|
124
|
-
}
|
|
125
|
-
// before join clause, add newline
|
|
126
|
-
this.linePrinter.appendNewline(level);
|
|
127
|
-
this.linePrinter.appendText(text);
|
|
104
|
+
this.handleJoinClauseToken(token, level);
|
|
128
105
|
}
|
|
129
106
|
else if (token.type === SqlPrintToken_1.SqlPrintTokenType.comment) {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
107
|
+
this.handleCommentToken(token);
|
|
108
|
+
}
|
|
109
|
+
else if (token.containerType === SqlPrintToken_1.SqlPrintTokenContainerType.CommonTable && this.withClauseStyle === 'cte-oneline') {
|
|
110
|
+
this.handleCteOnelineToken(token, level);
|
|
111
|
+
return; // Return early to avoid processing innerTokens
|
|
112
|
+
}
|
|
113
|
+
else if (token.containerType === SqlPrintToken_1.SqlPrintTokenContainerType.WithClause && this.withClauseStyle === 'full-oneline') {
|
|
114
|
+
this.handleWithClauseOnelineToken(token, level);
|
|
115
|
+
return; // Return early to avoid processing innerTokens
|
|
136
116
|
}
|
|
137
117
|
else {
|
|
138
118
|
this.linePrinter.appendText(token.text);
|
|
@@ -141,23 +121,129 @@ class SqlPrinter {
|
|
|
141
121
|
if (token.keywordTokens && token.keywordTokens.length > 0) {
|
|
142
122
|
for (let i = 0; i < token.keywordTokens.length; i++) {
|
|
143
123
|
const keywordToken = token.keywordTokens[i];
|
|
144
|
-
this.appendToken(keywordToken, level);
|
|
124
|
+
this.appendToken(keywordToken, level, token.containerType);
|
|
145
125
|
}
|
|
146
126
|
}
|
|
147
127
|
let innerLevel = level;
|
|
148
128
|
// indent level up
|
|
149
129
|
if (this.newline !== ' ' && current.text !== '' && this.indentIncrementContainers.has(token.containerType)) { // Changed condition
|
|
150
|
-
|
|
151
|
-
this.
|
|
130
|
+
// Skip newline for WithClause when withClauseStyle is 'full-oneline'
|
|
131
|
+
if (!(token.containerType === SqlPrintToken_1.SqlPrintTokenContainerType.WithClause && this.withClauseStyle === 'full-oneline')) {
|
|
132
|
+
innerLevel++;
|
|
133
|
+
this.linePrinter.appendNewline(innerLevel);
|
|
134
|
+
}
|
|
152
135
|
}
|
|
153
136
|
for (let i = 0; i < token.innerTokens.length; i++) {
|
|
154
137
|
const child = token.innerTokens[i];
|
|
155
|
-
this.appendToken(child, innerLevel);
|
|
138
|
+
this.appendToken(child, innerLevel, token.containerType);
|
|
156
139
|
}
|
|
157
140
|
// indent level down
|
|
158
141
|
if (innerLevel !== level) {
|
|
142
|
+
// Skip newline for WithClause when withClauseStyle is 'full-oneline'
|
|
143
|
+
if (!(parentContainerType === SqlPrintToken_1.SqlPrintTokenContainerType.WithClause && this.withClauseStyle === 'full-oneline')) {
|
|
144
|
+
this.linePrinter.appendNewline(level);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
shouldSkipToken(token) {
|
|
149
|
+
return (!token.innerTokens || token.innerTokens.length === 0) && token.text === '';
|
|
150
|
+
}
|
|
151
|
+
applyKeywordCase(text) {
|
|
152
|
+
if (this.keywordCase === 'upper') {
|
|
153
|
+
return text.toUpperCase();
|
|
154
|
+
}
|
|
155
|
+
else if (this.keywordCase === 'lower') {
|
|
156
|
+
return text.toLowerCase();
|
|
157
|
+
}
|
|
158
|
+
return text;
|
|
159
|
+
}
|
|
160
|
+
handleKeywordToken(token, level) {
|
|
161
|
+
const text = this.applyKeywordCase(token.text);
|
|
162
|
+
this.linePrinter.appendText(text);
|
|
163
|
+
}
|
|
164
|
+
handleCommaToken(token, level, parentContainerType) {
|
|
165
|
+
const text = token.text;
|
|
166
|
+
// Special handling for commas in WithClause when withClauseStyle is 'cte-oneline'
|
|
167
|
+
if (this.withClauseStyle === 'cte-oneline' && parentContainerType === SqlPrintToken_1.SqlPrintTokenContainerType.WithClause) {
|
|
168
|
+
this.linePrinter.appendText(text);
|
|
159
169
|
this.linePrinter.appendNewline(level);
|
|
160
170
|
}
|
|
171
|
+
else if (this.commaBreak === 'before') {
|
|
172
|
+
this.linePrinter.appendNewline(level);
|
|
173
|
+
this.linePrinter.appendText(text);
|
|
174
|
+
}
|
|
175
|
+
else if (this.commaBreak === 'after') {
|
|
176
|
+
this.linePrinter.appendText(text);
|
|
177
|
+
this.linePrinter.appendNewline(level);
|
|
178
|
+
}
|
|
179
|
+
else {
|
|
180
|
+
this.linePrinter.appendText(text);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
handleAndOperatorToken(token, level) {
|
|
184
|
+
const text = this.applyKeywordCase(token.text);
|
|
185
|
+
if (this.andBreak === 'before') {
|
|
186
|
+
this.linePrinter.appendNewline(level);
|
|
187
|
+
this.linePrinter.appendText(text);
|
|
188
|
+
}
|
|
189
|
+
else if (this.andBreak === 'after') {
|
|
190
|
+
this.linePrinter.appendText(text);
|
|
191
|
+
this.linePrinter.appendNewline(level);
|
|
192
|
+
}
|
|
193
|
+
else {
|
|
194
|
+
this.linePrinter.appendText(text);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
handleJoinClauseToken(token, level) {
|
|
198
|
+
const text = this.applyKeywordCase(token.text);
|
|
199
|
+
// before join clause, add newline
|
|
200
|
+
this.linePrinter.appendNewline(level);
|
|
201
|
+
this.linePrinter.appendText(text);
|
|
202
|
+
}
|
|
203
|
+
handleCommentToken(token) {
|
|
204
|
+
// Handle comments - only output if exportComment is true
|
|
205
|
+
if (this.exportComment) {
|
|
206
|
+
this.linePrinter.appendText(token.text);
|
|
207
|
+
// Always add a space after comment to ensure SQL structure safety
|
|
208
|
+
this.linePrinter.appendText(' ');
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
handleCteOnelineToken(token, level) {
|
|
212
|
+
// Handle CTE with one-liner formatting when withClauseStyle is 'cte-oneline'
|
|
213
|
+
const onelinePrinter = new SqlPrinter({
|
|
214
|
+
indentChar: '',
|
|
215
|
+
indentSize: 0,
|
|
216
|
+
newline: ' ',
|
|
217
|
+
commaBreak: this.commaBreak,
|
|
218
|
+
andBreak: this.andBreak,
|
|
219
|
+
keywordCase: this.keywordCase,
|
|
220
|
+
exportComment: this.exportComment,
|
|
221
|
+
strictCommentPlacement: this.strictCommentPlacement,
|
|
222
|
+
withClauseStyle: 'standard', // Prevent recursive processing
|
|
223
|
+
});
|
|
224
|
+
const onelineResult = onelinePrinter.print(token, level);
|
|
225
|
+
this.linePrinter.appendText(onelineResult);
|
|
226
|
+
}
|
|
227
|
+
handleWithClauseOnelineToken(token, level) {
|
|
228
|
+
// Handle entire WITH clause as one-liner when withClauseStyle is 'full-oneline'
|
|
229
|
+
// Create a completely oneline printer for the entire WITH clause
|
|
230
|
+
const onelinePrinter = new SqlPrinter({
|
|
231
|
+
indentChar: '',
|
|
232
|
+
indentSize: 0,
|
|
233
|
+
newline: ' ',
|
|
234
|
+
commaBreak: 'none',
|
|
235
|
+
andBreak: this.andBreak,
|
|
236
|
+
keywordCase: this.keywordCase,
|
|
237
|
+
exportComment: this.exportComment,
|
|
238
|
+
strictCommentPlacement: this.strictCommentPlacement,
|
|
239
|
+
withClauseStyle: 'standard', // Prevent recursive processing
|
|
240
|
+
indentIncrementContainerTypes: [], // Disable all indentation
|
|
241
|
+
});
|
|
242
|
+
// Print the entire WITH clause as one line
|
|
243
|
+
const onelineResult = onelinePrinter.print(token, 0);
|
|
244
|
+
this.linePrinter.appendText(onelineResult);
|
|
245
|
+
// Add newline after WITH clause
|
|
246
|
+
this.linePrinter.appendNewline(level);
|
|
161
247
|
}
|
|
162
248
|
}
|
|
163
249
|
exports.SqlPrinter = SqlPrinter;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SqlPrinter.js","sourceRoot":"","sources":["../../../src/transformers/SqlPrinter.ts"],"names":[],"mappings":";;;AAAA,2DAAuG;AACvG,+CAA6E;
|
|
1
|
+
{"version":3,"file":"SqlPrinter.js","sourceRoot":"","sources":["../../../src/transformers/SqlPrinter.ts"],"names":[],"mappings":";;;AAAA,2DAAuG;AACvG,+CAA6E;AA6C7E;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAa,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,CAAC,aAAa,GAAG,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,aAAa,mCAAI,KAAK,CAAC;QACrD,IAAI,CAAC,sBAAsB,GAAG,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,sBAAsB,mCAAI,KAAK,CAAC;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