rawsql-ts 0.11.43-beta → 0.11.44-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/README.md +12 -12
- package/dist/esm/index.js +18 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/index.min.js +15 -19
- package/dist/esm/index.min.js.map +4 -4
- package/dist/esm/src/index.d.ts +18 -0
- package/dist/esm/src/index.js +18 -0
- package/dist/esm/src/index.js.map +1 -1
- package/dist/esm/src/models/BinarySelectQuery.d.ts +25 -1
- package/dist/esm/src/models/BinarySelectQuery.js +28 -0
- package/dist/esm/src/models/BinarySelectQuery.js.map +1 -1
- package/dist/esm/src/models/Clause.d.ts +14 -2
- package/dist/esm/src/models/Clause.js +26 -1
- package/dist/esm/src/models/Clause.js.map +1 -1
- package/dist/esm/src/models/CreateTableQuery.d.ts +99 -5
- package/dist/esm/src/models/CreateTableQuery.js +85 -10
- package/dist/esm/src/models/CreateTableQuery.js.map +1 -1
- package/dist/esm/src/models/DDLStatements.d.ts +157 -0
- package/dist/esm/src/models/DDLStatements.js +141 -0
- package/dist/esm/src/models/DDLStatements.js.map +1 -0
- package/dist/esm/src/models/DeleteQuery.d.ts +17 -0
- package/dist/esm/src/models/DeleteQuery.js +16 -0
- package/dist/esm/src/models/DeleteQuery.js.map +1 -0
- package/dist/esm/src/models/InsertQuery.d.ts +7 -1
- package/dist/esm/src/models/InsertQuery.js +6 -2
- package/dist/esm/src/models/InsertQuery.js.map +1 -1
- package/dist/esm/src/models/MergeQuery.d.ts +63 -0
- package/dist/esm/src/models/MergeQuery.js +94 -0
- package/dist/esm/src/models/MergeQuery.js.map +1 -0
- package/dist/esm/src/models/SelectQuery.d.ts +37 -1
- package/dist/esm/src/models/SelectQuery.js +4 -1
- package/dist/esm/src/models/SelectQuery.js.map +1 -1
- package/dist/esm/src/models/SimpleSelectQuery.d.ts +29 -1
- package/dist/esm/src/models/SimpleSelectQuery.js +32 -0
- package/dist/esm/src/models/SimpleSelectQuery.js.map +1 -1
- package/dist/esm/src/models/SqlComponent.d.ts +2 -1
- package/dist/esm/src/models/SqlComponent.js +1 -1
- package/dist/esm/src/models/SqlComponent.js.map +1 -1
- package/dist/esm/src/models/SqlPrintToken.d.ts +33 -0
- package/dist/esm/src/models/SqlPrintToken.js +32 -0
- package/dist/esm/src/models/SqlPrintToken.js.map +1 -1
- package/dist/esm/src/models/ValuesQuery.d.ts +25 -1
- package/dist/esm/src/models/ValuesQuery.js +28 -0
- package/dist/esm/src/models/ValuesQuery.js.map +1 -1
- package/dist/esm/src/parsers/AlterTableParser.d.ts +25 -0
- package/dist/esm/src/parsers/AlterTableParser.js +428 -0
- package/dist/esm/src/parsers/AlterTableParser.js.map +1 -0
- package/dist/esm/src/parsers/CreateIndexParser.d.ts +16 -0
- package/dist/esm/src/parsers/CreateIndexParser.js +237 -0
- package/dist/esm/src/parsers/CreateIndexParser.js.map +1 -0
- package/dist/esm/src/parsers/CreateTableParser.d.ts +41 -0
- package/dist/esm/src/parsers/CreateTableParser.js +734 -0
- package/dist/esm/src/parsers/CreateTableParser.js.map +1 -0
- package/dist/esm/src/parsers/DeleteClauseParser.d.ts +11 -0
- package/dist/esm/src/parsers/DeleteClauseParser.js +33 -0
- package/dist/esm/src/parsers/DeleteClauseParser.js.map +1 -0
- package/dist/esm/src/parsers/DeleteQueryParser.d.ts +16 -0
- package/dist/esm/src/parsers/DeleteQueryParser.js +73 -0
- package/dist/esm/src/parsers/DeleteQueryParser.js.map +1 -0
- package/dist/esm/src/parsers/DropConstraintParser.d.ts +12 -0
- package/dist/esm/src/parsers/DropConstraintParser.js +47 -0
- package/dist/esm/src/parsers/DropConstraintParser.js.map +1 -0
- package/dist/esm/src/parsers/DropIndexParser.d.ts +12 -0
- package/dist/esm/src/parsers/DropIndexParser.js +69 -0
- package/dist/esm/src/parsers/DropIndexParser.js.map +1 -0
- package/dist/esm/src/parsers/DropTableParser.d.ts +12 -0
- package/dist/esm/src/parsers/DropTableParser.js +59 -0
- package/dist/esm/src/parsers/DropTableParser.js.map +1 -0
- package/dist/esm/src/parsers/FunctionExpressionParser.d.ts +4 -0
- package/dist/esm/src/parsers/FunctionExpressionParser.js +25 -8
- package/dist/esm/src/parsers/FunctionExpressionParser.js.map +1 -1
- package/dist/esm/src/parsers/InsertQueryParser.js +103 -31
- package/dist/esm/src/parsers/InsertQueryParser.js.map +1 -1
- package/dist/esm/src/parsers/MergeQueryParser.d.ts +26 -0
- package/dist/esm/src/parsers/MergeQueryParser.js +479 -0
- package/dist/esm/src/parsers/MergeQueryParser.js.map +1 -0
- package/dist/esm/src/parsers/ReturningClauseParser.js +50 -7
- package/dist/esm/src/parsers/ReturningClauseParser.js.map +1 -1
- package/dist/esm/src/parsers/SelectClauseParser.js +3 -3
- package/dist/esm/src/parsers/SelectClauseParser.js.map +1 -1
- package/dist/esm/src/parsers/SelectQueryParser.d.ts +4 -0
- package/dist/esm/src/parsers/SelectQueryParser.js +4 -0
- package/dist/esm/src/parsers/SelectQueryParser.js.map +1 -1
- package/dist/esm/src/parsers/SetClauseParser.js +97 -15
- package/dist/esm/src/parsers/SetClauseParser.js.map +1 -1
- package/dist/esm/src/parsers/SqlParser.d.ts +38 -0
- package/dist/esm/src/parsers/SqlParser.js +344 -0
- package/dist/esm/src/parsers/SqlParser.js.map +1 -0
- package/dist/esm/src/parsers/SqlPrintTokenParser.d.ts +57 -3
- package/dist/esm/src/parsers/SqlPrintTokenParser.js +1016 -33
- package/dist/esm/src/parsers/SqlPrintTokenParser.js.map +1 -1
- package/dist/esm/src/parsers/SqlTokenizer.d.ts +24 -2
- package/dist/esm/src/parsers/SqlTokenizer.js +135 -74
- package/dist/esm/src/parsers/SqlTokenizer.js.map +1 -1
- package/dist/esm/src/parsers/UpdateQueryParser.js +11 -1
- package/dist/esm/src/parsers/UpdateQueryParser.js.map +1 -1
- package/dist/esm/src/parsers/UsingClauseParser.d.ts +11 -0
- package/dist/esm/src/parsers/UsingClauseParser.js +29 -0
- package/dist/esm/src/parsers/UsingClauseParser.js.map +1 -0
- package/dist/esm/src/parsers/ValueParser.js +5 -1
- package/dist/esm/src/parsers/ValueParser.js.map +1 -1
- package/dist/esm/src/parsers/ValuesQueryParser.d.ts +0 -2
- package/dist/esm/src/parsers/ValuesQueryParser.js +5 -45
- package/dist/esm/src/parsers/ValuesQueryParser.js.map +1 -1
- package/dist/esm/src/parsers/utils/LexemeCommentUtils.d.ts +6 -0
- package/dist/esm/src/parsers/utils/LexemeCommentUtils.js +26 -0
- package/dist/esm/src/parsers/utils/LexemeCommentUtils.js.map +1 -0
- package/dist/esm/src/tokenReaders/CommandTokenReader.js +49 -2
- package/dist/esm/src/tokenReaders/CommandTokenReader.js.map +1 -1
- package/dist/esm/src/tokenReaders/LiteralTokenReader.js +8 -5
- package/dist/esm/src/tokenReaders/LiteralTokenReader.js.map +1 -1
- package/dist/esm/src/tokenReaders/OperatorTokenReader.js +10 -1
- package/dist/esm/src/tokenReaders/OperatorTokenReader.js.map +1 -1
- package/dist/esm/src/tokenReaders/TypeTokenReader.js +11 -1
- package/dist/esm/src/tokenReaders/TypeTokenReader.js.map +1 -1
- package/dist/esm/src/transformers/InsertQuerySelectValuesConverter.d.ts +18 -0
- package/dist/esm/src/transformers/InsertQuerySelectValuesConverter.js +118 -0
- package/dist/esm/src/transformers/InsertQuerySelectValuesConverter.js.map +1 -0
- package/dist/esm/src/transformers/LinePrinter.d.ts +1 -0
- package/dist/esm/src/transformers/LinePrinter.js +12 -0
- package/dist/esm/src/transformers/LinePrinter.js.map +1 -1
- package/dist/esm/src/transformers/OnelineFormattingHelper.d.ts +29 -0
- package/dist/esm/src/transformers/OnelineFormattingHelper.js +88 -0
- package/dist/esm/src/transformers/OnelineFormattingHelper.js.map +1 -0
- package/dist/esm/src/transformers/QueryBuilder.d.ts +47 -13
- package/dist/esm/src/transformers/QueryBuilder.js +424 -62
- package/dist/esm/src/transformers/QueryBuilder.js.map +1 -1
- package/dist/esm/src/transformers/SqlFormatter.d.ts +13 -1
- package/dist/esm/src/transformers/SqlFormatter.js +13 -4
- package/dist/esm/src/transformers/SqlFormatter.js.map +1 -1
- package/dist/esm/src/transformers/SqlPrinter.d.ts +46 -8
- package/dist/esm/src/transformers/SqlPrinter.js +596 -71
- package/dist/esm/src/transformers/SqlPrinter.js.map +1 -1
- package/dist/esm/src/types/Formatting.d.ts +8 -0
- package/dist/esm/src/types/Formatting.js +2 -0
- package/dist/esm/src/types/Formatting.js.map +1 -0
- package/dist/esm/src/utils/ParserStringUtils.d.ts +6 -0
- package/dist/esm/src/utils/ParserStringUtils.js +28 -0
- package/dist/esm/src/utils/ParserStringUtils.js.map +1 -0
- package/dist/esm/tsconfig.browser.tsbuildinfo +1 -1
- package/dist/index.min.js +14 -18
- package/dist/index.min.js.map +4 -4
- package/dist/src/index.d.ts +18 -0
- package/dist/src/index.js +18 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/models/BinarySelectQuery.d.ts +25 -1
- package/dist/src/models/BinarySelectQuery.js +28 -0
- package/dist/src/models/BinarySelectQuery.js.map +1 -1
- package/dist/src/models/Clause.d.ts +14 -2
- package/dist/src/models/Clause.js +29 -2
- package/dist/src/models/Clause.js.map +1 -1
- package/dist/src/models/CreateTableQuery.d.ts +99 -5
- package/dist/src/models/CreateTableQuery.js +90 -11
- package/dist/src/models/CreateTableQuery.js.map +1 -1
- package/dist/src/models/DDLStatements.d.ts +157 -0
- package/dist/src/models/DDLStatements.js +153 -0
- package/dist/src/models/DDLStatements.js.map +1 -0
- package/dist/src/models/DeleteQuery.d.ts +17 -0
- package/dist/src/models/DeleteQuery.js +20 -0
- package/dist/src/models/DeleteQuery.js.map +1 -0
- package/dist/src/models/InsertQuery.d.ts +7 -1
- package/dist/src/models/InsertQuery.js +6 -2
- package/dist/src/models/InsertQuery.js.map +1 -1
- package/dist/src/models/MergeQuery.d.ts +63 -0
- package/dist/src/models/MergeQuery.js +104 -0
- package/dist/src/models/MergeQuery.js.map +1 -0
- package/dist/src/models/SelectQuery.d.ts +37 -1
- package/dist/src/models/SelectQuery.js +7 -1
- package/dist/src/models/SelectQuery.js.map +1 -1
- package/dist/src/models/SimpleSelectQuery.d.ts +29 -1
- package/dist/src/models/SimpleSelectQuery.js +32 -0
- package/dist/src/models/SimpleSelectQuery.js.map +1 -1
- package/dist/src/models/SqlComponent.d.ts +2 -1
- package/dist/src/models/SqlComponent.js +1 -1
- package/dist/src/models/SqlComponent.js.map +1 -1
- package/dist/src/models/SqlPrintToken.d.ts +33 -0
- package/dist/src/models/SqlPrintToken.js +32 -0
- package/dist/src/models/SqlPrintToken.js.map +1 -1
- package/dist/src/models/ValuesQuery.d.ts +25 -1
- package/dist/src/models/ValuesQuery.js +28 -0
- package/dist/src/models/ValuesQuery.js.map +1 -1
- package/dist/src/parsers/AlterTableParser.d.ts +25 -0
- package/dist/src/parsers/AlterTableParser.js +432 -0
- package/dist/src/parsers/AlterTableParser.js.map +1 -0
- package/dist/src/parsers/CreateIndexParser.d.ts +16 -0
- package/dist/src/parsers/CreateIndexParser.js +241 -0
- package/dist/src/parsers/CreateIndexParser.js.map +1 -0
- package/dist/src/parsers/CreateTableParser.d.ts +41 -0
- package/dist/src/parsers/CreateTableParser.js +738 -0
- package/dist/src/parsers/CreateTableParser.js.map +1 -0
- package/dist/src/parsers/DeleteClauseParser.d.ts +11 -0
- package/dist/src/parsers/DeleteClauseParser.js +37 -0
- package/dist/src/parsers/DeleteClauseParser.js.map +1 -0
- package/dist/src/parsers/DeleteQueryParser.d.ts +16 -0
- package/dist/src/parsers/DeleteQueryParser.js +77 -0
- package/dist/src/parsers/DeleteQueryParser.js.map +1 -0
- package/dist/src/parsers/DropConstraintParser.d.ts +12 -0
- package/dist/src/parsers/DropConstraintParser.js +51 -0
- package/dist/src/parsers/DropConstraintParser.js.map +1 -0
- package/dist/src/parsers/DropIndexParser.d.ts +12 -0
- package/dist/src/parsers/DropIndexParser.js +73 -0
- package/dist/src/parsers/DropIndexParser.js.map +1 -0
- package/dist/src/parsers/DropTableParser.d.ts +12 -0
- package/dist/src/parsers/DropTableParser.js +63 -0
- package/dist/src/parsers/DropTableParser.js.map +1 -0
- package/dist/src/parsers/FunctionExpressionParser.d.ts +4 -0
- package/dist/src/parsers/FunctionExpressionParser.js +25 -8
- package/dist/src/parsers/FunctionExpressionParser.js.map +1 -1
- package/dist/src/parsers/InsertQueryParser.js +103 -31
- package/dist/src/parsers/InsertQueryParser.js.map +1 -1
- package/dist/src/parsers/MergeQueryParser.d.ts +26 -0
- package/dist/src/parsers/MergeQueryParser.js +483 -0
- package/dist/src/parsers/MergeQueryParser.js.map +1 -0
- package/dist/src/parsers/ReturningClauseParser.js +50 -7
- package/dist/src/parsers/ReturningClauseParser.js.map +1 -1
- package/dist/src/parsers/SelectClauseParser.js +2 -2
- package/dist/src/parsers/SelectClauseParser.js.map +1 -1
- package/dist/src/parsers/SelectQueryParser.d.ts +4 -0
- package/dist/src/parsers/SelectQueryParser.js +4 -0
- package/dist/src/parsers/SelectQueryParser.js.map +1 -1
- package/dist/src/parsers/SetClauseParser.js +97 -15
- package/dist/src/parsers/SetClauseParser.js.map +1 -1
- package/dist/src/parsers/SqlParser.d.ts +38 -0
- package/dist/src/parsers/SqlParser.js +353 -0
- package/dist/src/parsers/SqlParser.js.map +1 -0
- package/dist/src/parsers/SqlPrintTokenParser.d.ts +57 -3
- package/dist/src/parsers/SqlPrintTokenParser.js +1014 -31
- package/dist/src/parsers/SqlPrintTokenParser.js.map +1 -1
- package/dist/src/parsers/SqlTokenizer.d.ts +24 -2
- package/dist/src/parsers/SqlTokenizer.js +139 -74
- package/dist/src/parsers/SqlTokenizer.js.map +1 -1
- package/dist/src/parsers/UpdateQueryParser.js +11 -1
- package/dist/src/parsers/UpdateQueryParser.js.map +1 -1
- package/dist/src/parsers/UsingClauseParser.d.ts +11 -0
- package/dist/src/parsers/UsingClauseParser.js +33 -0
- package/dist/src/parsers/UsingClauseParser.js.map +1 -0
- package/dist/src/parsers/ValueParser.js +5 -1
- package/dist/src/parsers/ValueParser.js.map +1 -1
- package/dist/src/parsers/ValuesQueryParser.d.ts +0 -2
- package/dist/src/parsers/ValuesQueryParser.js +5 -45
- package/dist/src/parsers/ValuesQueryParser.js.map +1 -1
- package/dist/src/parsers/utils/LexemeCommentUtils.d.ts +6 -0
- package/dist/src/parsers/utils/LexemeCommentUtils.js +29 -0
- package/dist/src/parsers/utils/LexemeCommentUtils.js.map +1 -0
- package/dist/src/tokenReaders/CommandTokenReader.js +49 -2
- package/dist/src/tokenReaders/CommandTokenReader.js.map +1 -1
- package/dist/src/tokenReaders/LiteralTokenReader.js +8 -5
- package/dist/src/tokenReaders/LiteralTokenReader.js.map +1 -1
- package/dist/src/tokenReaders/OperatorTokenReader.js +10 -1
- package/dist/src/tokenReaders/OperatorTokenReader.js.map +1 -1
- package/dist/src/tokenReaders/TypeTokenReader.js +11 -1
- package/dist/src/tokenReaders/TypeTokenReader.js.map +1 -1
- package/dist/src/transformers/InsertQuerySelectValuesConverter.d.ts +18 -0
- package/dist/src/transformers/InsertQuerySelectValuesConverter.js +122 -0
- package/dist/src/transformers/InsertQuerySelectValuesConverter.js.map +1 -0
- package/dist/src/transformers/LinePrinter.d.ts +1 -0
- package/dist/src/transformers/LinePrinter.js +12 -0
- package/dist/src/transformers/LinePrinter.js.map +1 -1
- package/dist/src/transformers/OnelineFormattingHelper.d.ts +29 -0
- package/dist/src/transformers/OnelineFormattingHelper.js +92 -0
- package/dist/src/transformers/OnelineFormattingHelper.js.map +1 -0
- package/dist/src/transformers/QueryBuilder.d.ts +47 -13
- package/dist/src/transformers/QueryBuilder.js +433 -60
- package/dist/src/transformers/QueryBuilder.js.map +1 -1
- package/dist/src/transformers/SqlFormatter.d.ts +13 -1
- package/dist/src/transformers/SqlFormatter.js +20 -5
- package/dist/src/transformers/SqlFormatter.js.map +1 -1
- package/dist/src/transformers/SqlPrinter.d.ts +46 -8
- package/dist/src/transformers/SqlPrinter.js +596 -71
- package/dist/src/transformers/SqlPrinter.js.map +1 -1
- package/dist/src/types/Formatting.d.ts +8 -0
- package/dist/src/types/Formatting.js +3 -0
- package/dist/src/types/Formatting.js.map +1 -0
- package/dist/src/utils/ParserStringUtils.d.ts +6 -0
- package/dist/src/utils/ParserStringUtils.js +31 -0
- package/dist/src/utils/ParserStringUtils.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -4,6 +4,10 @@ exports.SqlPrinter = void 0;
|
|
|
4
4
|
const SqlPrintToken_1 = require("../models/SqlPrintToken");
|
|
5
5
|
const LinePrinter_1 = require("./LinePrinter");
|
|
6
6
|
const FormatOptionResolver_1 = require("./FormatOptionResolver");
|
|
7
|
+
const OnelineFormattingHelper_1 = require("./OnelineFormattingHelper");
|
|
8
|
+
const CREATE_TABLE_SINGLE_PAREN_KEYWORDS = new Set(['unique', 'check', 'key', 'index']);
|
|
9
|
+
const CREATE_TABLE_MULTI_PAREN_KEYWORDS = new Set(['primary key', 'foreign key', 'unique key']);
|
|
10
|
+
const CREATE_TABLE_PAREN_KEYWORDS_WITH_IDENTIFIER = new Set(['references']);
|
|
7
11
|
/**
|
|
8
12
|
* SqlPrinter formats a SqlPrintToken tree into a SQL string with flexible style options.
|
|
9
13
|
*
|
|
@@ -29,9 +33,11 @@ class SqlPrinter {
|
|
|
29
33
|
* @param options Optional style settings for pretty printing
|
|
30
34
|
*/
|
|
31
35
|
constructor(options) {
|
|
32
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t;
|
|
36
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u;
|
|
33
37
|
/** Track whether we are currently inside a WITH clause for full-oneline formatting */
|
|
34
38
|
this.insideWithClause = false;
|
|
39
|
+
/** Tracks nesting depth while formatting MERGE WHEN predicate segments */
|
|
40
|
+
this.mergeWhenPredicateDepth = 0;
|
|
35
41
|
/** Pending line comment that needs a forced newline before next token */
|
|
36
42
|
this.pendingLineCommentBreak = null;
|
|
37
43
|
/** Accumulates lines when reconstructing multi-line block comments inside CommentBlocks */
|
|
@@ -50,19 +56,32 @@ class SqlPrinter {
|
|
|
50
56
|
this.andBreak = (_e = options === null || options === void 0 ? void 0 : options.andBreak) !== null && _e !== void 0 ? _e : 'none';
|
|
51
57
|
this.orBreak = (_f = options === null || options === void 0 ? void 0 : options.orBreak) !== null && _f !== void 0 ? _f : 'none';
|
|
52
58
|
this.keywordCase = (_g = options === null || options === void 0 ? void 0 : options.keywordCase) !== null && _g !== void 0 ? _g : 'none';
|
|
53
|
-
this.
|
|
54
|
-
this.withClauseStyle = (
|
|
55
|
-
this.commentStyle = (
|
|
56
|
-
this.parenthesesOneLine = (
|
|
57
|
-
this.betweenOneLine = (
|
|
58
|
-
this.valuesOneLine = (
|
|
59
|
-
this.joinOneLine = (
|
|
60
|
-
this.caseOneLine = (
|
|
61
|
-
this.subqueryOneLine = (
|
|
62
|
-
this.indentNestedParentheses = (
|
|
59
|
+
this.commentExportMode = this.resolveCommentExportMode(options === null || options === void 0 ? void 0 : options.exportComment);
|
|
60
|
+
this.withClauseStyle = (_h = options === null || options === void 0 ? void 0 : options.withClauseStyle) !== null && _h !== void 0 ? _h : 'standard';
|
|
61
|
+
this.commentStyle = (_j = options === null || options === void 0 ? void 0 : options.commentStyle) !== null && _j !== void 0 ? _j : 'block';
|
|
62
|
+
this.parenthesesOneLine = (_k = options === null || options === void 0 ? void 0 : options.parenthesesOneLine) !== null && _k !== void 0 ? _k : false;
|
|
63
|
+
this.betweenOneLine = (_l = options === null || options === void 0 ? void 0 : options.betweenOneLine) !== null && _l !== void 0 ? _l : false;
|
|
64
|
+
this.valuesOneLine = (_m = options === null || options === void 0 ? void 0 : options.valuesOneLine) !== null && _m !== void 0 ? _m : false;
|
|
65
|
+
this.joinOneLine = (_o = options === null || options === void 0 ? void 0 : options.joinOneLine) !== null && _o !== void 0 ? _o : false;
|
|
66
|
+
this.caseOneLine = (_p = options === null || options === void 0 ? void 0 : options.caseOneLine) !== null && _p !== void 0 ? _p : false;
|
|
67
|
+
this.subqueryOneLine = (_q = options === null || options === void 0 ? void 0 : options.subqueryOneLine) !== null && _q !== void 0 ? _q : false;
|
|
68
|
+
this.indentNestedParentheses = (_r = options === null || options === void 0 ? void 0 : options.indentNestedParentheses) !== null && _r !== void 0 ? _r : false;
|
|
69
|
+
this.insertColumnsOneLine = (_s = options === null || options === void 0 ? void 0 : options.insertColumnsOneLine) !== null && _s !== void 0 ? _s : false;
|
|
70
|
+
this.whenOneLine = (_t = options === null || options === void 0 ? void 0 : options.whenOneLine) !== null && _t !== void 0 ? _t : false;
|
|
71
|
+
const onelineOptions = {
|
|
72
|
+
parenthesesOneLine: this.parenthesesOneLine,
|
|
73
|
+
betweenOneLine: this.betweenOneLine,
|
|
74
|
+
valuesOneLine: this.valuesOneLine,
|
|
75
|
+
joinOneLine: this.joinOneLine,
|
|
76
|
+
caseOneLine: this.caseOneLine,
|
|
77
|
+
subqueryOneLine: this.subqueryOneLine,
|
|
78
|
+
insertColumnsOneLine: this.insertColumnsOneLine,
|
|
79
|
+
withClauseStyle: this.withClauseStyle,
|
|
80
|
+
};
|
|
81
|
+
this.onelineHelper = new OnelineFormattingHelper_1.OnelineFormattingHelper(onelineOptions);
|
|
63
82
|
this.linePrinter = new LinePrinter_1.LinePrinter(this.indentChar, this.indentSize, this.newline, this.commaBreak);
|
|
64
83
|
// Initialize
|
|
65
|
-
this.indentIncrementContainers = new Set((
|
|
84
|
+
this.indentIncrementContainers = new Set((_u = options === null || options === void 0 ? void 0 : options.indentIncrementContainerTypes) !== null && _u !== void 0 ? _u : [
|
|
66
85
|
SqlPrintToken_1.SqlPrintTokenContainerType.SelectClause,
|
|
67
86
|
SqlPrintToken_1.SqlPrintTokenContainerType.FromClause,
|
|
68
87
|
SqlPrintToken_1.SqlPrintTokenContainerType.WhereClause,
|
|
@@ -82,7 +101,11 @@ class SqlPrinter {
|
|
|
82
101
|
SqlPrintToken_1.SqlPrintTokenContainerType.CaseThenValue,
|
|
83
102
|
SqlPrintToken_1.SqlPrintTokenContainerType.ElseClause,
|
|
84
103
|
SqlPrintToken_1.SqlPrintTokenContainerType.CaseElseValue,
|
|
85
|
-
SqlPrintToken_1.SqlPrintTokenContainerType.SimpleSelectQuery
|
|
104
|
+
SqlPrintToken_1.SqlPrintTokenContainerType.SimpleSelectQuery,
|
|
105
|
+
SqlPrintToken_1.SqlPrintTokenContainerType.CreateTableDefinition,
|
|
106
|
+
SqlPrintToken_1.SqlPrintTokenContainerType.AlterTableStatement,
|
|
107
|
+
SqlPrintToken_1.SqlPrintTokenContainerType.IndexColumnList,
|
|
108
|
+
SqlPrintToken_1.SqlPrintTokenContainerType.SetClause
|
|
86
109
|
// Note: CommentBlock is intentionally excluded from indentIncrementContainers
|
|
87
110
|
// because it serves as a grouping mechanism without affecting indentation.
|
|
88
111
|
// CaseExpression, SwitchCaseArgument, CaseKeyValuePair, and ElseClause
|
|
@@ -111,7 +134,42 @@ class SqlPrinter {
|
|
|
111
134
|
this.appendToken(token, level, undefined, 0, false);
|
|
112
135
|
return this.linePrinter.print();
|
|
113
136
|
}
|
|
114
|
-
|
|
137
|
+
// Resolve legacy boolean values into explicit comment export modes.
|
|
138
|
+
resolveCommentExportMode(option) {
|
|
139
|
+
if (option === undefined) {
|
|
140
|
+
return 'none';
|
|
141
|
+
}
|
|
142
|
+
if (option === true) {
|
|
143
|
+
return 'full';
|
|
144
|
+
}
|
|
145
|
+
if (option === false) {
|
|
146
|
+
return 'none';
|
|
147
|
+
}
|
|
148
|
+
return option;
|
|
149
|
+
}
|
|
150
|
+
// Determine whether the current mode allows emitting inline comments.
|
|
151
|
+
rendersInlineComments() {
|
|
152
|
+
return this.commentExportMode === 'full';
|
|
153
|
+
}
|
|
154
|
+
// Decide if a comment block or token should be rendered given its context.
|
|
155
|
+
shouldRenderComment(token, context) {
|
|
156
|
+
if (context === null || context === void 0 ? void 0 : context.forceRender) {
|
|
157
|
+
return this.commentExportMode !== 'none';
|
|
158
|
+
}
|
|
159
|
+
switch (this.commentExportMode) {
|
|
160
|
+
case 'full':
|
|
161
|
+
return true;
|
|
162
|
+
case 'none':
|
|
163
|
+
return false;
|
|
164
|
+
case 'header-only':
|
|
165
|
+
return token.isHeaderComment === true;
|
|
166
|
+
case 'top-header-only':
|
|
167
|
+
return token.isHeaderComment === true && Boolean(context === null || context === void 0 ? void 0 : context.isTopLevelContainer);
|
|
168
|
+
default:
|
|
169
|
+
return false;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
appendToken(token, level, parentContainerType, caseContextDepth = 0, indentParentActive = false, commentContext) {
|
|
115
173
|
// Track WITH clause context for full-oneline formatting
|
|
116
174
|
const wasInsideWithClause = this.insideWithClause;
|
|
117
175
|
if (token.containerType === SqlPrintToken_1.SqlPrintTokenContainerType.WithClause && this.withClauseStyle === 'full-oneline') {
|
|
@@ -120,6 +178,45 @@ class SqlPrinter {
|
|
|
120
178
|
if (this.shouldSkipToken(token)) {
|
|
121
179
|
return;
|
|
122
180
|
}
|
|
181
|
+
const containerIsTopLevel = parentContainerType === undefined;
|
|
182
|
+
let leadingCommentCount = 0;
|
|
183
|
+
// Collect leading comment blocks with context so we can respect the export mode.
|
|
184
|
+
const leadingCommentContexts = [];
|
|
185
|
+
if (token.innerTokens && token.innerTokens.length > 0) {
|
|
186
|
+
while (leadingCommentCount < token.innerTokens.length) {
|
|
187
|
+
const leadingCandidate = token.innerTokens[leadingCommentCount];
|
|
188
|
+
if (leadingCandidate.containerType !== SqlPrintToken_1.SqlPrintTokenContainerType.CommentBlock) {
|
|
189
|
+
break;
|
|
190
|
+
}
|
|
191
|
+
const context = {
|
|
192
|
+
position: 'leading',
|
|
193
|
+
isTopLevelContainer: containerIsTopLevel,
|
|
194
|
+
};
|
|
195
|
+
const shouldRender = this.shouldRenderComment(leadingCandidate, context);
|
|
196
|
+
leadingCommentContexts.push({ token: leadingCandidate, context, shouldRender });
|
|
197
|
+
leadingCommentCount++;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
const hasRenderableLeadingComment = leadingCommentContexts.some(item => item.shouldRender);
|
|
201
|
+
const leadingCommentIndentLevel = hasRenderableLeadingComment
|
|
202
|
+
? this.getLeadingCommentIndentLevel(parentContainerType, level)
|
|
203
|
+
: null;
|
|
204
|
+
if (hasRenderableLeadingComment
|
|
205
|
+
&& !this.isOnelineMode()
|
|
206
|
+
&& this.shouldAddNewlineBeforeLeadingComments(parentContainerType)) {
|
|
207
|
+
const currentLine = this.linePrinter.getCurrentLine();
|
|
208
|
+
if (currentLine.text.trim().length > 0) {
|
|
209
|
+
// Align the newline before leading comments with the intended comment indentation.
|
|
210
|
+
this.linePrinter.appendNewline(leadingCommentIndentLevel !== null && leadingCommentIndentLevel !== void 0 ? leadingCommentIndentLevel : level);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
for (const leading of leadingCommentContexts) {
|
|
214
|
+
if (!leading.shouldRender) {
|
|
215
|
+
continue;
|
|
216
|
+
}
|
|
217
|
+
// Keep leading comment processing aligned with its computed indentation level.
|
|
218
|
+
this.appendToken(leading.token, leadingCommentIndentLevel !== null && leadingCommentIndentLevel !== void 0 ? leadingCommentIndentLevel : level, token.containerType, caseContextDepth, indentParentActive, leading.context);
|
|
219
|
+
}
|
|
123
220
|
if (this.smartCommentBlockBuilder && token.containerType !== SqlPrintToken_1.SqlPrintTokenContainerType.CommentBlock && token.type !== SqlPrintToken_1.SqlPrintTokenType.commentNewline) {
|
|
124
221
|
this.flushSmartCommentBlockBuilder();
|
|
125
222
|
}
|
|
@@ -133,8 +230,17 @@ class SqlPrinter {
|
|
|
133
230
|
return;
|
|
134
231
|
}
|
|
135
232
|
}
|
|
233
|
+
// Fallback context applies when the caller did not provide comment metadata.
|
|
234
|
+
const effectiveCommentContext = commentContext !== null && commentContext !== void 0 ? commentContext : {
|
|
235
|
+
position: 'inline',
|
|
236
|
+
isTopLevelContainer: containerIsTopLevel,
|
|
237
|
+
};
|
|
136
238
|
if (token.containerType === SqlPrintToken_1.SqlPrintTokenContainerType.CommentBlock) {
|
|
137
|
-
this.
|
|
239
|
+
if (!this.shouldRenderComment(token, effectiveCommentContext)) {
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
const commentLevel = this.getCommentBaseIndentLevel(level, parentContainerType);
|
|
243
|
+
this.handleCommentBlockContainer(token, commentLevel, effectiveCommentContext);
|
|
138
244
|
return;
|
|
139
245
|
}
|
|
140
246
|
const current = this.linePrinter.getCurrentLine();
|
|
@@ -149,7 +255,7 @@ class SqlPrinter {
|
|
|
149
255
|
this.handleCommaToken(token, level, parentContainerType);
|
|
150
256
|
}
|
|
151
257
|
else if (token.type === SqlPrintToken_1.SqlPrintTokenType.parenthesis) {
|
|
152
|
-
this.handleParenthesisToken(token, level, indentParentActive);
|
|
258
|
+
this.handleParenthesisToken(token, level, indentParentActive, parentContainerType);
|
|
153
259
|
}
|
|
154
260
|
else if (token.type === SqlPrintToken_1.SqlPrintTokenType.operator && token.text.toLowerCase() === 'and') {
|
|
155
261
|
this.handleAndOperatorToken(token, level, parentContainerType, caseContextDepth);
|
|
@@ -157,34 +263,34 @@ class SqlPrinter {
|
|
|
157
263
|
else if (token.type === SqlPrintToken_1.SqlPrintTokenType.operator && token.text.toLowerCase() === 'or') {
|
|
158
264
|
this.handleOrOperatorToken(token, level, parentContainerType, caseContextDepth);
|
|
159
265
|
}
|
|
160
|
-
else if (token.containerType ===
|
|
266
|
+
else if (token.containerType === SqlPrintToken_1.SqlPrintTokenContainerType.JoinClause) {
|
|
161
267
|
this.handleJoinClauseToken(token, level);
|
|
162
268
|
}
|
|
163
269
|
else if (token.type === SqlPrintToken_1.SqlPrintTokenType.comment) {
|
|
164
|
-
if (this.
|
|
165
|
-
this.
|
|
270
|
+
if (this.shouldRenderComment(token, effectiveCommentContext)) {
|
|
271
|
+
const commentLevel = this.getCommentBaseIndentLevel(level, parentContainerType);
|
|
272
|
+
this.printCommentToken(token.text, commentLevel, parentContainerType);
|
|
166
273
|
}
|
|
167
274
|
}
|
|
168
275
|
else if (token.type === SqlPrintToken_1.SqlPrintTokenType.space) {
|
|
169
276
|
this.handleSpaceToken(token, parentContainerType);
|
|
170
277
|
}
|
|
171
278
|
else if (token.type === SqlPrintToken_1.SqlPrintTokenType.commentNewline) {
|
|
172
|
-
this.
|
|
279
|
+
if (this.whenOneLine && parentContainerType === SqlPrintToken_1.SqlPrintTokenContainerType.MergeWhenClause) {
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
282
|
+
const commentLevel = this.getCommentBaseIndentLevel(level, parentContainerType);
|
|
283
|
+
this.handleCommentNewlineToken(token, commentLevel);
|
|
173
284
|
}
|
|
174
285
|
else if (token.containerType === SqlPrintToken_1.SqlPrintTokenContainerType.CommonTable && this.withClauseStyle === 'cte-oneline') {
|
|
175
286
|
this.handleCteOnelineToken(token, level);
|
|
176
287
|
return; // Return early to avoid processing innerTokens
|
|
177
288
|
}
|
|
178
|
-
else if ((token
|
|
179
|
-
(token.containerType === SqlPrintToken_1.SqlPrintTokenContainerType.BetweenExpression && this.betweenOneLine) ||
|
|
180
|
-
(token.containerType === SqlPrintToken_1.SqlPrintTokenContainerType.Values && this.valuesOneLine) ||
|
|
181
|
-
(token.containerType === SqlPrintToken_1.SqlPrintTokenContainerType.JoinOnClause && this.joinOneLine) ||
|
|
182
|
-
(token.containerType === SqlPrintToken_1.SqlPrintTokenContainerType.CaseExpression && this.caseOneLine) ||
|
|
183
|
-
(token.containerType === SqlPrintToken_1.SqlPrintTokenContainerType.InlineQuery && this.subqueryOneLine)) {
|
|
289
|
+
else if (this.shouldFormatContainerAsOneline(token, shouldIndentNested)) {
|
|
184
290
|
this.handleOnelineToken(token, level);
|
|
185
291
|
return; // Return early to avoid processing innerTokens
|
|
186
292
|
}
|
|
187
|
-
else {
|
|
293
|
+
else if (!this.tryAppendInsertClauseTokenText(token.text, parentContainerType)) {
|
|
188
294
|
this.linePrinter.appendText(token.text);
|
|
189
295
|
}
|
|
190
296
|
// append keyword tokens(not indented)
|
|
@@ -198,6 +304,8 @@ class SqlPrinter {
|
|
|
198
304
|
let increasedIndent = false;
|
|
199
305
|
const shouldIncreaseIndent = this.indentIncrementContainers.has(token.containerType) || shouldIndentNested;
|
|
200
306
|
const delayIndentNewline = shouldIndentNested && token.containerType === SqlPrintToken_1.SqlPrintTokenContainerType.ParenExpression;
|
|
307
|
+
const isAlterTableStatement = token.containerType === SqlPrintToken_1.SqlPrintTokenContainerType.AlterTableStatement;
|
|
308
|
+
let deferAlterTableIndent = false;
|
|
201
309
|
if (!this.isOnelineMode() && shouldIncreaseIndent) {
|
|
202
310
|
if (this.insideWithClause && this.withClauseStyle === 'full-oneline') {
|
|
203
311
|
// Keep everything on one line for full-oneline WITH clauses.
|
|
@@ -207,15 +315,96 @@ class SqlPrinter {
|
|
|
207
315
|
increasedIndent = true;
|
|
208
316
|
}
|
|
209
317
|
else if (current.text !== '') {
|
|
210
|
-
|
|
318
|
+
if (isAlterTableStatement) {
|
|
319
|
+
// Delay the first line break so ALTER TABLE keeps the table name on the opening line.
|
|
320
|
+
innerLevel = level + 1;
|
|
321
|
+
increasedIndent = true;
|
|
322
|
+
deferAlterTableIndent = true;
|
|
323
|
+
}
|
|
324
|
+
else {
|
|
325
|
+
let targetIndentLevel = level + 1;
|
|
326
|
+
if (token.containerType === SqlPrintToken_1.SqlPrintTokenContainerType.SetClause &&
|
|
327
|
+
parentContainerType === SqlPrintToken_1.SqlPrintTokenContainerType.MergeUpdateAction) {
|
|
328
|
+
targetIndentLevel = level + 2;
|
|
329
|
+
}
|
|
330
|
+
if (this.shouldAlignCreateTableSelect(token.containerType, parentContainerType)) {
|
|
331
|
+
innerLevel = level;
|
|
332
|
+
increasedIndent = false;
|
|
333
|
+
this.linePrinter.appendNewline(level);
|
|
334
|
+
}
|
|
335
|
+
else {
|
|
336
|
+
innerLevel = targetIndentLevel;
|
|
337
|
+
increasedIndent = true;
|
|
338
|
+
this.linePrinter.appendNewline(innerLevel);
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
else if (token.containerType === SqlPrintToken_1.SqlPrintTokenContainerType.SetClause) {
|
|
343
|
+
innerLevel = parentContainerType === SqlPrintToken_1.SqlPrintTokenContainerType.MergeUpdateAction ? level + 2 : level + 1;
|
|
211
344
|
increasedIndent = true;
|
|
212
|
-
|
|
345
|
+
current.level = innerLevel;
|
|
213
346
|
}
|
|
214
347
|
}
|
|
215
|
-
|
|
348
|
+
const isMergeWhenClause = this.whenOneLine && token.containerType === SqlPrintToken_1.SqlPrintTokenContainerType.MergeWhenClause;
|
|
349
|
+
let mergePredicateActive = isMergeWhenClause;
|
|
350
|
+
let alterTableTableRendered = false;
|
|
351
|
+
let alterTableIndentInserted = false;
|
|
352
|
+
for (let i = leadingCommentCount; i < token.innerTokens.length; i++) {
|
|
216
353
|
const child = token.innerTokens[i];
|
|
354
|
+
const nextChild = token.innerTokens[i + 1];
|
|
355
|
+
const previousEntry = this.findPreviousSignificantToken(token.innerTokens, i);
|
|
356
|
+
const previousChild = previousEntry === null || previousEntry === void 0 ? void 0 : previousEntry.token;
|
|
357
|
+
const priorEntry = previousEntry ? this.findPreviousSignificantToken(token.innerTokens, previousEntry.index) : undefined;
|
|
358
|
+
const priorChild = priorEntry === null || priorEntry === void 0 ? void 0 : priorEntry.token;
|
|
359
|
+
const childIsAction = this.isMergeActionContainer(child);
|
|
360
|
+
const nextIsAction = this.isMergeActionContainer(nextChild);
|
|
361
|
+
const inMergePredicate = mergePredicateActive && !childIsAction;
|
|
362
|
+
if (isAlterTableStatement) {
|
|
363
|
+
if (child.containerType === SqlPrintToken_1.SqlPrintTokenContainerType.QualifiedName) {
|
|
364
|
+
// Track when the table name has been printed so we can defer indentation until after it.
|
|
365
|
+
alterTableTableRendered = true;
|
|
366
|
+
}
|
|
367
|
+
else if (deferAlterTableIndent && alterTableTableRendered && !alterTableIndentInserted) {
|
|
368
|
+
if (!this.isOnelineMode()) {
|
|
369
|
+
this.linePrinter.appendNewline(innerLevel);
|
|
370
|
+
}
|
|
371
|
+
alterTableIndentInserted = true;
|
|
372
|
+
deferAlterTableIndent = false;
|
|
373
|
+
if (!this.isOnelineMode() && child.type === SqlPrintToken_1.SqlPrintTokenType.space) {
|
|
374
|
+
// Drop the space token because we already emitted a newline.
|
|
375
|
+
continue;
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
if (child.type === SqlPrintToken_1.SqlPrintTokenType.space) {
|
|
380
|
+
if (this.shouldConvertSpaceToClauseBreak(token.containerType, nextChild)) {
|
|
381
|
+
if (!this.isOnelineMode()) {
|
|
382
|
+
// Use a dedicated indent resolver so clause breaks can shift indentation for nested blocks.
|
|
383
|
+
const clauseBreakIndent = this.getClauseBreakIndentLevel(token.containerType, innerLevel);
|
|
384
|
+
this.linePrinter.appendNewline(clauseBreakIndent);
|
|
385
|
+
}
|
|
386
|
+
if (isMergeWhenClause && nextIsAction) {
|
|
387
|
+
mergePredicateActive = false;
|
|
388
|
+
}
|
|
389
|
+
continue;
|
|
390
|
+
}
|
|
391
|
+
this.handleSpaceToken(child, token.containerType, nextChild, previousChild, priorChild);
|
|
392
|
+
continue;
|
|
393
|
+
}
|
|
217
394
|
const childIndentParentActive = token.containerType === SqlPrintToken_1.SqlPrintTokenContainerType.ParenExpression ? shouldIndentNested : indentParentActive;
|
|
218
|
-
|
|
395
|
+
if (inMergePredicate) {
|
|
396
|
+
this.mergeWhenPredicateDepth++;
|
|
397
|
+
}
|
|
398
|
+
const childCommentContext = child.containerType === SqlPrintToken_1.SqlPrintTokenContainerType.CommentBlock
|
|
399
|
+
? { position: 'inline', isTopLevelContainer: containerIsTopLevel }
|
|
400
|
+
: undefined;
|
|
401
|
+
this.appendToken(child, innerLevel, token.containerType, nextCaseContextDepth, childIndentParentActive, childCommentContext);
|
|
402
|
+
if (inMergePredicate) {
|
|
403
|
+
this.mergeWhenPredicateDepth--;
|
|
404
|
+
}
|
|
405
|
+
if (childIsAction && isMergeWhenClause) {
|
|
406
|
+
mergePredicateActive = false;
|
|
407
|
+
}
|
|
219
408
|
}
|
|
220
409
|
if (this.smartCommentBlockBuilder && this.smartCommentBlockBuilder.mode === 'line') {
|
|
221
410
|
this.flushSmartCommentBlockBuilder();
|
|
@@ -268,11 +457,13 @@ class SqlPrinter {
|
|
|
268
457
|
}
|
|
269
458
|
handleKeywordToken(token, level, parentContainerType, caseContextDepth = 0) {
|
|
270
459
|
const lower = token.text.toLowerCase();
|
|
271
|
-
if (lower === 'and' &&
|
|
460
|
+
if (lower === 'and' &&
|
|
461
|
+
(this.andBreak !== 'none' || (this.whenOneLine && parentContainerType === SqlPrintToken_1.SqlPrintTokenContainerType.MergeWhenClause))) {
|
|
272
462
|
this.handleAndOperatorToken(token, level, parentContainerType, caseContextDepth);
|
|
273
463
|
return;
|
|
274
464
|
}
|
|
275
|
-
else if (lower === 'or' &&
|
|
465
|
+
else if (lower === 'or' &&
|
|
466
|
+
(this.orBreak !== 'none' || (this.whenOneLine && parentContainerType === SqlPrintToken_1.SqlPrintTokenContainerType.MergeWhenClause))) {
|
|
276
467
|
this.handleOrOperatorToken(token, level, parentContainerType, caseContextDepth);
|
|
277
468
|
return;
|
|
278
469
|
}
|
|
@@ -281,18 +472,50 @@ class SqlPrinter {
|
|
|
281
472
|
this.linePrinter.appendText(text);
|
|
282
473
|
return;
|
|
283
474
|
}
|
|
475
|
+
this.ensureSpaceBeforeKeyword();
|
|
284
476
|
this.linePrinter.appendText(text);
|
|
285
477
|
}
|
|
478
|
+
ensureSpaceBeforeKeyword() {
|
|
479
|
+
const currentLine = this.linePrinter.getCurrentLine();
|
|
480
|
+
if (currentLine.text === '') {
|
|
481
|
+
return;
|
|
482
|
+
}
|
|
483
|
+
const lastChar = currentLine.text[currentLine.text.length - 1];
|
|
484
|
+
if (lastChar === '(') {
|
|
485
|
+
return;
|
|
486
|
+
}
|
|
487
|
+
this.ensureTrailingSpace();
|
|
488
|
+
}
|
|
489
|
+
ensureTrailingSpace() {
|
|
490
|
+
const currentLine = this.linePrinter.getCurrentLine();
|
|
491
|
+
if (currentLine.text === '') {
|
|
492
|
+
return;
|
|
493
|
+
}
|
|
494
|
+
if (!currentLine.text.endsWith(' ')) {
|
|
495
|
+
currentLine.text += ' ';
|
|
496
|
+
}
|
|
497
|
+
currentLine.text = currentLine.text.replace(/\s+$/, ' ');
|
|
498
|
+
}
|
|
499
|
+
/**
|
|
500
|
+
* Normalizes INSERT column list token text when one-line formatting is active.
|
|
501
|
+
*/
|
|
502
|
+
tryAppendInsertClauseTokenText(text, parentContainerType) {
|
|
503
|
+
const currentLineText = this.linePrinter.getCurrentLine().text;
|
|
504
|
+
const result = this.onelineHelper.formatInsertClauseToken(text, parentContainerType, currentLineText, () => this.ensureTrailingSpace());
|
|
505
|
+
if (!result.handled) {
|
|
506
|
+
return false;
|
|
507
|
+
}
|
|
508
|
+
if (result.text) {
|
|
509
|
+
this.linePrinter.appendText(result.text);
|
|
510
|
+
}
|
|
511
|
+
return true;
|
|
512
|
+
}
|
|
286
513
|
handleCommaToken(token, level, parentContainerType) {
|
|
287
514
|
const text = token.text;
|
|
288
515
|
const isWithinWithClause = parentContainerType === SqlPrintToken_1.SqlPrintTokenContainerType.WithClause;
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
effectiveCommaBreak = this.cteCommaBreak;
|
|
293
|
-
}
|
|
294
|
-
else if (isWithinValuesClause) {
|
|
295
|
-
effectiveCommaBreak = this.valuesCommaBreak;
|
|
516
|
+
let effectiveCommaBreak = this.onelineHelper.resolveCommaBreak(parentContainerType, this.commaBreak, this.cteCommaBreak, this.valuesCommaBreak);
|
|
517
|
+
if (parentContainerType === SqlPrintToken_1.SqlPrintTokenContainerType.SetClause) {
|
|
518
|
+
effectiveCommaBreak = 'before';
|
|
296
519
|
}
|
|
297
520
|
// Skip comma newlines when inside WITH clause with full-oneline style
|
|
298
521
|
if (this.insideWithClause && this.withClauseStyle === 'full-oneline') {
|
|
@@ -310,6 +533,14 @@ class SqlPrinter {
|
|
|
310
533
|
}
|
|
311
534
|
if (!(this.insideWithClause && this.withClauseStyle === 'full-oneline')) {
|
|
312
535
|
this.linePrinter.appendNewline(level);
|
|
536
|
+
if (this.newline === ' ') {
|
|
537
|
+
// Remove the spacer introduced by space newlines so commas attach directly to the preceding token.
|
|
538
|
+
this.linePrinter.trimTrailingWhitespaceFromPreviousLine();
|
|
539
|
+
}
|
|
540
|
+
if (parentContainerType === SqlPrintToken_1.SqlPrintTokenContainerType.InsertClause) {
|
|
541
|
+
// Align comma-prefixed column entries under the INSERT column indentation.
|
|
542
|
+
this.linePrinter.getCurrentLine().level = level + 1;
|
|
543
|
+
}
|
|
313
544
|
}
|
|
314
545
|
this.linePrinter.appendText(text);
|
|
315
546
|
if (previousCommaBreak !== 'before') {
|
|
@@ -338,6 +569,9 @@ class SqlPrinter {
|
|
|
338
569
|
this.linePrinter.commaBreak = 'none';
|
|
339
570
|
}
|
|
340
571
|
this.linePrinter.appendText(text);
|
|
572
|
+
if (this.onelineHelper.isInsertClauseOneline(parentContainerType)) {
|
|
573
|
+
this.ensureTrailingSpace();
|
|
574
|
+
}
|
|
341
575
|
if (previousCommaBreak !== 'none') {
|
|
342
576
|
this.linePrinter.commaBreak = previousCommaBreak;
|
|
343
577
|
}
|
|
@@ -352,6 +586,11 @@ class SqlPrinter {
|
|
|
352
586
|
this.linePrinter.appendText(text);
|
|
353
587
|
return;
|
|
354
588
|
}
|
|
589
|
+
if (this.whenOneLine &&
|
|
590
|
+
(parentContainerType === SqlPrintToken_1.SqlPrintTokenContainerType.MergeWhenClause || this.mergeWhenPredicateDepth > 0)) {
|
|
591
|
+
this.linePrinter.appendText(text);
|
|
592
|
+
return;
|
|
593
|
+
}
|
|
355
594
|
if (this.andBreak === 'before') {
|
|
356
595
|
// Skip newline when inside WITH clause with full-oneline style
|
|
357
596
|
if (!(this.insideWithClause && this.withClauseStyle === 'full-oneline')) {
|
|
@@ -370,20 +609,32 @@ class SqlPrinter {
|
|
|
370
609
|
this.linePrinter.appendText(text);
|
|
371
610
|
}
|
|
372
611
|
}
|
|
373
|
-
handleParenthesisToken(token, level, indentParentActive) {
|
|
612
|
+
handleParenthesisToken(token, level, indentParentActive, parentContainerType) {
|
|
374
613
|
if (token.text === '(') {
|
|
375
614
|
this.linePrinter.appendText(token.text);
|
|
376
|
-
if (
|
|
377
|
-
|
|
615
|
+
if ((parentContainerType === SqlPrintToken_1.SqlPrintTokenContainerType.InsertClause ||
|
|
616
|
+
parentContainerType === SqlPrintToken_1.SqlPrintTokenContainerType.MergeInsertAction) &&
|
|
617
|
+
this.insertColumnsOneLine) {
|
|
618
|
+
return;
|
|
619
|
+
}
|
|
620
|
+
if (!this.isOnelineMode()) {
|
|
621
|
+
if (this.shouldBreakAfterOpeningParen(parentContainerType)) {
|
|
622
|
+
this.linePrinter.appendNewline(level + 1);
|
|
623
|
+
}
|
|
624
|
+
else if (indentParentActive && !(this.insideWithClause && this.withClauseStyle === 'full-oneline')) {
|
|
378
625
|
this.linePrinter.appendNewline(level);
|
|
379
626
|
}
|
|
380
627
|
}
|
|
381
628
|
return;
|
|
382
629
|
}
|
|
383
|
-
if (token.text === ')' &&
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
630
|
+
if (token.text === ')' && !this.isOnelineMode()) {
|
|
631
|
+
if (this.shouldBreakBeforeClosingParen(parentContainerType)) {
|
|
632
|
+
this.linePrinter.appendNewline(Math.max(level, 0));
|
|
633
|
+
this.linePrinter.appendText(token.text);
|
|
634
|
+
return;
|
|
635
|
+
}
|
|
636
|
+
if (indentParentActive && !(this.insideWithClause && this.withClauseStyle === 'full-oneline')) {
|
|
637
|
+
const closingLevel = Math.max(level - 1, 0);
|
|
387
638
|
this.linePrinter.appendNewline(closingLevel);
|
|
388
639
|
}
|
|
389
640
|
}
|
|
@@ -396,6 +647,11 @@ class SqlPrinter {
|
|
|
396
647
|
this.linePrinter.appendText(text);
|
|
397
648
|
return;
|
|
398
649
|
}
|
|
650
|
+
if (this.whenOneLine &&
|
|
651
|
+
(parentContainerType === SqlPrintToken_1.SqlPrintTokenContainerType.MergeWhenClause || this.mergeWhenPredicateDepth > 0)) {
|
|
652
|
+
this.linePrinter.appendText(text);
|
|
653
|
+
return;
|
|
654
|
+
}
|
|
399
655
|
if (this.orBreak === 'before') {
|
|
400
656
|
// Insert a newline before OR unless WITH full-oneline mode suppresses breaks.
|
|
401
657
|
if (!(this.insideWithClause && this.withClauseStyle === 'full-oneline')) {
|
|
@@ -445,37 +701,140 @@ class SqlPrinter {
|
|
|
445
701
|
}
|
|
446
702
|
handleJoinClauseToken(token, level) {
|
|
447
703
|
const text = this.applyKeywordCase(token.text);
|
|
448
|
-
// before join clause, add newline
|
|
449
|
-
if (
|
|
704
|
+
// before join clause, add newline when multiline formatting is allowed
|
|
705
|
+
if (this.onelineHelper.shouldInsertJoinNewline(this.insideWithClause)) {
|
|
450
706
|
this.linePrinter.appendNewline(level);
|
|
451
707
|
}
|
|
452
708
|
this.linePrinter.appendText(text);
|
|
453
709
|
}
|
|
710
|
+
/**
|
|
711
|
+
* Decides whether the current container should collapse into a single line.
|
|
712
|
+
*/
|
|
713
|
+
shouldFormatContainerAsOneline(token, shouldIndentNested) {
|
|
714
|
+
return this.onelineHelper.shouldFormatContainer(token, shouldIndentNested);
|
|
715
|
+
}
|
|
716
|
+
/**
|
|
717
|
+
* Detects an INSERT column list that must stay on a single line.
|
|
718
|
+
*/
|
|
719
|
+
isInsertClauseOneline(parentContainerType) {
|
|
720
|
+
return this.onelineHelper.isInsertClauseOneline(parentContainerType);
|
|
721
|
+
}
|
|
454
722
|
/**
|
|
455
723
|
* Handles space tokens with context-aware filtering.
|
|
456
724
|
* Skips spaces in CommentBlocks when in specific CTE modes to prevent duplication.
|
|
457
725
|
*/
|
|
458
|
-
handleSpaceToken(token, parentContainerType) {
|
|
726
|
+
handleSpaceToken(token, parentContainerType, nextToken, previousToken, priorToken) {
|
|
459
727
|
if (this.smartCommentBlockBuilder && this.smartCommentBlockBuilder.mode === 'line') {
|
|
460
728
|
this.flushSmartCommentBlockBuilder();
|
|
461
729
|
}
|
|
462
|
-
|
|
730
|
+
const currentLineText = this.linePrinter.getCurrentLine().text;
|
|
731
|
+
if (this.onelineHelper.shouldSkipInsertClauseSpace(parentContainerType, nextToken, currentLineText)) {
|
|
732
|
+
return;
|
|
733
|
+
}
|
|
734
|
+
if (this.onelineHelper.shouldSkipCommentBlockSpace(parentContainerType, this.insideWithClause)) {
|
|
463
735
|
const currentLine = this.linePrinter.getCurrentLine();
|
|
464
736
|
if (currentLine.text !== '' && !currentLine.text.endsWith(' ')) {
|
|
465
737
|
this.linePrinter.appendText(' ');
|
|
466
738
|
}
|
|
467
739
|
return;
|
|
468
740
|
}
|
|
741
|
+
// Skip redundant spaces before structural parentheses in CREATE TABLE DDL.
|
|
742
|
+
if (this.shouldSkipSpaceBeforeParenthesis(parentContainerType, nextToken, previousToken, priorToken)) {
|
|
743
|
+
return;
|
|
744
|
+
}
|
|
469
745
|
this.linePrinter.appendText(token.text);
|
|
470
746
|
}
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
this.
|
|
478
|
-
|
|
747
|
+
findPreviousSignificantToken(tokens, index) {
|
|
748
|
+
for (let i = index - 1; i >= 0; i--) {
|
|
749
|
+
const candidate = tokens[i];
|
|
750
|
+
if (candidate.type === SqlPrintToken_1.SqlPrintTokenType.space || candidate.type === SqlPrintToken_1.SqlPrintTokenType.commentNewline) {
|
|
751
|
+
continue;
|
|
752
|
+
}
|
|
753
|
+
if (candidate.type === SqlPrintToken_1.SqlPrintTokenType.comment && !this.rendersInlineComments()) {
|
|
754
|
+
continue;
|
|
755
|
+
}
|
|
756
|
+
return { token: candidate, index: i };
|
|
757
|
+
}
|
|
758
|
+
return undefined;
|
|
759
|
+
}
|
|
760
|
+
shouldSkipSpaceBeforeParenthesis(parentContainerType, nextToken, previousToken, priorToken) {
|
|
761
|
+
if (!nextToken || nextToken.type !== SqlPrintToken_1.SqlPrintTokenType.parenthesis || nextToken.text !== '(') {
|
|
762
|
+
return false;
|
|
763
|
+
}
|
|
764
|
+
if (!parentContainerType || !this.isCreateTableSpacingContext(parentContainerType)) {
|
|
765
|
+
return false;
|
|
766
|
+
}
|
|
767
|
+
if (!previousToken) {
|
|
768
|
+
return false;
|
|
769
|
+
}
|
|
770
|
+
if (this.isCreateTableNameToken(previousToken, parentContainerType)) {
|
|
771
|
+
return true;
|
|
772
|
+
}
|
|
773
|
+
if (this.isCreateTableConstraintKeyword(previousToken, parentContainerType)) {
|
|
774
|
+
return true;
|
|
775
|
+
}
|
|
776
|
+
if (priorToken && this.isCreateTableConstraintKeyword(priorToken, parentContainerType)) {
|
|
777
|
+
if (this.isIdentifierAttachedToConstraint(previousToken, priorToken, parentContainerType)) {
|
|
778
|
+
return true;
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
return false;
|
|
782
|
+
}
|
|
783
|
+
shouldAlignCreateTableSelect(containerType, parentContainerType) {
|
|
784
|
+
return containerType === SqlPrintToken_1.SqlPrintTokenContainerType.SimpleSelectQuery &&
|
|
785
|
+
parentContainerType === SqlPrintToken_1.SqlPrintTokenContainerType.CreateTableQuery;
|
|
786
|
+
}
|
|
787
|
+
isCreateTableSpacingContext(parentContainerType) {
|
|
788
|
+
switch (parentContainerType) {
|
|
789
|
+
case SqlPrintToken_1.SqlPrintTokenContainerType.CreateTableQuery:
|
|
790
|
+
case SqlPrintToken_1.SqlPrintTokenContainerType.CreateTableDefinition:
|
|
791
|
+
case SqlPrintToken_1.SqlPrintTokenContainerType.TableConstraintDefinition:
|
|
792
|
+
case SqlPrintToken_1.SqlPrintTokenContainerType.ColumnConstraintDefinition:
|
|
793
|
+
case SqlPrintToken_1.SqlPrintTokenContainerType.ReferenceDefinition:
|
|
794
|
+
return true;
|
|
795
|
+
default:
|
|
796
|
+
return false;
|
|
797
|
+
}
|
|
798
|
+
}
|
|
799
|
+
isCreateTableNameToken(previousToken, parentContainerType) {
|
|
800
|
+
if (parentContainerType !== SqlPrintToken_1.SqlPrintTokenContainerType.CreateTableQuery) {
|
|
801
|
+
return false;
|
|
802
|
+
}
|
|
803
|
+
return previousToken.containerType === SqlPrintToken_1.SqlPrintTokenContainerType.QualifiedName;
|
|
804
|
+
}
|
|
805
|
+
isCreateTableConstraintKeyword(token, parentContainerType) {
|
|
806
|
+
if (token.type !== SqlPrintToken_1.SqlPrintTokenType.keyword) {
|
|
807
|
+
return false;
|
|
808
|
+
}
|
|
809
|
+
const text = token.text.toLowerCase();
|
|
810
|
+
if (parentContainerType === SqlPrintToken_1.SqlPrintTokenContainerType.ReferenceDefinition) {
|
|
811
|
+
return CREATE_TABLE_PAREN_KEYWORDS_WITH_IDENTIFIER.has(text);
|
|
812
|
+
}
|
|
813
|
+
if (CREATE_TABLE_SINGLE_PAREN_KEYWORDS.has(text)) {
|
|
814
|
+
return true;
|
|
815
|
+
}
|
|
816
|
+
if (CREATE_TABLE_MULTI_PAREN_KEYWORDS.has(text)) {
|
|
817
|
+
return true;
|
|
818
|
+
}
|
|
819
|
+
return false;
|
|
820
|
+
}
|
|
821
|
+
isIdentifierAttachedToConstraint(token, keywordToken, parentContainerType) {
|
|
822
|
+
if (!token) {
|
|
823
|
+
return false;
|
|
824
|
+
}
|
|
825
|
+
if (parentContainerType === SqlPrintToken_1.SqlPrintTokenContainerType.ReferenceDefinition) {
|
|
826
|
+
return token.containerType === SqlPrintToken_1.SqlPrintTokenContainerType.QualifiedName &&
|
|
827
|
+
CREATE_TABLE_PAREN_KEYWORDS_WITH_IDENTIFIER.has(keywordToken.text.toLowerCase());
|
|
828
|
+
}
|
|
829
|
+
if (parentContainerType === SqlPrintToken_1.SqlPrintTokenContainerType.TableConstraintDefinition ||
|
|
830
|
+
parentContainerType === SqlPrintToken_1.SqlPrintTokenContainerType.ColumnConstraintDefinition) {
|
|
831
|
+
const normalized = keywordToken.text.toLowerCase();
|
|
832
|
+
if (CREATE_TABLE_SINGLE_PAREN_KEYWORDS.has(normalized) ||
|
|
833
|
+
CREATE_TABLE_MULTI_PAREN_KEYWORDS.has(normalized)) {
|
|
834
|
+
return token.containerType === SqlPrintToken_1.SqlPrintTokenContainerType.IdentifierString;
|
|
835
|
+
}
|
|
836
|
+
}
|
|
837
|
+
return false;
|
|
479
838
|
}
|
|
480
839
|
printCommentToken(text, level, parentContainerType) {
|
|
481
840
|
const trimmed = text.trim();
|
|
@@ -498,11 +857,12 @@ class SqlPrinter {
|
|
|
498
857
|
const lineText = content ? `-- ${content}` : '--';
|
|
499
858
|
if (parentContainerType === SqlPrintToken_1.SqlPrintTokenContainerType.CommentBlock) {
|
|
500
859
|
this.linePrinter.appendText(lineText);
|
|
501
|
-
this.pendingLineCommentBreak = level;
|
|
860
|
+
this.pendingLineCommentBreak = this.resolveCommentIndentLevel(level, parentContainerType);
|
|
502
861
|
}
|
|
503
862
|
else {
|
|
504
863
|
this.linePrinter.appendText(lineText);
|
|
505
|
-
this.
|
|
864
|
+
const effectiveLevel = this.resolveCommentIndentLevel(level, parentContainerType);
|
|
865
|
+
this.linePrinter.appendNewline(effectiveLevel);
|
|
506
866
|
}
|
|
507
867
|
}
|
|
508
868
|
}
|
|
@@ -523,10 +883,11 @@ class SqlPrinter {
|
|
|
523
883
|
}
|
|
524
884
|
if (trimmed.startsWith('--')) {
|
|
525
885
|
if (parentContainerType === SqlPrintToken_1.SqlPrintTokenContainerType.CommentBlock) {
|
|
526
|
-
this.pendingLineCommentBreak = level;
|
|
886
|
+
this.pendingLineCommentBreak = this.resolveCommentIndentLevel(level, parentContainerType);
|
|
527
887
|
}
|
|
528
888
|
else {
|
|
529
|
-
this.
|
|
889
|
+
const effectiveLevel = this.resolveCommentIndentLevel(level, parentContainerType);
|
|
890
|
+
this.linePrinter.appendNewline(effectiveLevel);
|
|
530
891
|
}
|
|
531
892
|
}
|
|
532
893
|
}
|
|
@@ -569,11 +930,8 @@ class SqlPrinter {
|
|
|
569
930
|
this.flushSmartCommentBlockBuilder();
|
|
570
931
|
return false;
|
|
571
932
|
}
|
|
572
|
-
handleCommentBlockContainer(token, level) {
|
|
933
|
+
handleCommentBlockContainer(token, level, context) {
|
|
573
934
|
var _a;
|
|
574
|
-
if (!this.exportComment) {
|
|
575
|
-
return;
|
|
576
|
-
}
|
|
577
935
|
if (this.commentStyle !== 'smart') {
|
|
578
936
|
const rawLines = this.extractRawCommentBlockLines(token);
|
|
579
937
|
if (rawLines.length > 0) {
|
|
@@ -583,7 +941,13 @@ class SqlPrinter {
|
|
|
583
941
|
return;
|
|
584
942
|
}
|
|
585
943
|
for (const child of token.innerTokens) {
|
|
586
|
-
|
|
944
|
+
// Force inner comment tokens to render once the block is approved.
|
|
945
|
+
const childContext = {
|
|
946
|
+
position: context.position,
|
|
947
|
+
isTopLevelContainer: context.isTopLevelContainer,
|
|
948
|
+
forceRender: true,
|
|
949
|
+
};
|
|
950
|
+
this.appendToken(child, level, token.containerType, 0, false, childContext);
|
|
587
951
|
}
|
|
588
952
|
return;
|
|
589
953
|
}
|
|
@@ -645,7 +1009,8 @@ class SqlPrinter {
|
|
|
645
1009
|
}
|
|
646
1010
|
const { lines, level, mode } = this.smartCommentBlockBuilder;
|
|
647
1011
|
if (mode === 'line') {
|
|
648
|
-
|
|
1012
|
+
const meaningfulLineCount = lines.filter(line => line.trim() !== '').length;
|
|
1013
|
+
if (meaningfulLineCount > 1) {
|
|
649
1014
|
const blockText = this.buildBlockComment(lines, level);
|
|
650
1015
|
this.linePrinter.appendText(blockText);
|
|
651
1016
|
}
|
|
@@ -808,6 +1173,19 @@ class SqlPrinter {
|
|
|
808
1173
|
.replace(/\/\*/g, '\\/\\*')
|
|
809
1174
|
.replace(/\*\//g, '*\\/');
|
|
810
1175
|
}
|
|
1176
|
+
getCommentBaseIndentLevel(level, parentContainerType) {
|
|
1177
|
+
if (!parentContainerType) {
|
|
1178
|
+
return level;
|
|
1179
|
+
}
|
|
1180
|
+
const clauseAlignedLevel = this.getClauseBreakIndentLevel(parentContainerType, level);
|
|
1181
|
+
return Math.max(level, clauseAlignedLevel);
|
|
1182
|
+
}
|
|
1183
|
+
resolveCommentIndentLevel(level, parentContainerType) {
|
|
1184
|
+
var _a;
|
|
1185
|
+
const baseLevel = this.getCommentBaseIndentLevel(level, parentContainerType);
|
|
1186
|
+
const currentLevel = (_a = this.linePrinter.getCurrentLine().level) !== null && _a !== void 0 ? _a : baseLevel;
|
|
1187
|
+
return Math.max(baseLevel, currentLevel);
|
|
1188
|
+
}
|
|
811
1189
|
/**
|
|
812
1190
|
* Handles commentNewline tokens with conditional newline behavior.
|
|
813
1191
|
* In multiline mode (newline !== ' '), adds a newline after comments.
|
|
@@ -838,6 +1216,39 @@ class SqlPrinter {
|
|
|
838
1216
|
return (this.insideWithClause && this.withClauseStyle === 'full-oneline') ||
|
|
839
1217
|
this.withClauseStyle === 'cte-oneline';
|
|
840
1218
|
}
|
|
1219
|
+
shouldAddNewlineBeforeLeadingComments(parentType) {
|
|
1220
|
+
if (!parentType) {
|
|
1221
|
+
return false;
|
|
1222
|
+
}
|
|
1223
|
+
if (parentType === SqlPrintToken_1.SqlPrintTokenContainerType.TupleExpression) {
|
|
1224
|
+
return true;
|
|
1225
|
+
}
|
|
1226
|
+
if (parentType === SqlPrintToken_1.SqlPrintTokenContainerType.InsertClause ||
|
|
1227
|
+
parentType === SqlPrintToken_1.SqlPrintTokenContainerType.MergeInsertAction) {
|
|
1228
|
+
return !this.insertColumnsOneLine;
|
|
1229
|
+
}
|
|
1230
|
+
if (parentType === SqlPrintToken_1.SqlPrintTokenContainerType.SetClause) {
|
|
1231
|
+
return true;
|
|
1232
|
+
}
|
|
1233
|
+
if (parentType === SqlPrintToken_1.SqlPrintTokenContainerType.SelectClause) {
|
|
1234
|
+
return true;
|
|
1235
|
+
}
|
|
1236
|
+
return false;
|
|
1237
|
+
}
|
|
1238
|
+
getLeadingCommentIndentLevel(parentType, currentLevel) {
|
|
1239
|
+
if (parentType === SqlPrintToken_1.SqlPrintTokenContainerType.TupleExpression) {
|
|
1240
|
+
return currentLevel + 1;
|
|
1241
|
+
}
|
|
1242
|
+
if (parentType === SqlPrintToken_1.SqlPrintTokenContainerType.InsertClause ||
|
|
1243
|
+
parentType === SqlPrintToken_1.SqlPrintTokenContainerType.MergeInsertAction ||
|
|
1244
|
+
parentType === SqlPrintToken_1.SqlPrintTokenContainerType.SelectClause) {
|
|
1245
|
+
return currentLevel + 1;
|
|
1246
|
+
}
|
|
1247
|
+
if (parentType === SqlPrintToken_1.SqlPrintTokenContainerType.SetClause) {
|
|
1248
|
+
return currentLevel + 1;
|
|
1249
|
+
}
|
|
1250
|
+
return currentLevel;
|
|
1251
|
+
}
|
|
841
1252
|
/**
|
|
842
1253
|
* Determines if the printer is in oneliner mode.
|
|
843
1254
|
* Oneliner mode uses single spaces instead of actual newlines.
|
|
@@ -870,9 +1281,10 @@ class SqlPrinter {
|
|
|
870
1281
|
andBreak: this.andBreak,
|
|
871
1282
|
orBreak: this.orBreak,
|
|
872
1283
|
keywordCase: this.keywordCase,
|
|
873
|
-
exportComment:
|
|
1284
|
+
exportComment: 'none',
|
|
874
1285
|
withClauseStyle: 'standard', // Prevent recursive processing
|
|
875
1286
|
indentNestedParentheses: false,
|
|
1287
|
+
insertColumnsOneLine: this.insertColumnsOneLine,
|
|
876
1288
|
});
|
|
877
1289
|
}
|
|
878
1290
|
/**
|
|
@@ -885,6 +1297,117 @@ class SqlPrinter {
|
|
|
885
1297
|
const cleanedResult = this.cleanDuplicateSpaces(onelineResult);
|
|
886
1298
|
this.linePrinter.appendText(cleanedResult);
|
|
887
1299
|
}
|
|
1300
|
+
getClauseBreakIndentLevel(parentType, level) {
|
|
1301
|
+
if (!parentType) {
|
|
1302
|
+
return level;
|
|
1303
|
+
}
|
|
1304
|
+
switch (parentType) {
|
|
1305
|
+
case SqlPrintToken_1.SqlPrintTokenContainerType.MergeWhenClause:
|
|
1306
|
+
// Actions under WHEN clauses should be indented one level deeper than the WHEN line.
|
|
1307
|
+
return level + 1;
|
|
1308
|
+
case SqlPrintToken_1.SqlPrintTokenContainerType.MergeUpdateAction:
|
|
1309
|
+
case SqlPrintToken_1.SqlPrintTokenContainerType.MergeDeleteAction:
|
|
1310
|
+
case SqlPrintToken_1.SqlPrintTokenContainerType.MergeInsertAction:
|
|
1311
|
+
// Keep MERGE actions and their follow-up keywords (e.g., VALUES, WHERE) aligned with the action keyword.
|
|
1312
|
+
return level + 1;
|
|
1313
|
+
default:
|
|
1314
|
+
return level;
|
|
1315
|
+
}
|
|
1316
|
+
}
|
|
1317
|
+
isMergeActionContainer(token) {
|
|
1318
|
+
if (!token) {
|
|
1319
|
+
return false;
|
|
1320
|
+
}
|
|
1321
|
+
switch (token.containerType) {
|
|
1322
|
+
case SqlPrintToken_1.SqlPrintTokenContainerType.MergeUpdateAction:
|
|
1323
|
+
case SqlPrintToken_1.SqlPrintTokenContainerType.MergeDeleteAction:
|
|
1324
|
+
case SqlPrintToken_1.SqlPrintTokenContainerType.MergeInsertAction:
|
|
1325
|
+
case SqlPrintToken_1.SqlPrintTokenContainerType.MergeDoNothingAction:
|
|
1326
|
+
return true;
|
|
1327
|
+
default:
|
|
1328
|
+
return false;
|
|
1329
|
+
}
|
|
1330
|
+
}
|
|
1331
|
+
shouldBreakAfterOpeningParen(parentType) {
|
|
1332
|
+
if (!parentType) {
|
|
1333
|
+
return false;
|
|
1334
|
+
}
|
|
1335
|
+
if (parentType === SqlPrintToken_1.SqlPrintTokenContainerType.InsertClause ||
|
|
1336
|
+
parentType === SqlPrintToken_1.SqlPrintTokenContainerType.MergeInsertAction) {
|
|
1337
|
+
return !this.isInsertClauseOneline(parentType);
|
|
1338
|
+
}
|
|
1339
|
+
return false;
|
|
1340
|
+
}
|
|
1341
|
+
shouldBreakBeforeClosingParen(parentType) {
|
|
1342
|
+
if (!parentType) {
|
|
1343
|
+
return false;
|
|
1344
|
+
}
|
|
1345
|
+
if (parentType === SqlPrintToken_1.SqlPrintTokenContainerType.InsertClause ||
|
|
1346
|
+
parentType === SqlPrintToken_1.SqlPrintTokenContainerType.MergeInsertAction) {
|
|
1347
|
+
return !this.isInsertClauseOneline(parentType);
|
|
1348
|
+
}
|
|
1349
|
+
return false;
|
|
1350
|
+
}
|
|
1351
|
+
shouldConvertSpaceToClauseBreak(parentType, nextToken) {
|
|
1352
|
+
if (!parentType || !nextToken) {
|
|
1353
|
+
return false;
|
|
1354
|
+
}
|
|
1355
|
+
const nextKeyword = nextToken.type === SqlPrintToken_1.SqlPrintTokenType.keyword ? nextToken.text.toLowerCase() : null;
|
|
1356
|
+
const nextContainer = nextToken.containerType;
|
|
1357
|
+
if (parentType === SqlPrintToken_1.SqlPrintTokenContainerType.MergeQuery) {
|
|
1358
|
+
// Break before USING blocks and before each WHEN clause to mirror statement structure.
|
|
1359
|
+
if (nextKeyword === 'using') {
|
|
1360
|
+
return true;
|
|
1361
|
+
}
|
|
1362
|
+
if (nextContainer === SqlPrintToken_1.SqlPrintTokenContainerType.MergeWhenClause) {
|
|
1363
|
+
return true;
|
|
1364
|
+
}
|
|
1365
|
+
}
|
|
1366
|
+
if (parentType === SqlPrintToken_1.SqlPrintTokenContainerType.MergeWhenClause) {
|
|
1367
|
+
// Force the action to start on the next line with additional indentation.
|
|
1368
|
+
if (nextContainer === SqlPrintToken_1.SqlPrintTokenContainerType.MergeUpdateAction ||
|
|
1369
|
+
nextContainer === SqlPrintToken_1.SqlPrintTokenContainerType.MergeDeleteAction ||
|
|
1370
|
+
nextContainer === SqlPrintToken_1.SqlPrintTokenContainerType.MergeInsertAction ||
|
|
1371
|
+
nextContainer === SqlPrintToken_1.SqlPrintTokenContainerType.MergeDoNothingAction) {
|
|
1372
|
+
return true;
|
|
1373
|
+
}
|
|
1374
|
+
}
|
|
1375
|
+
if (parentType === SqlPrintToken_1.SqlPrintTokenContainerType.UpdateQuery) {
|
|
1376
|
+
if (nextKeyword === 'set' || nextKeyword === 'from' || nextKeyword === 'where' || nextKeyword === 'returning') {
|
|
1377
|
+
return true;
|
|
1378
|
+
}
|
|
1379
|
+
}
|
|
1380
|
+
if (parentType === SqlPrintToken_1.SqlPrintTokenContainerType.InsertQuery) {
|
|
1381
|
+
if (nextKeyword === 'returning') {
|
|
1382
|
+
return true;
|
|
1383
|
+
}
|
|
1384
|
+
if (nextKeyword && (nextKeyword.startsWith('select') || nextKeyword.startsWith('values'))) {
|
|
1385
|
+
return true;
|
|
1386
|
+
}
|
|
1387
|
+
if (nextContainer === SqlPrintToken_1.SqlPrintTokenContainerType.ValuesQuery || nextContainer === SqlPrintToken_1.SqlPrintTokenContainerType.SimpleSelectQuery) {
|
|
1388
|
+
return true;
|
|
1389
|
+
}
|
|
1390
|
+
if (nextContainer === SqlPrintToken_1.SqlPrintTokenContainerType.InsertClause) {
|
|
1391
|
+
return true;
|
|
1392
|
+
}
|
|
1393
|
+
}
|
|
1394
|
+
if (parentType === SqlPrintToken_1.SqlPrintTokenContainerType.DeleteQuery) {
|
|
1395
|
+
if (nextKeyword === 'using' || nextKeyword === 'where' || nextKeyword === 'returning') {
|
|
1396
|
+
return true;
|
|
1397
|
+
}
|
|
1398
|
+
}
|
|
1399
|
+
if (parentType === SqlPrintToken_1.SqlPrintTokenContainerType.MergeUpdateAction || parentType === SqlPrintToken_1.SqlPrintTokenContainerType.MergeDeleteAction) {
|
|
1400
|
+
if (nextKeyword === 'where') {
|
|
1401
|
+
return true;
|
|
1402
|
+
}
|
|
1403
|
+
}
|
|
1404
|
+
if (parentType === SqlPrintToken_1.SqlPrintTokenContainerType.MergeInsertAction) {
|
|
1405
|
+
if (nextKeyword && (nextKeyword.startsWith('values') || nextKeyword === 'default values')) {
|
|
1406
|
+
return true;
|
|
1407
|
+
}
|
|
1408
|
+
}
|
|
1409
|
+
return false;
|
|
1410
|
+
}
|
|
888
1411
|
/**
|
|
889
1412
|
* Creates a unified SqlPrinter instance configured for oneline formatting.
|
|
890
1413
|
* Works for all oneline options: parentheses, BETWEEN, VALUES, JOIN, CASE, subqueries.
|
|
@@ -901,7 +1424,8 @@ class SqlPrinter {
|
|
|
901
1424
|
andBreak: 'none', // Disable AND-based line breaks
|
|
902
1425
|
orBreak: 'none', // Disable OR-based line breaks
|
|
903
1426
|
keywordCase: this.keywordCase,
|
|
904
|
-
exportComment: this.
|
|
1427
|
+
exportComment: this.commentExportMode,
|
|
1428
|
+
commentStyle: this.commentStyle,
|
|
905
1429
|
withClauseStyle: 'standard',
|
|
906
1430
|
parenthesesOneLine: false, // Prevent recursive processing (avoid infinite loops)
|
|
907
1431
|
betweenOneLine: false, // Prevent recursive processing (avoid infinite loops)
|
|
@@ -910,6 +1434,7 @@ class SqlPrinter {
|
|
|
910
1434
|
caseOneLine: false, // Prevent recursive processing (avoid infinite loops)
|
|
911
1435
|
subqueryOneLine: false, // Prevent recursive processing (avoid infinite loops)
|
|
912
1436
|
indentNestedParentheses: false,
|
|
1437
|
+
insertColumnsOneLine: this.insertColumnsOneLine,
|
|
913
1438
|
});
|
|
914
1439
|
}
|
|
915
1440
|
/**
|