rawsql-ts 0.11.43-beta → 0.12.0
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 +195 -0
- package/dist/esm/src/models/DDLStatements.js +201 -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 +36 -0
- package/dist/esm/src/models/SqlPrintToken.js +35 -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/AnalyzeStatementParser.d.ts +13 -0
- package/dist/esm/src/parsers/AnalyzeStatementParser.js +90 -0
- package/dist/esm/src/parsers/AnalyzeStatementParser.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/ExplainStatementParser.d.ts +23 -0
- package/dist/esm/src/parsers/ExplainStatementParser.js +185 -0
- package/dist/esm/src/parsers/ExplainStatementParser.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/ParenExpressionParser.js +25 -0
- package/dist/esm/src/parsers/ParenExpressionParser.js.map +1 -1
- 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 +40 -0
- package/dist/esm/src/parsers/SqlParser.js +400 -0
- package/dist/esm/src/parsers/SqlParser.js.map +1 -0
- package/dist/esm/src/parsers/SqlPrintTokenParser.d.ts +65 -3
- package/dist/esm/src/parsers/SqlPrintTokenParser.js +1145 -38
- 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 +50 -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 +95 -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 +47 -8
- package/dist/esm/src/transformers/SqlPrinter.js +625 -72
- 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 +195 -0
- package/dist/src/models/DDLStatements.js +216 -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 +36 -0
- package/dist/src/models/SqlPrintToken.js +35 -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/AnalyzeStatementParser.d.ts +13 -0
- package/dist/src/parsers/AnalyzeStatementParser.js +94 -0
- package/dist/src/parsers/AnalyzeStatementParser.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/ExplainStatementParser.d.ts +23 -0
- package/dist/src/parsers/ExplainStatementParser.js +189 -0
- package/dist/src/parsers/ExplainStatementParser.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/ParenExpressionParser.js +25 -0
- package/dist/src/parsers/ParenExpressionParser.js.map +1 -1
- 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 +40 -0
- package/dist/src/parsers/SqlParser.js +409 -0
- package/dist/src/parsers/SqlParser.js.map +1 -0
- package/dist/src/parsers/SqlPrintTokenParser.d.ts +65 -3
- package/dist/src/parsers/SqlPrintTokenParser.js +1143 -36
- 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 +50 -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 +99 -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 +47 -8
- package/dist/src/transformers/SqlPrinter.js +625 -72
- 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 +3 -3
|
@@ -11,7 +11,10 @@ const IdentifierDecorator_1 = require("./IdentifierDecorator");
|
|
|
11
11
|
const ParameterDecorator_1 = require("./ParameterDecorator");
|
|
12
12
|
const InsertQuery_1 = require("../models/InsertQuery");
|
|
13
13
|
const UpdateQuery_1 = require("../models/UpdateQuery");
|
|
14
|
+
const DeleteQuery_1 = require("../models/DeleteQuery");
|
|
14
15
|
const CreateTableQuery_1 = require("../models/CreateTableQuery");
|
|
16
|
+
const MergeQuery_1 = require("../models/MergeQuery");
|
|
17
|
+
const DDLStatements_1 = require("../models/DDLStatements");
|
|
15
18
|
var ParameterStyle;
|
|
16
19
|
(function (ParameterStyle) {
|
|
17
20
|
ParameterStyle["Anonymous"] = "anonymous";
|
|
@@ -23,36 +26,45 @@ exports.PRESETS = {
|
|
|
23
26
|
identifierEscape: { start: '`', end: '`' },
|
|
24
27
|
parameterSymbol: '?',
|
|
25
28
|
parameterStyle: ParameterStyle.Anonymous,
|
|
29
|
+
constraintStyle: 'mysql',
|
|
26
30
|
},
|
|
27
31
|
postgres: {
|
|
28
32
|
identifierEscape: { start: '"', end: '"' },
|
|
29
33
|
parameterSymbol: '$',
|
|
30
34
|
parameterStyle: ParameterStyle.Indexed,
|
|
35
|
+
castStyle: 'postgres',
|
|
36
|
+
constraintStyle: 'postgres',
|
|
31
37
|
},
|
|
32
38
|
postgresWithNamedParams: {
|
|
33
39
|
identifierEscape: { start: '"', end: '"' },
|
|
34
40
|
parameterSymbol: ':',
|
|
35
41
|
parameterStyle: ParameterStyle.Named,
|
|
42
|
+
castStyle: 'postgres',
|
|
43
|
+
constraintStyle: 'postgres',
|
|
36
44
|
},
|
|
37
45
|
sqlserver: {
|
|
38
46
|
identifierEscape: { start: '[', end: ']' },
|
|
39
47
|
parameterSymbol: '@',
|
|
40
48
|
parameterStyle: ParameterStyle.Named,
|
|
49
|
+
constraintStyle: 'postgres',
|
|
41
50
|
},
|
|
42
51
|
sqlite: {
|
|
43
52
|
identifierEscape: { start: '"', end: '"' },
|
|
44
53
|
parameterSymbol: ':',
|
|
45
54
|
parameterStyle: ParameterStyle.Named,
|
|
55
|
+
constraintStyle: 'postgres',
|
|
46
56
|
},
|
|
47
57
|
oracle: {
|
|
48
58
|
identifierEscape: { start: '"', end: '"' },
|
|
49
59
|
parameterSymbol: ':',
|
|
50
60
|
parameterStyle: ParameterStyle.Named,
|
|
61
|
+
constraintStyle: 'postgres',
|
|
51
62
|
},
|
|
52
63
|
clickhouse: {
|
|
53
64
|
identifierEscape: { start: '`', end: '`' },
|
|
54
65
|
parameterSymbol: '?',
|
|
55
66
|
parameterStyle: ParameterStyle.Anonymous,
|
|
67
|
+
constraintStyle: 'postgres',
|
|
56
68
|
},
|
|
57
69
|
firebird: {
|
|
58
70
|
identifierEscape: { start: '"', end: '"' },
|
|
@@ -83,6 +95,7 @@ exports.PRESETS = {
|
|
|
83
95
|
identifierEscape: { start: '"', end: '"' },
|
|
84
96
|
parameterSymbol: '$',
|
|
85
97
|
parameterStyle: ParameterStyle.Indexed,
|
|
98
|
+
castStyle: 'postgres',
|
|
86
99
|
},
|
|
87
100
|
athena: {
|
|
88
101
|
identifierEscape: { start: '"', end: '"' },
|
|
@@ -108,6 +121,7 @@ exports.PRESETS = {
|
|
|
108
121
|
identifierEscape: { start: '"', end: '"' },
|
|
109
122
|
parameterSymbol: '$',
|
|
110
123
|
parameterStyle: ParameterStyle.Indexed,
|
|
124
|
+
castStyle: 'postgres',
|
|
111
125
|
},
|
|
112
126
|
flinksql: {
|
|
113
127
|
identifierEscape: { start: '`', end: '`' },
|
|
@@ -142,9 +156,10 @@ class SqlPrintTokenParser {
|
|
|
142
156
|
return this._selfHandlingComponentTypes;
|
|
143
157
|
}
|
|
144
158
|
constructor(options) {
|
|
145
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
159
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
146
160
|
this.handlers = new Map();
|
|
147
161
|
this.index = 1;
|
|
162
|
+
this.joinConditionContexts = [];
|
|
148
163
|
if (options === null || options === void 0 ? void 0 : options.preset) {
|
|
149
164
|
const preset = options.preset;
|
|
150
165
|
options = { ...preset, ...options };
|
|
@@ -158,6 +173,9 @@ class SqlPrintTokenParser {
|
|
|
158
173
|
start: (_e = (_d = options === null || options === void 0 ? void 0 : options.identifierEscape) === null || _d === void 0 ? void 0 : _d.start) !== null && _e !== void 0 ? _e : '"',
|
|
159
174
|
end: (_g = (_f = options === null || options === void 0 ? void 0 : options.identifierEscape) === null || _f === void 0 ? void 0 : _f.end) !== null && _g !== void 0 ? _g : '"'
|
|
160
175
|
});
|
|
176
|
+
this.castStyle = (_h = options === null || options === void 0 ? void 0 : options.castStyle) !== null && _h !== void 0 ? _h : 'standard';
|
|
177
|
+
this.constraintStyle = (_j = options === null || options === void 0 ? void 0 : options.constraintStyle) !== null && _j !== void 0 ? _j : 'postgres';
|
|
178
|
+
this.normalizeJoinConditionOrder = (_k = options === null || options === void 0 ? void 0 : options.joinConditionOrderByDeclaration) !== null && _k !== void 0 ? _k : false;
|
|
161
179
|
this.handlers.set(ValueComponent_1.ValueList.kind, (expr) => this.visitValueList(expr));
|
|
162
180
|
this.handlers.set(ValueComponent_1.ColumnReference.kind, (expr) => this.visitColumnReference(expr));
|
|
163
181
|
this.handlers.set(ValueComponent_1.QualifiedName.kind, (expr) => this.visitQualifiedName(expr));
|
|
@@ -229,10 +247,34 @@ class SqlPrintTokenParser {
|
|
|
229
247
|
this.handlers.set(Clause_1.InsertClause.kind, (expr) => this.visitInsertClause(expr));
|
|
230
248
|
this.handlers.set(UpdateQuery_1.UpdateQuery.kind, (expr) => this.visitUpdateQuery(expr));
|
|
231
249
|
this.handlers.set(Clause_1.UpdateClause.kind, (expr) => this.visitUpdateClause(expr));
|
|
250
|
+
this.handlers.set(DeleteQuery_1.DeleteQuery.kind, (expr) => this.visitDeleteQuery(expr));
|
|
251
|
+
this.handlers.set(Clause_1.DeleteClause.kind, (expr) => this.visitDeleteClause(expr));
|
|
252
|
+
this.handlers.set(Clause_1.UsingClause.kind, (expr) => this.visitUsingClause(expr));
|
|
232
253
|
this.handlers.set(Clause_1.SetClause.kind, (expr) => this.visitSetClause(expr));
|
|
233
254
|
this.handlers.set(Clause_1.SetClauseItem.kind, (expr) => this.visitSetClauseItem(expr));
|
|
234
255
|
this.handlers.set(Clause_1.ReturningClause.kind, (expr) => this.visitReturningClause(expr));
|
|
235
256
|
this.handlers.set(CreateTableQuery_1.CreateTableQuery.kind, (expr) => this.visitCreateTableQuery(expr));
|
|
257
|
+
this.handlers.set(CreateTableQuery_1.TableColumnDefinition.kind, (expr) => this.visitTableColumnDefinition(expr));
|
|
258
|
+
this.handlers.set(CreateTableQuery_1.ColumnConstraintDefinition.kind, (expr) => this.visitColumnConstraintDefinition(expr));
|
|
259
|
+
this.handlers.set(CreateTableQuery_1.TableConstraintDefinition.kind, (expr) => this.visitTableConstraintDefinition(expr));
|
|
260
|
+
this.handlers.set(CreateTableQuery_1.ReferenceDefinition.kind, (expr) => this.visitReferenceDefinition(expr));
|
|
261
|
+
this.handlers.set(DDLStatements_1.CreateIndexStatement.kind, (expr) => this.visitCreateIndexStatement(expr));
|
|
262
|
+
this.handlers.set(DDLStatements_1.IndexColumnDefinition.kind, (expr) => this.visitIndexColumnDefinition(expr));
|
|
263
|
+
this.handlers.set(DDLStatements_1.DropTableStatement.kind, (expr) => this.visitDropTableStatement(expr));
|
|
264
|
+
this.handlers.set(DDLStatements_1.DropIndexStatement.kind, (expr) => this.visitDropIndexStatement(expr));
|
|
265
|
+
this.handlers.set(DDLStatements_1.AlterTableStatement.kind, (expr) => this.visitAlterTableStatement(expr));
|
|
266
|
+
this.handlers.set(DDLStatements_1.AlterTableAddConstraint.kind, (expr) => this.visitAlterTableAddConstraint(expr));
|
|
267
|
+
this.handlers.set(DDLStatements_1.AlterTableDropConstraint.kind, (expr) => this.visitAlterTableDropConstraint(expr));
|
|
268
|
+
this.handlers.set(DDLStatements_1.AlterTableDropColumn.kind, (expr) => this.visitAlterTableDropColumn(expr));
|
|
269
|
+
this.handlers.set(DDLStatements_1.DropConstraintStatement.kind, (expr) => this.visitDropConstraintStatement(expr));
|
|
270
|
+
this.handlers.set(DDLStatements_1.ExplainStatement.kind, (expr) => this.visitExplainStatement(expr));
|
|
271
|
+
this.handlers.set(DDLStatements_1.AnalyzeStatement.kind, (expr) => this.visitAnalyzeStatement(expr));
|
|
272
|
+
this.handlers.set(MergeQuery_1.MergeQuery.kind, (expr) => this.visitMergeQuery(expr));
|
|
273
|
+
this.handlers.set(MergeQuery_1.MergeWhenClause.kind, (expr) => this.visitMergeWhenClause(expr));
|
|
274
|
+
this.handlers.set(MergeQuery_1.MergeUpdateAction.kind, (expr) => this.visitMergeUpdateAction(expr));
|
|
275
|
+
this.handlers.set(MergeQuery_1.MergeDeleteAction.kind, (expr) => this.visitMergeDeleteAction(expr));
|
|
276
|
+
this.handlers.set(MergeQuery_1.MergeInsertAction.kind, (expr) => this.visitMergeInsertAction(expr));
|
|
277
|
+
this.handlers.set(MergeQuery_1.MergeDoNothingAction.kind, (expr) => this.visitMergeDoNothingAction(expr));
|
|
236
278
|
}
|
|
237
279
|
/**
|
|
238
280
|
* Pretty-prints a BinarySelectQuery (e.g., UNION, INTERSECT, EXCEPT).
|
|
@@ -253,7 +295,7 @@ class SqlPrintTokenParser {
|
|
|
253
295
|
token.innerTokens.push(mergedHeaderComment);
|
|
254
296
|
}
|
|
255
297
|
else {
|
|
256
|
-
const headerCommentBlocks = this.createCommentBlocks(arg.headerComments);
|
|
298
|
+
const headerCommentBlocks = this.createCommentBlocks(arg.headerComments, true);
|
|
257
299
|
token.innerTokens.push(...headerCommentBlocks);
|
|
258
300
|
}
|
|
259
301
|
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
@@ -501,10 +543,11 @@ class SqlPrintTokenParser {
|
|
|
501
543
|
}
|
|
502
544
|
/**
|
|
503
545
|
* Creates CommentBlock containers for the given comments.
|
|
504
|
-
* Each CommentBlock contains: Comment -> CommentNewline -> Space
|
|
505
|
-
*
|
|
546
|
+
* Each CommentBlock contains: Comment -> CommentNewline -> Space.
|
|
547
|
+
* @param comments Raw comment strings to convert into CommentBlock tokens.
|
|
548
|
+
* @param isHeaderComment Marks the generated blocks as originating from header comments when true.
|
|
506
549
|
*/
|
|
507
|
-
createCommentBlocks(comments) {
|
|
550
|
+
createCommentBlocks(comments, isHeaderComment = false) {
|
|
508
551
|
// Create individual comment blocks for each comment entry
|
|
509
552
|
const commentBlocks = [];
|
|
510
553
|
for (const comment of comments) {
|
|
@@ -512,7 +555,7 @@ class SqlPrintTokenParser {
|
|
|
512
555
|
const trimmed = comment.trim();
|
|
513
556
|
const isSeparatorLine = /^[-=_+*#]+$/.test(trimmed);
|
|
514
557
|
if (trimmed || isSeparatorLine || comment === '') {
|
|
515
|
-
commentBlocks.push(this.createSingleCommentBlock(comment));
|
|
558
|
+
commentBlocks.push(this.createSingleCommentBlock(comment, isHeaderComment));
|
|
516
559
|
}
|
|
517
560
|
}
|
|
518
561
|
return commentBlocks;
|
|
@@ -552,8 +595,11 @@ class SqlPrintTokenParser {
|
|
|
552
595
|
* - Multiline mode: Comment + newline (space is filtered as leading space)
|
|
553
596
|
* - Oneliner mode: Comment + space (commentNewline is skipped)
|
|
554
597
|
*/
|
|
555
|
-
createSingleCommentBlock(comment) {
|
|
598
|
+
createSingleCommentBlock(comment, isHeaderComment = false) {
|
|
556
599
|
const commentBlock = new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.container, '', SqlPrintToken_1.SqlPrintTokenContainerType.CommentBlock);
|
|
600
|
+
if (isHeaderComment) {
|
|
601
|
+
commentBlock.markAsHeaderComment();
|
|
602
|
+
}
|
|
557
603
|
// Add comment token - preserve original format for line comments
|
|
558
604
|
const commentToken = new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.comment, this.formatComment(comment));
|
|
559
605
|
commentBlock.innerTokens.push(commentToken);
|
|
@@ -668,10 +714,11 @@ class SqlPrintTokenParser {
|
|
|
668
714
|
const afterComments = component.getPositionedComments('after');
|
|
669
715
|
if (afterComments.length > 0) {
|
|
670
716
|
const commentBlocks = this.createCommentBlocks(afterComments);
|
|
671
|
-
|
|
672
|
-
|
|
717
|
+
const closingIndex = token.innerTokens.length - 1;
|
|
718
|
+
let insertIndex = closingIndex + 1;
|
|
673
719
|
for (const commentBlock of commentBlocks) {
|
|
674
|
-
token.innerTokens.splice(insertIndex
|
|
720
|
+
token.innerTokens.splice(insertIndex, 0, SqlPrintTokenParser.SPACE_TOKEN, commentBlock);
|
|
721
|
+
insertIndex += 2;
|
|
675
722
|
}
|
|
676
723
|
}
|
|
677
724
|
}
|
|
@@ -751,6 +798,7 @@ class SqlPrintTokenParser {
|
|
|
751
798
|
}
|
|
752
799
|
createHeaderMultiLineCommentBlock(headerComments) {
|
|
753
800
|
const commentBlock = new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.container, '', SqlPrintToken_1.SqlPrintTokenContainerType.CommentBlock);
|
|
801
|
+
commentBlock.markAsHeaderComment();
|
|
754
802
|
if (headerComments.length === 0) {
|
|
755
803
|
const commentToken = new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.comment, '/* */');
|
|
756
804
|
commentBlock.innerTokens.push(commentToken);
|
|
@@ -821,7 +869,6 @@ class SqlPrintTokenParser {
|
|
|
821
869
|
}
|
|
822
870
|
visitFunctionCall(arg) {
|
|
823
871
|
const token = new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.container, '', SqlPrintToken_1.SqlPrintTokenContainerType.FunctionCall);
|
|
824
|
-
this.addComponentComments(token, arg);
|
|
825
872
|
token.innerTokens.push(arg.qualifiedName.accept(this));
|
|
826
873
|
token.innerTokens.push(SqlPrintTokenParser.PAREN_OPEN_TOKEN);
|
|
827
874
|
if (arg.argument) {
|
|
@@ -859,6 +906,7 @@ class SqlPrintTokenParser {
|
|
|
859
906
|
token.innerTokens.push(SqlPrintTokenParser.PAREN_CLOSE_TOKEN);
|
|
860
907
|
}
|
|
861
908
|
}
|
|
909
|
+
this.addComponentComments(token, arg);
|
|
862
910
|
return token;
|
|
863
911
|
}
|
|
864
912
|
visitUnaryExpression(arg) {
|
|
@@ -1063,9 +1111,22 @@ class SqlPrintTokenParser {
|
|
|
1063
1111
|
}
|
|
1064
1112
|
visitCastExpression(arg) {
|
|
1065
1113
|
const token = new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.container, '', SqlPrintToken_1.SqlPrintTokenContainerType.CastExpression);
|
|
1114
|
+
// Use PostgreSQL-specific :: casts only when the preset explicitly opts in.
|
|
1115
|
+
if (this.castStyle === 'postgres') {
|
|
1116
|
+
token.innerTokens.push(this.visit(arg.input));
|
|
1117
|
+
token.innerTokens.push(new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.operator, '::'));
|
|
1118
|
+
token.innerTokens.push(this.visit(arg.castType));
|
|
1119
|
+
return token;
|
|
1120
|
+
}
|
|
1121
|
+
// Default to ANSI-compliant CAST(expression AS type) syntax for broader compatibility.
|
|
1122
|
+
token.innerTokens.push(new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.keyword, 'cast'));
|
|
1123
|
+
token.innerTokens.push(SqlPrintTokenParser.PAREN_OPEN_TOKEN);
|
|
1066
1124
|
token.innerTokens.push(this.visit(arg.input));
|
|
1067
|
-
token.innerTokens.push(
|
|
1125
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
1126
|
+
token.innerTokens.push(new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.keyword, 'as'));
|
|
1127
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
1068
1128
|
token.innerTokens.push(this.visit(arg.castType));
|
|
1129
|
+
token.innerTokens.push(SqlPrintTokenParser.PAREN_CLOSE_TOKEN);
|
|
1069
1130
|
return token;
|
|
1070
1131
|
}
|
|
1071
1132
|
visitCaseExpression(arg) {
|
|
@@ -1076,20 +1137,148 @@ class SqlPrintTokenParser {
|
|
|
1076
1137
|
// Clear positioned comments to prevent duplicate processing
|
|
1077
1138
|
arg.positionedComments = null;
|
|
1078
1139
|
}
|
|
1140
|
+
const promotedComments = [];
|
|
1141
|
+
const trailingSwitchComments = this.extractSwitchAfterComments(arg.switchCase);
|
|
1142
|
+
let conditionToken = null;
|
|
1143
|
+
if (arg.condition) {
|
|
1144
|
+
conditionToken = this.visit(arg.condition);
|
|
1145
|
+
promotedComments.push(...this.collectCaseLeadingCommentBlocks(conditionToken));
|
|
1146
|
+
}
|
|
1147
|
+
const switchToken = this.visit(arg.switchCase);
|
|
1148
|
+
promotedComments.push(...this.collectCaseLeadingCommentsFromSwitch(switchToken));
|
|
1149
|
+
if (promotedComments.length > 0) {
|
|
1150
|
+
token.innerTokens.push(...promotedComments);
|
|
1151
|
+
}
|
|
1079
1152
|
// Add the CASE keyword
|
|
1080
1153
|
token.innerTokens.push(new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.keyword, 'case'));
|
|
1081
1154
|
// Add the condition if exists
|
|
1082
|
-
if (
|
|
1155
|
+
if (conditionToken) {
|
|
1083
1156
|
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
1084
|
-
token.innerTokens.push(
|
|
1157
|
+
token.innerTokens.push(conditionToken);
|
|
1085
1158
|
}
|
|
1086
1159
|
// Add the WHEN/THEN pairs and ELSE
|
|
1087
|
-
token.innerTokens.push(
|
|
1160
|
+
token.innerTokens.push(switchToken);
|
|
1088
1161
|
// Add the END keyword
|
|
1089
1162
|
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
1090
1163
|
token.innerTokens.push(new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.keyword, 'end'));
|
|
1164
|
+
if (trailingSwitchComments.length > 0) {
|
|
1165
|
+
token.innerTokens.push(new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.commentNewline, ''));
|
|
1166
|
+
const trailingBlocks = this.createCommentBlocks(trailingSwitchComments);
|
|
1167
|
+
token.innerTokens.push(...trailingBlocks);
|
|
1168
|
+
}
|
|
1091
1169
|
return token;
|
|
1092
1170
|
}
|
|
1171
|
+
extractSwitchAfterComments(arg) {
|
|
1172
|
+
if (!arg.positionedComments || arg.positionedComments.length === 0) {
|
|
1173
|
+
return [];
|
|
1174
|
+
}
|
|
1175
|
+
const trailing = [];
|
|
1176
|
+
const retained = [];
|
|
1177
|
+
for (const entry of arg.positionedComments) {
|
|
1178
|
+
if (entry.position === 'after') {
|
|
1179
|
+
trailing.push(...entry.comments);
|
|
1180
|
+
}
|
|
1181
|
+
else {
|
|
1182
|
+
retained.push(entry);
|
|
1183
|
+
}
|
|
1184
|
+
}
|
|
1185
|
+
arg.positionedComments = retained.length > 0 ? retained : null;
|
|
1186
|
+
return trailing;
|
|
1187
|
+
}
|
|
1188
|
+
collectCaseLeadingCommentsFromSwitch(token) {
|
|
1189
|
+
if (!token.innerTokens || token.innerTokens.length === 0) {
|
|
1190
|
+
return [];
|
|
1191
|
+
}
|
|
1192
|
+
const pairToken = token.innerTokens.find(child => child.containerType === SqlPrintToken_1.SqlPrintTokenContainerType.CaseKeyValuePair);
|
|
1193
|
+
if (!pairToken) {
|
|
1194
|
+
return [];
|
|
1195
|
+
}
|
|
1196
|
+
const keyToken = this.findCaseKeyToken(pairToken);
|
|
1197
|
+
if (!keyToken) {
|
|
1198
|
+
return [];
|
|
1199
|
+
}
|
|
1200
|
+
return this.collectCaseLeadingCommentBlocks(keyToken);
|
|
1201
|
+
}
|
|
1202
|
+
findCaseKeyToken(pairToken) {
|
|
1203
|
+
for (const child of pairToken.innerTokens) {
|
|
1204
|
+
if (child.containerType === SqlPrintToken_1.SqlPrintTokenContainerType.CommentBlock) {
|
|
1205
|
+
continue;
|
|
1206
|
+
}
|
|
1207
|
+
if (child.type === SqlPrintToken_1.SqlPrintTokenType.space) {
|
|
1208
|
+
continue;
|
|
1209
|
+
}
|
|
1210
|
+
if (child.type === SqlPrintToken_1.SqlPrintTokenType.keyword) {
|
|
1211
|
+
continue;
|
|
1212
|
+
}
|
|
1213
|
+
if (child.containerType === SqlPrintToken_1.SqlPrintTokenContainerType.CaseThenValue) {
|
|
1214
|
+
continue;
|
|
1215
|
+
}
|
|
1216
|
+
return child;
|
|
1217
|
+
}
|
|
1218
|
+
return undefined;
|
|
1219
|
+
}
|
|
1220
|
+
collectCaseLeadingCommentBlocks(token) {
|
|
1221
|
+
if (!token.innerTokens || token.innerTokens.length === 0) {
|
|
1222
|
+
return [];
|
|
1223
|
+
}
|
|
1224
|
+
const collected = [];
|
|
1225
|
+
this.collectCaseLeadingCommentBlocksRecursive(token, collected, new Set(), 0);
|
|
1226
|
+
return collected;
|
|
1227
|
+
}
|
|
1228
|
+
collectCaseLeadingCommentBlocksRecursive(token, collected, seen, depth) {
|
|
1229
|
+
if (!token.innerTokens || token.innerTokens.length === 0) {
|
|
1230
|
+
return;
|
|
1231
|
+
}
|
|
1232
|
+
let removedAny = false;
|
|
1233
|
+
while (token.innerTokens.length > 0) {
|
|
1234
|
+
const first = token.innerTokens[0];
|
|
1235
|
+
if (first.containerType === SqlPrintToken_1.SqlPrintTokenContainerType.CommentBlock) {
|
|
1236
|
+
token.innerTokens.shift();
|
|
1237
|
+
const signature = this.commentBlockSignature(first);
|
|
1238
|
+
if (!(depth > 0 && seen.has(signature))) {
|
|
1239
|
+
collected.push(first);
|
|
1240
|
+
seen.add(signature);
|
|
1241
|
+
}
|
|
1242
|
+
removedAny = true;
|
|
1243
|
+
continue;
|
|
1244
|
+
}
|
|
1245
|
+
if (!removedAny && first.type === SqlPrintToken_1.SqlPrintTokenType.space) {
|
|
1246
|
+
return;
|
|
1247
|
+
}
|
|
1248
|
+
break;
|
|
1249
|
+
}
|
|
1250
|
+
if (!token.innerTokens || token.innerTokens.length === 0) {
|
|
1251
|
+
return;
|
|
1252
|
+
}
|
|
1253
|
+
const firstChild = token.innerTokens[0];
|
|
1254
|
+
if (this.isTransparentCaseWrapper(firstChild)) {
|
|
1255
|
+
this.collectCaseLeadingCommentBlocksRecursive(firstChild, collected, seen, depth + 1);
|
|
1256
|
+
}
|
|
1257
|
+
}
|
|
1258
|
+
isTransparentCaseWrapper(token) {
|
|
1259
|
+
if (!token) {
|
|
1260
|
+
return false;
|
|
1261
|
+
}
|
|
1262
|
+
const transparentContainers = [
|
|
1263
|
+
SqlPrintToken_1.SqlPrintTokenContainerType.ColumnReference,
|
|
1264
|
+
SqlPrintToken_1.SqlPrintTokenContainerType.QualifiedName,
|
|
1265
|
+
SqlPrintToken_1.SqlPrintTokenContainerType.IdentifierString,
|
|
1266
|
+
SqlPrintToken_1.SqlPrintTokenContainerType.RawString,
|
|
1267
|
+
SqlPrintToken_1.SqlPrintTokenContainerType.LiteralValue,
|
|
1268
|
+
SqlPrintToken_1.SqlPrintTokenContainerType.ParenExpression,
|
|
1269
|
+
SqlPrintToken_1.SqlPrintTokenContainerType.UnaryExpression,
|
|
1270
|
+
];
|
|
1271
|
+
return transparentContainers.includes(token.containerType);
|
|
1272
|
+
}
|
|
1273
|
+
commentBlockSignature(commentBlock) {
|
|
1274
|
+
if (!commentBlock.innerTokens || commentBlock.innerTokens.length === 0) {
|
|
1275
|
+
return '';
|
|
1276
|
+
}
|
|
1277
|
+
return commentBlock.innerTokens
|
|
1278
|
+
.filter(inner => inner.text !== '')
|
|
1279
|
+
.map(inner => inner.text)
|
|
1280
|
+
.join('|');
|
|
1281
|
+
}
|
|
1093
1282
|
visitArrayExpression(arg) {
|
|
1094
1283
|
const token = new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.container, '', SqlPrintToken_1.SqlPrintTokenContainerType.ArrayExpression);
|
|
1095
1284
|
token.innerTokens.push(new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.keyword, 'array'));
|
|
@@ -1175,6 +1364,7 @@ class SqlPrintTokenParser {
|
|
|
1175
1364
|
}
|
|
1176
1365
|
visitTupleExpression(arg) {
|
|
1177
1366
|
const token = new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.container, '', SqlPrintToken_1.SqlPrintTokenContainerType.TupleExpression);
|
|
1367
|
+
const requiresMultiline = this.tupleRequiresMultiline(arg);
|
|
1178
1368
|
token.innerTokens.push(SqlPrintTokenParser.PAREN_OPEN_TOKEN);
|
|
1179
1369
|
for (let i = 0; i < arg.values.length; i++) {
|
|
1180
1370
|
if (i > 0) {
|
|
@@ -1182,10 +1372,38 @@ class SqlPrintTokenParser {
|
|
|
1182
1372
|
}
|
|
1183
1373
|
token.innerTokens.push(this.visit(arg.values[i]));
|
|
1184
1374
|
}
|
|
1375
|
+
if (requiresMultiline) {
|
|
1376
|
+
token.innerTokens.push(new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.commentNewline, '', SqlPrintToken_1.SqlPrintTokenContainerType.TupleExpression));
|
|
1377
|
+
}
|
|
1185
1378
|
token.innerTokens.push(SqlPrintTokenParser.PAREN_CLOSE_TOKEN);
|
|
1186
|
-
this.addComponentComments(token, arg);
|
|
1187
1379
|
return token;
|
|
1188
1380
|
}
|
|
1381
|
+
tupleRequiresMultiline(tuple) {
|
|
1382
|
+
for (const value of tuple.values) {
|
|
1383
|
+
if (this.hasInlineComments(value)) {
|
|
1384
|
+
return true;
|
|
1385
|
+
}
|
|
1386
|
+
}
|
|
1387
|
+
return false;
|
|
1388
|
+
}
|
|
1389
|
+
hasInlineComments(component) {
|
|
1390
|
+
if (this.hasLeadingComments(component)) {
|
|
1391
|
+
return true;
|
|
1392
|
+
}
|
|
1393
|
+
if (component instanceof ValueComponent_1.TupleExpression) {
|
|
1394
|
+
return this.tupleRequiresMultiline(component);
|
|
1395
|
+
}
|
|
1396
|
+
return false;
|
|
1397
|
+
}
|
|
1398
|
+
hasLeadingComments(component) {
|
|
1399
|
+
var _a;
|
|
1400
|
+
const positioned = (_a = component.positionedComments) !== null && _a !== void 0 ? _a : [];
|
|
1401
|
+
const before = positioned.find(pc => pc.position === 'before');
|
|
1402
|
+
if (before && before.comments.some(comment => comment.trim().length > 0)) {
|
|
1403
|
+
return true;
|
|
1404
|
+
}
|
|
1405
|
+
return false;
|
|
1406
|
+
}
|
|
1189
1407
|
visitWindowFrameExpression(arg) {
|
|
1190
1408
|
// Compose window frame expression: over(partition by ... order by ... rows ...)
|
|
1191
1409
|
const token = new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.container, '', SqlPrintToken_1.SqlPrintTokenContainerType.WindowFrameExpression);
|
|
@@ -1262,12 +1480,15 @@ class SqlPrintTokenParser {
|
|
|
1262
1480
|
// Preserve original positioned comments to avoid mutating the source object
|
|
1263
1481
|
const originalSelectItemPositionedComments = arg.positionedComments;
|
|
1264
1482
|
const originalValuePositionedComments = arg.value.positionedComments;
|
|
1265
|
-
|
|
1266
|
-
|
|
1483
|
+
const isParenExpression = arg.value instanceof ValueComponent_1.ParenExpression;
|
|
1484
|
+
// Clear positioned comments from the value to avoid duplication when SelectItem itself renders them.
|
|
1485
|
+
// ParenExpression handles trailing comments internally, so we must keep its metadata intact.
|
|
1486
|
+
if (!isParenExpression) {
|
|
1487
|
+
arg.value.positionedComments = null;
|
|
1488
|
+
}
|
|
1267
1489
|
// Add positioned comments in recorded order
|
|
1268
1490
|
const beforeComments = arg.getPositionedComments('before');
|
|
1269
1491
|
const afterComments = arg.getPositionedComments('after');
|
|
1270
|
-
const isParenExpression = arg.value.constructor.name === 'ParenExpression';
|
|
1271
1492
|
if (beforeComments.length > 0) {
|
|
1272
1493
|
const commentTokens = this.createInlineCommentSequence(beforeComments);
|
|
1273
1494
|
token.innerTokens.push(...commentTokens);
|
|
@@ -1466,16 +1687,32 @@ class SqlPrintTokenParser {
|
|
|
1466
1687
|
}
|
|
1467
1688
|
}
|
|
1468
1689
|
visitFromClause(arg) {
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1690
|
+
// Build a declaration order map so JOIN ON operands can be normalized later.
|
|
1691
|
+
let contextPushed = false;
|
|
1692
|
+
if (this.normalizeJoinConditionOrder) {
|
|
1693
|
+
const aliasOrder = this.buildJoinAliasOrder(arg);
|
|
1694
|
+
if (aliasOrder.size > 0) {
|
|
1695
|
+
this.joinConditionContexts.push({ aliasOrder });
|
|
1696
|
+
contextPushed = true;
|
|
1697
|
+
}
|
|
1698
|
+
}
|
|
1699
|
+
try {
|
|
1700
|
+
const token = new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.keyword, 'from', SqlPrintToken_1.SqlPrintTokenContainerType.FromClause);
|
|
1701
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
1702
|
+
token.innerTokens.push(this.visit(arg.source));
|
|
1703
|
+
if (arg.joins) {
|
|
1704
|
+
for (let i = 0; i < arg.joins.length; i++) {
|
|
1705
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
1706
|
+
token.innerTokens.push(this.visit(arg.joins[i]));
|
|
1707
|
+
}
|
|
1708
|
+
}
|
|
1709
|
+
return token;
|
|
1710
|
+
}
|
|
1711
|
+
finally {
|
|
1712
|
+
if (contextPushed) {
|
|
1713
|
+
this.joinConditionContexts.pop();
|
|
1476
1714
|
}
|
|
1477
1715
|
}
|
|
1478
|
-
return token;
|
|
1479
1716
|
}
|
|
1480
1717
|
visitJoinClause(arg) {
|
|
1481
1718
|
// Print join clause: [joinType] [lateral] [source] [on/using ...]
|
|
@@ -1525,12 +1762,123 @@ class SqlPrintTokenParser {
|
|
|
1525
1762
|
return token;
|
|
1526
1763
|
}
|
|
1527
1764
|
visitJoinOnClause(arg) {
|
|
1765
|
+
// Normalize JOIN ON predicate columns to follow declaration order when enabled.
|
|
1766
|
+
if (this.normalizeJoinConditionOrder) {
|
|
1767
|
+
const aliasOrder = this.getCurrentJoinAliasOrder();
|
|
1768
|
+
if (aliasOrder) {
|
|
1769
|
+
this.normalizeJoinConditionValue(arg.condition, aliasOrder);
|
|
1770
|
+
}
|
|
1771
|
+
}
|
|
1528
1772
|
const token = new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.container, '', SqlPrintToken_1.SqlPrintTokenContainerType.JoinOnClause);
|
|
1529
1773
|
token.innerTokens.push(new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.keyword, 'on'));
|
|
1530
1774
|
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
1531
1775
|
token.innerTokens.push(this.visit(arg.condition));
|
|
1532
1776
|
return token;
|
|
1533
1777
|
}
|
|
1778
|
+
getCurrentJoinAliasOrder() {
|
|
1779
|
+
if (this.joinConditionContexts.length === 0) {
|
|
1780
|
+
return null;
|
|
1781
|
+
}
|
|
1782
|
+
return this.joinConditionContexts[this.joinConditionContexts.length - 1].aliasOrder;
|
|
1783
|
+
}
|
|
1784
|
+
buildJoinAliasOrder(fromClause) {
|
|
1785
|
+
const aliasOrder = new Map();
|
|
1786
|
+
let nextIndex = 0;
|
|
1787
|
+
const registerSource = (source) => {
|
|
1788
|
+
const identifiers = this.collectSourceIdentifiers(source);
|
|
1789
|
+
if (identifiers.length === 0) {
|
|
1790
|
+
return;
|
|
1791
|
+
}
|
|
1792
|
+
// Track the earliest declaration index for each identifier found in the FROM clause.
|
|
1793
|
+
for (const identifier of identifiers) {
|
|
1794
|
+
const key = identifier.toLowerCase();
|
|
1795
|
+
if (!aliasOrder.has(key)) {
|
|
1796
|
+
aliasOrder.set(key, nextIndex);
|
|
1797
|
+
}
|
|
1798
|
+
}
|
|
1799
|
+
nextIndex++;
|
|
1800
|
+
};
|
|
1801
|
+
registerSource(fromClause.source);
|
|
1802
|
+
if (fromClause.joins) {
|
|
1803
|
+
for (const joinClause of fromClause.joins) {
|
|
1804
|
+
registerSource(joinClause.source);
|
|
1805
|
+
}
|
|
1806
|
+
}
|
|
1807
|
+
return aliasOrder;
|
|
1808
|
+
}
|
|
1809
|
+
collectSourceIdentifiers(source) {
|
|
1810
|
+
const identifiers = [];
|
|
1811
|
+
const aliasName = source.getAliasName();
|
|
1812
|
+
if (aliasName) {
|
|
1813
|
+
identifiers.push(aliasName);
|
|
1814
|
+
}
|
|
1815
|
+
// Capture table identifiers so unaliased tables can still be matched.
|
|
1816
|
+
if (source.datasource instanceof Clause_1.TableSource) {
|
|
1817
|
+
const tableComponent = source.datasource.table.name;
|
|
1818
|
+
identifiers.push(tableComponent);
|
|
1819
|
+
const fullName = source.datasource.getSourceName();
|
|
1820
|
+
if (fullName && fullName !== tableComponent) {
|
|
1821
|
+
identifiers.push(fullName);
|
|
1822
|
+
}
|
|
1823
|
+
}
|
|
1824
|
+
return identifiers;
|
|
1825
|
+
}
|
|
1826
|
+
normalizeJoinConditionValue(condition, aliasOrder) {
|
|
1827
|
+
// Walk the value tree so every comparison within the JOIN predicate is inspected.
|
|
1828
|
+
const kind = condition.getKind();
|
|
1829
|
+
if (kind === ValueComponent_1.ParenExpression.kind) {
|
|
1830
|
+
const paren = condition;
|
|
1831
|
+
this.normalizeJoinConditionValue(paren.expression, aliasOrder);
|
|
1832
|
+
return;
|
|
1833
|
+
}
|
|
1834
|
+
if (kind === ValueComponent_1.BinaryExpression.kind) {
|
|
1835
|
+
const binary = condition;
|
|
1836
|
+
this.normalizeJoinConditionValue(binary.left, aliasOrder);
|
|
1837
|
+
this.normalizeJoinConditionValue(binary.right, aliasOrder);
|
|
1838
|
+
this.normalizeBinaryEquality(binary, aliasOrder);
|
|
1839
|
+
}
|
|
1840
|
+
}
|
|
1841
|
+
normalizeBinaryEquality(binary, aliasOrder) {
|
|
1842
|
+
// Only normalize simple equality comparisons, leaving other operators untouched.
|
|
1843
|
+
const operatorValue = binary.operator.value.toLowerCase();
|
|
1844
|
+
if (operatorValue !== '=') {
|
|
1845
|
+
return;
|
|
1846
|
+
}
|
|
1847
|
+
const leftOwner = this.resolveColumnOwner(binary.left);
|
|
1848
|
+
const rightOwner = this.resolveColumnOwner(binary.right);
|
|
1849
|
+
if (!leftOwner || !rightOwner || leftOwner === rightOwner) {
|
|
1850
|
+
return;
|
|
1851
|
+
}
|
|
1852
|
+
const leftOrder = aliasOrder.get(leftOwner);
|
|
1853
|
+
const rightOrder = aliasOrder.get(rightOwner);
|
|
1854
|
+
if (leftOrder === undefined || rightOrder === undefined) {
|
|
1855
|
+
return;
|
|
1856
|
+
}
|
|
1857
|
+
if (leftOrder > rightOrder) {
|
|
1858
|
+
// Swap operands so the earlier declared table appears on the left.
|
|
1859
|
+
const originalLeft = binary.left;
|
|
1860
|
+
binary.left = binary.right;
|
|
1861
|
+
binary.right = originalLeft;
|
|
1862
|
+
}
|
|
1863
|
+
}
|
|
1864
|
+
resolveColumnOwner(value) {
|
|
1865
|
+
var _a;
|
|
1866
|
+
const kind = value.getKind();
|
|
1867
|
+
if (kind === ValueComponent_1.ColumnReference.kind) {
|
|
1868
|
+
// Column references expose their qualifier namespace, which we normalize for lookups.
|
|
1869
|
+
const columnRef = value;
|
|
1870
|
+
const namespace = columnRef.getNamespace();
|
|
1871
|
+
if (!namespace) {
|
|
1872
|
+
return null;
|
|
1873
|
+
}
|
|
1874
|
+
const qualifier = namespace.includes('.') ? (_a = namespace.split('.').pop()) !== null && _a !== void 0 ? _a : '' : namespace;
|
|
1875
|
+
return qualifier.toLowerCase();
|
|
1876
|
+
}
|
|
1877
|
+
if (kind === ValueComponent_1.ParenExpression.kind) {
|
|
1878
|
+
return this.resolveColumnOwner(value.expression);
|
|
1879
|
+
}
|
|
1880
|
+
return null;
|
|
1881
|
+
}
|
|
1534
1882
|
visitJoinUsingClause(arg) {
|
|
1535
1883
|
const token = new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.container, '', SqlPrintToken_1.SqlPrintTokenContainerType.JoinUsingClause);
|
|
1536
1884
|
token.innerTokens.push(new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.keyword, 'using'));
|
|
@@ -1714,7 +2062,7 @@ class SqlPrintTokenParser {
|
|
|
1714
2062
|
token.innerTokens.push(mergedHeaderComment);
|
|
1715
2063
|
}
|
|
1716
2064
|
else {
|
|
1717
|
-
const headerCommentBlocks = this.createCommentBlocks(arg.headerComments);
|
|
2065
|
+
const headerCommentBlocks = this.createCommentBlocks(arg.headerComments, true);
|
|
1718
2066
|
token.innerTokens.push(...headerCommentBlocks);
|
|
1719
2067
|
}
|
|
1720
2068
|
if (arg.withClause) {
|
|
@@ -1801,7 +2149,7 @@ class SqlPrintTokenParser {
|
|
|
1801
2149
|
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
1802
2150
|
}
|
|
1803
2151
|
else {
|
|
1804
|
-
const headerCommentBlocks = this.createCommentBlocks(arg.headerComments);
|
|
2152
|
+
const headerCommentBlocks = this.createCommentBlocks(arg.headerComments, true);
|
|
1805
2153
|
for (const commentBlock of headerCommentBlocks) {
|
|
1806
2154
|
token.innerTokens.push(commentBlock);
|
|
1807
2155
|
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
@@ -1842,22 +2190,27 @@ class SqlPrintTokenParser {
|
|
|
1842
2190
|
}
|
|
1843
2191
|
visitInsertQuery(arg) {
|
|
1844
2192
|
const token = new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.container, '', SqlPrintToken_1.SqlPrintTokenContainerType.InsertQuery);
|
|
1845
|
-
|
|
2193
|
+
if (arg.withClause) {
|
|
2194
|
+
token.innerTokens.push(arg.withClause.accept(this));
|
|
2195
|
+
}
|
|
1846
2196
|
token.innerTokens.push(this.visit(arg.insertClause));
|
|
1847
2197
|
// Process the select query if present
|
|
1848
2198
|
if (arg.selectQuery) {
|
|
1849
2199
|
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
1850
2200
|
token.innerTokens.push(this.visit(arg.selectQuery));
|
|
1851
2201
|
}
|
|
2202
|
+
if (arg.returningClause) {
|
|
2203
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2204
|
+
token.innerTokens.push(arg.returningClause.accept(this));
|
|
2205
|
+
}
|
|
1852
2206
|
return token;
|
|
1853
2207
|
}
|
|
1854
2208
|
visitInsertClause(arg) {
|
|
1855
|
-
const token = new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.container, '');
|
|
1856
|
-
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2209
|
+
const token = new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.container, '', SqlPrintToken_1.SqlPrintTokenContainerType.InsertClause);
|
|
1857
2210
|
token.innerTokens.push(new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.keyword, 'insert into'));
|
|
1858
2211
|
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
1859
2212
|
token.innerTokens.push(arg.source.accept(this));
|
|
1860
|
-
if (arg.columns.length > 0) {
|
|
2213
|
+
if (arg.columns && arg.columns.length > 0) {
|
|
1861
2214
|
token.innerTokens.push(SqlPrintTokenParser.PAREN_OPEN_TOKEN);
|
|
1862
2215
|
for (let i = 0; i < arg.columns.length; i++) {
|
|
1863
2216
|
if (i > 0) {
|
|
@@ -1869,6 +2222,176 @@ class SqlPrintTokenParser {
|
|
|
1869
2222
|
}
|
|
1870
2223
|
return token;
|
|
1871
2224
|
}
|
|
2225
|
+
visitDeleteQuery(arg) {
|
|
2226
|
+
const token = new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.container, '', SqlPrintToken_1.SqlPrintTokenContainerType.DeleteQuery);
|
|
2227
|
+
// Attach WITH clause tokens when present before the DELETE command.
|
|
2228
|
+
if (arg.withClause) {
|
|
2229
|
+
token.innerTokens.push(arg.withClause.accept(this));
|
|
2230
|
+
}
|
|
2231
|
+
token.innerTokens.push(arg.deleteClause.accept(this));
|
|
2232
|
+
// Append USING clause when the DELETE references additional sources.
|
|
2233
|
+
if (arg.usingClause) {
|
|
2234
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2235
|
+
token.innerTokens.push(arg.usingClause.accept(this));
|
|
2236
|
+
}
|
|
2237
|
+
// Append WHERE clause to restrict affected rows.
|
|
2238
|
+
if (arg.whereClause) {
|
|
2239
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2240
|
+
token.innerTokens.push(arg.whereClause.accept(this));
|
|
2241
|
+
}
|
|
2242
|
+
// Append RETURNING clause when the DELETE yields output columns.
|
|
2243
|
+
if (arg.returningClause) {
|
|
2244
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2245
|
+
token.innerTokens.push(arg.returningClause.accept(this));
|
|
2246
|
+
}
|
|
2247
|
+
return token;
|
|
2248
|
+
}
|
|
2249
|
+
visitDeleteClause(arg) {
|
|
2250
|
+
const token = new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.keyword, 'delete from', SqlPrintToken_1.SqlPrintTokenContainerType.DeleteClause);
|
|
2251
|
+
// Render the target relation immediately after the DELETE FROM keyword.
|
|
2252
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2253
|
+
token.innerTokens.push(arg.source.accept(this));
|
|
2254
|
+
return token;
|
|
2255
|
+
}
|
|
2256
|
+
visitUsingClause(arg) {
|
|
2257
|
+
const token = new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.keyword, 'using', SqlPrintToken_1.SqlPrintTokenContainerType.UsingClause);
|
|
2258
|
+
if (arg.sources.length > 0) {
|
|
2259
|
+
// Attach the first USING source directly after the keyword.
|
|
2260
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2261
|
+
for (let i = 0; i < arg.sources.length; i++) {
|
|
2262
|
+
if (i > 0) {
|
|
2263
|
+
// Separate subsequent sources with comma and space for clarity.
|
|
2264
|
+
token.innerTokens.push(...SqlPrintTokenParser.commaSpaceTokens());
|
|
2265
|
+
}
|
|
2266
|
+
token.innerTokens.push(this.visit(arg.sources[i]));
|
|
2267
|
+
}
|
|
2268
|
+
}
|
|
2269
|
+
return token;
|
|
2270
|
+
}
|
|
2271
|
+
visitMergeQuery(arg) {
|
|
2272
|
+
const token = new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.container, '', SqlPrintToken_1.SqlPrintTokenContainerType.MergeQuery);
|
|
2273
|
+
if (arg.withClause) {
|
|
2274
|
+
token.innerTokens.push(arg.withClause.accept(this));
|
|
2275
|
+
}
|
|
2276
|
+
token.innerTokens.push(new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.keyword, 'merge into'));
|
|
2277
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2278
|
+
token.innerTokens.push(arg.target.accept(this));
|
|
2279
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2280
|
+
token.innerTokens.push(new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.keyword, 'using'));
|
|
2281
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2282
|
+
token.innerTokens.push(arg.source.accept(this));
|
|
2283
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2284
|
+
const onClauseToken = new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.container, '', SqlPrintToken_1.SqlPrintTokenContainerType.JoinOnClause);
|
|
2285
|
+
onClauseToken.innerTokens.push(new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.keyword, 'on'));
|
|
2286
|
+
onClauseToken.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2287
|
+
onClauseToken.innerTokens.push(arg.onCondition.accept(this));
|
|
2288
|
+
token.innerTokens.push(onClauseToken);
|
|
2289
|
+
for (const clause of arg.whenClauses) {
|
|
2290
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2291
|
+
token.innerTokens.push(clause.accept(this));
|
|
2292
|
+
}
|
|
2293
|
+
return token;
|
|
2294
|
+
}
|
|
2295
|
+
visitMergeWhenClause(arg) {
|
|
2296
|
+
const token = new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.container, '', SqlPrintToken_1.SqlPrintTokenContainerType.MergeWhenClause);
|
|
2297
|
+
token.innerTokens.push(new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.keyword, this.mergeMatchTypeToKeyword(arg.matchType)));
|
|
2298
|
+
if (arg.condition) {
|
|
2299
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2300
|
+
token.innerTokens.push(new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.keyword, 'and'));
|
|
2301
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2302
|
+
token.innerTokens.push(arg.condition.accept(this));
|
|
2303
|
+
}
|
|
2304
|
+
const thenLeadingComments = arg.getThenLeadingComments();
|
|
2305
|
+
const thenKeywordToken = new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.keyword, 'then');
|
|
2306
|
+
if (thenLeadingComments.length > 0) {
|
|
2307
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2308
|
+
const commentBlocks = this.createCommentBlocks(thenLeadingComments);
|
|
2309
|
+
token.innerTokens.push(...commentBlocks);
|
|
2310
|
+
token.innerTokens.push(thenKeywordToken);
|
|
2311
|
+
}
|
|
2312
|
+
else {
|
|
2313
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2314
|
+
token.innerTokens.push(thenKeywordToken);
|
|
2315
|
+
}
|
|
2316
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2317
|
+
token.innerTokens.push(arg.action.accept(this));
|
|
2318
|
+
return token;
|
|
2319
|
+
}
|
|
2320
|
+
visitMergeUpdateAction(arg) {
|
|
2321
|
+
const token = new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.container, '', SqlPrintToken_1.SqlPrintTokenContainerType.MergeUpdateAction);
|
|
2322
|
+
token.innerTokens.push(new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.keyword, 'update'));
|
|
2323
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2324
|
+
token.innerTokens.push(arg.setClause.accept(this));
|
|
2325
|
+
if (arg.whereClause) {
|
|
2326
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2327
|
+
token.innerTokens.push(arg.whereClause.accept(this));
|
|
2328
|
+
}
|
|
2329
|
+
return token;
|
|
2330
|
+
}
|
|
2331
|
+
visitMergeDeleteAction(arg) {
|
|
2332
|
+
const token = new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.container, '', SqlPrintToken_1.SqlPrintTokenContainerType.MergeDeleteAction);
|
|
2333
|
+
token.innerTokens.push(new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.keyword, 'delete'));
|
|
2334
|
+
if (arg.whereClause) {
|
|
2335
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2336
|
+
token.innerTokens.push(arg.whereClause.accept(this));
|
|
2337
|
+
}
|
|
2338
|
+
return token;
|
|
2339
|
+
}
|
|
2340
|
+
visitMergeInsertAction(arg) {
|
|
2341
|
+
const token = new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.container, '', SqlPrintToken_1.SqlPrintTokenContainerType.MergeInsertAction);
|
|
2342
|
+
token.innerTokens.push(new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.keyword, 'insert'));
|
|
2343
|
+
if (arg.columns && arg.columns.length > 0) {
|
|
2344
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2345
|
+
token.innerTokens.push(SqlPrintTokenParser.PAREN_OPEN_TOKEN);
|
|
2346
|
+
for (let i = 0; i < arg.columns.length; i++) {
|
|
2347
|
+
if (i > 0) {
|
|
2348
|
+
token.innerTokens.push(...SqlPrintTokenParser.commaSpaceTokens());
|
|
2349
|
+
}
|
|
2350
|
+
token.innerTokens.push(arg.columns[i].accept(this));
|
|
2351
|
+
}
|
|
2352
|
+
token.innerTokens.push(SqlPrintTokenParser.PAREN_CLOSE_TOKEN);
|
|
2353
|
+
}
|
|
2354
|
+
if (arg.defaultValues) {
|
|
2355
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2356
|
+
token.innerTokens.push(new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.keyword, 'default values'));
|
|
2357
|
+
return token;
|
|
2358
|
+
}
|
|
2359
|
+
if (arg.values) {
|
|
2360
|
+
const leadingValuesComments = arg.getValuesLeadingComments();
|
|
2361
|
+
if (leadingValuesComments.length > 0) {
|
|
2362
|
+
token.innerTokens.push(new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.commentNewline, ''));
|
|
2363
|
+
const commentBlocks = this.createCommentBlocks(leadingValuesComments);
|
|
2364
|
+
token.innerTokens.push(...commentBlocks);
|
|
2365
|
+
}
|
|
2366
|
+
else {
|
|
2367
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2368
|
+
}
|
|
2369
|
+
const valuesKeywordToken = new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.keyword, 'values');
|
|
2370
|
+
token.innerTokens.push(valuesKeywordToken);
|
|
2371
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2372
|
+
token.innerTokens.push(SqlPrintTokenParser.PAREN_OPEN_TOKEN);
|
|
2373
|
+
token.innerTokens.push(arg.values.accept(this));
|
|
2374
|
+
token.innerTokens.push(SqlPrintTokenParser.PAREN_CLOSE_TOKEN);
|
|
2375
|
+
}
|
|
2376
|
+
return token;
|
|
2377
|
+
}
|
|
2378
|
+
visitMergeDoNothingAction(_) {
|
|
2379
|
+
return new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.keyword, 'do nothing', SqlPrintToken_1.SqlPrintTokenContainerType.MergeDoNothingAction);
|
|
2380
|
+
}
|
|
2381
|
+
mergeMatchTypeToKeyword(matchType) {
|
|
2382
|
+
switch (matchType) {
|
|
2383
|
+
case 'matched':
|
|
2384
|
+
return 'when matched';
|
|
2385
|
+
case 'not_matched':
|
|
2386
|
+
return 'when not matched';
|
|
2387
|
+
case 'not_matched_by_source':
|
|
2388
|
+
return 'when not matched by source';
|
|
2389
|
+
case 'not_matched_by_target':
|
|
2390
|
+
return 'when not matched by target';
|
|
2391
|
+
default:
|
|
2392
|
+
return 'when';
|
|
2393
|
+
}
|
|
2394
|
+
}
|
|
1872
2395
|
visitUpdateQuery(arg) {
|
|
1873
2396
|
const token = new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.container, '', SqlPrintToken_1.SqlPrintTokenContainerType.UpdateQuery);
|
|
1874
2397
|
if (arg.withClause) {
|
|
@@ -1898,7 +2421,7 @@ class SqlPrintTokenParser {
|
|
|
1898
2421
|
return token;
|
|
1899
2422
|
}
|
|
1900
2423
|
visitSetClause(arg) {
|
|
1901
|
-
const token = new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.keyword, 'set', SqlPrintToken_1.SqlPrintTokenContainerType.
|
|
2424
|
+
const token = new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.keyword, 'set', SqlPrintToken_1.SqlPrintTokenContainerType.SetClause);
|
|
1902
2425
|
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
1903
2426
|
for (let i = 0; i < arg.items.length; i++) {
|
|
1904
2427
|
if (i > 0) {
|
|
@@ -1929,17 +2452,601 @@ class SqlPrintTokenParser {
|
|
|
1929
2452
|
return token;
|
|
1930
2453
|
}
|
|
1931
2454
|
visitCreateTableQuery(arg) {
|
|
1932
|
-
|
|
2455
|
+
var _a;
|
|
2456
|
+
const baseKeyword = arg.isTemporary ? 'create temporary table' : 'create table';
|
|
2457
|
+
let keywordText = arg.ifNotExists ? `${baseKeyword} if not exists` : baseKeyword;
|
|
2458
|
+
const token = new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.keyword, keywordText, SqlPrintToken_1.SqlPrintTokenContainerType.CreateTableQuery);
|
|
1933
2459
|
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
1934
|
-
|
|
2460
|
+
const qualifiedName = new ValueComponent_1.QualifiedName((_a = arg.namespaces) !== null && _a !== void 0 ? _a : null, arg.tableName);
|
|
2461
|
+
token.innerTokens.push(qualifiedName.accept(this));
|
|
2462
|
+
const definitionEntries = [...arg.columns, ...arg.tableConstraints];
|
|
2463
|
+
if (definitionEntries.length > 0) {
|
|
2464
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2465
|
+
token.innerTokens.push(SqlPrintTokenParser.PAREN_OPEN_TOKEN);
|
|
2466
|
+
const definitionToken = new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.container, '', SqlPrintToken_1.SqlPrintTokenContainerType.CreateTableDefinition);
|
|
2467
|
+
for (let i = 0; i < definitionEntries.length; i++) {
|
|
2468
|
+
if (i > 0) {
|
|
2469
|
+
definitionToken.innerTokens.push(...SqlPrintTokenParser.commaSpaceTokens());
|
|
2470
|
+
}
|
|
2471
|
+
definitionToken.innerTokens.push(definitionEntries[i].accept(this));
|
|
2472
|
+
}
|
|
2473
|
+
token.innerTokens.push(definitionToken);
|
|
2474
|
+
token.innerTokens.push(SqlPrintTokenParser.PAREN_CLOSE_TOKEN);
|
|
2475
|
+
}
|
|
2476
|
+
if (arg.tableOptions) {
|
|
2477
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2478
|
+
token.innerTokens.push(arg.tableOptions.accept(this));
|
|
2479
|
+
}
|
|
1935
2480
|
if (arg.asSelectQuery) {
|
|
1936
2481
|
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
1937
2482
|
token.innerTokens.push(new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.keyword, 'as'));
|
|
1938
2483
|
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
1939
2484
|
token.innerTokens.push(arg.asSelectQuery.accept(this));
|
|
1940
2485
|
}
|
|
2486
|
+
if (arg.withDataOption) {
|
|
2487
|
+
// Reconstruct WITH [NO] DATA clause to mirror PostgreSQL CREATE TABLE semantics.
|
|
2488
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2489
|
+
token.innerTokens.push(new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.keyword, 'with'));
|
|
2490
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2491
|
+
if (arg.withDataOption === 'with-no-data') {
|
|
2492
|
+
token.innerTokens.push(new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.keyword, 'no'));
|
|
2493
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2494
|
+
}
|
|
2495
|
+
token.innerTokens.push(new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.keyword, 'data'));
|
|
2496
|
+
}
|
|
2497
|
+
return token;
|
|
2498
|
+
}
|
|
2499
|
+
visitTableColumnDefinition(arg) {
|
|
2500
|
+
const token = new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.container, '', SqlPrintToken_1.SqlPrintTokenContainerType.TableColumnDefinition);
|
|
2501
|
+
token.innerTokens.push(arg.name.accept(this));
|
|
2502
|
+
if (arg.dataType) {
|
|
2503
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2504
|
+
token.innerTokens.push(arg.dataType.accept(this));
|
|
2505
|
+
}
|
|
2506
|
+
for (const constraint of arg.constraints) {
|
|
2507
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2508
|
+
token.innerTokens.push(constraint.accept(this));
|
|
2509
|
+
}
|
|
2510
|
+
return token;
|
|
2511
|
+
}
|
|
2512
|
+
visitColumnConstraintDefinition(arg) {
|
|
2513
|
+
const token = new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.container, '', SqlPrintToken_1.SqlPrintTokenContainerType.ColumnConstraintDefinition);
|
|
2514
|
+
if (arg.constraintName) {
|
|
2515
|
+
token.innerTokens.push(new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.keyword, 'constraint'));
|
|
2516
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2517
|
+
token.innerTokens.push(arg.constraintName.accept(this));
|
|
2518
|
+
}
|
|
2519
|
+
const appendKeyword = (text) => {
|
|
2520
|
+
if (token.innerTokens.length > 0) {
|
|
2521
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2522
|
+
}
|
|
2523
|
+
token.innerTokens.push(new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.keyword, text));
|
|
2524
|
+
};
|
|
2525
|
+
const appendComponent = (component) => {
|
|
2526
|
+
if (token.innerTokens.length > 0) {
|
|
2527
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2528
|
+
}
|
|
2529
|
+
token.innerTokens.push(component.accept(this));
|
|
2530
|
+
};
|
|
2531
|
+
switch (arg.kind) {
|
|
2532
|
+
case 'not-null':
|
|
2533
|
+
appendKeyword('not null');
|
|
2534
|
+
break;
|
|
2535
|
+
case 'null':
|
|
2536
|
+
appendKeyword('null');
|
|
2537
|
+
break;
|
|
2538
|
+
case 'default':
|
|
2539
|
+
appendKeyword('default');
|
|
2540
|
+
if (arg.defaultValue) {
|
|
2541
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2542
|
+
token.innerTokens.push(arg.defaultValue.accept(this));
|
|
2543
|
+
}
|
|
2544
|
+
break;
|
|
2545
|
+
case 'primary-key':
|
|
2546
|
+
appendKeyword('primary key');
|
|
2547
|
+
break;
|
|
2548
|
+
case 'unique':
|
|
2549
|
+
appendKeyword('unique');
|
|
2550
|
+
break;
|
|
2551
|
+
case 'references':
|
|
2552
|
+
if (arg.reference) {
|
|
2553
|
+
appendComponent(arg.reference);
|
|
2554
|
+
}
|
|
2555
|
+
break;
|
|
2556
|
+
case 'check':
|
|
2557
|
+
if (arg.checkExpression) {
|
|
2558
|
+
appendKeyword('check');
|
|
2559
|
+
token.innerTokens.push(this.wrapWithParenExpression(arg.checkExpression));
|
|
2560
|
+
}
|
|
2561
|
+
break;
|
|
2562
|
+
case 'generated-always-identity':
|
|
2563
|
+
case 'generated-by-default-identity':
|
|
2564
|
+
case 'raw':
|
|
2565
|
+
if (arg.rawClause) {
|
|
2566
|
+
appendComponent(arg.rawClause);
|
|
2567
|
+
}
|
|
2568
|
+
break;
|
|
2569
|
+
}
|
|
2570
|
+
return token;
|
|
2571
|
+
}
|
|
2572
|
+
visitTableConstraintDefinition(arg) {
|
|
2573
|
+
var _a, _b, _c;
|
|
2574
|
+
const token = new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.container, '', SqlPrintToken_1.SqlPrintTokenContainerType.TableConstraintDefinition);
|
|
2575
|
+
const appendKeyword = (text) => {
|
|
2576
|
+
if (token.innerTokens.length > 0) {
|
|
2577
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2578
|
+
}
|
|
2579
|
+
token.innerTokens.push(new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.keyword, text));
|
|
2580
|
+
};
|
|
2581
|
+
const appendComponent = (component) => {
|
|
2582
|
+
if (token.innerTokens.length > 0) {
|
|
2583
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2584
|
+
}
|
|
2585
|
+
token.innerTokens.push(component.accept(this));
|
|
2586
|
+
};
|
|
2587
|
+
const appendColumns = (columns) => {
|
|
2588
|
+
if (!columns || columns.length === 0) {
|
|
2589
|
+
return;
|
|
2590
|
+
}
|
|
2591
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2592
|
+
token.innerTokens.push(SqlPrintTokenParser.PAREN_OPEN_TOKEN);
|
|
2593
|
+
const listToken = new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.container, '', SqlPrintToken_1.SqlPrintTokenContainerType.ValueList);
|
|
2594
|
+
for (let i = 0; i < columns.length; i++) {
|
|
2595
|
+
if (i > 0) {
|
|
2596
|
+
listToken.innerTokens.push(...SqlPrintTokenParser.commaSpaceTokens());
|
|
2597
|
+
}
|
|
2598
|
+
listToken.innerTokens.push(columns[i].accept(this));
|
|
2599
|
+
}
|
|
2600
|
+
token.innerTokens.push(listToken);
|
|
2601
|
+
token.innerTokens.push(SqlPrintTokenParser.PAREN_CLOSE_TOKEN);
|
|
2602
|
+
};
|
|
2603
|
+
const useMysqlConstraintStyle = this.constraintStyle === 'mysql';
|
|
2604
|
+
const inlineNameKinds = new Set(['primary-key', 'unique', 'foreign-key']);
|
|
2605
|
+
const shouldInlineConstraintName = useMysqlConstraintStyle && !!arg.constraintName && inlineNameKinds.has(arg.kind);
|
|
2606
|
+
if (arg.constraintName && !shouldInlineConstraintName) {
|
|
2607
|
+
appendKeyword('constraint');
|
|
2608
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2609
|
+
token.innerTokens.push(arg.constraintName.accept(this));
|
|
2610
|
+
}
|
|
2611
|
+
switch (arg.kind) {
|
|
2612
|
+
case 'primary-key':
|
|
2613
|
+
appendKeyword('primary key');
|
|
2614
|
+
if (shouldInlineConstraintName && arg.constraintName) {
|
|
2615
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2616
|
+
token.innerTokens.push(arg.constraintName.accept(this));
|
|
2617
|
+
}
|
|
2618
|
+
appendColumns((_a = arg.columns) !== null && _a !== void 0 ? _a : []);
|
|
2619
|
+
break;
|
|
2620
|
+
case 'unique':
|
|
2621
|
+
if (useMysqlConstraintStyle) {
|
|
2622
|
+
appendKeyword('unique key');
|
|
2623
|
+
if (shouldInlineConstraintName && arg.constraintName) {
|
|
2624
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2625
|
+
token.innerTokens.push(arg.constraintName.accept(this));
|
|
2626
|
+
}
|
|
2627
|
+
}
|
|
2628
|
+
else {
|
|
2629
|
+
appendKeyword('unique');
|
|
2630
|
+
}
|
|
2631
|
+
appendColumns((_b = arg.columns) !== null && _b !== void 0 ? _b : []);
|
|
2632
|
+
break;
|
|
2633
|
+
case 'foreign-key':
|
|
2634
|
+
appendKeyword('foreign key');
|
|
2635
|
+
if (shouldInlineConstraintName && arg.constraintName) {
|
|
2636
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2637
|
+
token.innerTokens.push(arg.constraintName.accept(this));
|
|
2638
|
+
}
|
|
2639
|
+
appendColumns((_c = arg.columns) !== null && _c !== void 0 ? _c : []);
|
|
2640
|
+
if (arg.reference) {
|
|
2641
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2642
|
+
token.innerTokens.push(arg.reference.accept(this));
|
|
2643
|
+
}
|
|
2644
|
+
break;
|
|
2645
|
+
case 'check':
|
|
2646
|
+
if (arg.checkExpression) {
|
|
2647
|
+
appendKeyword('check');
|
|
2648
|
+
token.innerTokens.push(this.wrapWithParenExpression(arg.checkExpression));
|
|
2649
|
+
}
|
|
2650
|
+
break;
|
|
2651
|
+
case 'raw':
|
|
2652
|
+
if (arg.rawClause) {
|
|
2653
|
+
appendComponent(arg.rawClause);
|
|
2654
|
+
}
|
|
2655
|
+
break;
|
|
2656
|
+
}
|
|
2657
|
+
return token;
|
|
2658
|
+
}
|
|
2659
|
+
wrapWithParenExpression(expression) {
|
|
2660
|
+
// Reuse existing parentheses groups to avoid double-wrapping when callers already provided them.
|
|
2661
|
+
if (expression instanceof ValueComponent_1.ParenExpression) {
|
|
2662
|
+
return this.visit(expression);
|
|
2663
|
+
}
|
|
2664
|
+
// Synthesize a ParenExpression wrapper so nested boolean groups render with consistent indentation.
|
|
2665
|
+
const synthetic = new ValueComponent_1.ParenExpression(expression);
|
|
2666
|
+
return this.visit(synthetic);
|
|
2667
|
+
}
|
|
2668
|
+
visitReferenceDefinition(arg) {
|
|
2669
|
+
const token = new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.container, '', SqlPrintToken_1.SqlPrintTokenContainerType.ReferenceDefinition);
|
|
2670
|
+
token.innerTokens.push(new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.keyword, 'references'));
|
|
2671
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2672
|
+
token.innerTokens.push(arg.targetTable.accept(this));
|
|
2673
|
+
if (arg.columns && arg.columns.length > 0) {
|
|
2674
|
+
token.innerTokens.push(SqlPrintTokenParser.PAREN_OPEN_TOKEN);
|
|
2675
|
+
const columnList = new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.container, '', SqlPrintToken_1.SqlPrintTokenContainerType.ValueList);
|
|
2676
|
+
for (let i = 0; i < arg.columns.length; i++) {
|
|
2677
|
+
if (i > 0) {
|
|
2678
|
+
columnList.innerTokens.push(...SqlPrintTokenParser.commaSpaceTokens());
|
|
2679
|
+
}
|
|
2680
|
+
columnList.innerTokens.push(arg.columns[i].accept(this));
|
|
2681
|
+
}
|
|
2682
|
+
token.innerTokens.push(columnList);
|
|
2683
|
+
token.innerTokens.push(SqlPrintTokenParser.PAREN_CLOSE_TOKEN);
|
|
2684
|
+
}
|
|
2685
|
+
if (arg.matchType) {
|
|
2686
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2687
|
+
token.innerTokens.push(new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.keyword, `match ${arg.matchType}`));
|
|
2688
|
+
}
|
|
2689
|
+
if (arg.onDelete) {
|
|
2690
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2691
|
+
token.innerTokens.push(new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.keyword, 'on delete'));
|
|
2692
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2693
|
+
token.innerTokens.push(new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.keyword, arg.onDelete));
|
|
2694
|
+
}
|
|
2695
|
+
if (arg.onUpdate) {
|
|
2696
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2697
|
+
token.innerTokens.push(new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.keyword, 'on update'));
|
|
2698
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2699
|
+
token.innerTokens.push(new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.keyword, arg.onUpdate));
|
|
2700
|
+
}
|
|
2701
|
+
if (arg.deferrable === 'deferrable') {
|
|
2702
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2703
|
+
token.innerTokens.push(new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.keyword, 'deferrable'));
|
|
2704
|
+
}
|
|
2705
|
+
else if (arg.deferrable === 'not deferrable') {
|
|
2706
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2707
|
+
token.innerTokens.push(new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.keyword, 'not deferrable'));
|
|
2708
|
+
}
|
|
2709
|
+
if (arg.initially === 'immediate') {
|
|
2710
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2711
|
+
token.innerTokens.push(new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.keyword, 'initially immediate'));
|
|
2712
|
+
}
|
|
2713
|
+
else if (arg.initially === 'deferred') {
|
|
2714
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2715
|
+
token.innerTokens.push(new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.keyword, 'initially deferred'));
|
|
2716
|
+
}
|
|
2717
|
+
return token;
|
|
2718
|
+
}
|
|
2719
|
+
visitCreateIndexStatement(arg) {
|
|
2720
|
+
const keywordParts = ['create'];
|
|
2721
|
+
if (arg.unique) {
|
|
2722
|
+
keywordParts.push('unique');
|
|
2723
|
+
}
|
|
2724
|
+
keywordParts.push('index');
|
|
2725
|
+
if (arg.concurrently) {
|
|
2726
|
+
keywordParts.push('concurrently');
|
|
2727
|
+
}
|
|
2728
|
+
if (arg.ifNotExists) {
|
|
2729
|
+
keywordParts.push('if not exists');
|
|
2730
|
+
}
|
|
2731
|
+
const token = new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.keyword, keywordParts.join(' '), SqlPrintToken_1.SqlPrintTokenContainerType.CreateIndexStatement);
|
|
2732
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2733
|
+
token.innerTokens.push(arg.indexName.accept(this));
|
|
2734
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2735
|
+
token.innerTokens.push(new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.keyword, 'on'));
|
|
2736
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2737
|
+
token.innerTokens.push(arg.tableName.accept(this));
|
|
2738
|
+
if (arg.usingMethod) {
|
|
2739
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2740
|
+
token.innerTokens.push(new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.keyword, 'using'));
|
|
2741
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2742
|
+
token.innerTokens.push(arg.usingMethod.accept(this));
|
|
2743
|
+
}
|
|
2744
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2745
|
+
token.innerTokens.push(SqlPrintTokenParser.PAREN_OPEN_TOKEN);
|
|
2746
|
+
const columnList = new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.container, '', SqlPrintToken_1.SqlPrintTokenContainerType.IndexColumnList);
|
|
2747
|
+
for (let i = 0; i < arg.columns.length; i++) {
|
|
2748
|
+
if (i > 0) {
|
|
2749
|
+
columnList.innerTokens.push(...SqlPrintTokenParser.commaSpaceTokens());
|
|
2750
|
+
}
|
|
2751
|
+
columnList.innerTokens.push(arg.columns[i].accept(this));
|
|
2752
|
+
}
|
|
2753
|
+
token.innerTokens.push(columnList);
|
|
2754
|
+
token.innerTokens.push(SqlPrintTokenParser.PAREN_CLOSE_TOKEN);
|
|
2755
|
+
if (arg.include && arg.include.length > 0) {
|
|
2756
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2757
|
+
token.innerTokens.push(new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.keyword, 'include'));
|
|
2758
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2759
|
+
token.innerTokens.push(SqlPrintTokenParser.PAREN_OPEN_TOKEN);
|
|
2760
|
+
const includeList = new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.container, '', SqlPrintToken_1.SqlPrintTokenContainerType.ValueList);
|
|
2761
|
+
for (let i = 0; i < arg.include.length; i++) {
|
|
2762
|
+
if (i > 0) {
|
|
2763
|
+
includeList.innerTokens.push(...SqlPrintTokenParser.commaSpaceTokens());
|
|
2764
|
+
}
|
|
2765
|
+
includeList.innerTokens.push(arg.include[i].accept(this));
|
|
2766
|
+
}
|
|
2767
|
+
token.innerTokens.push(includeList);
|
|
2768
|
+
token.innerTokens.push(SqlPrintTokenParser.PAREN_CLOSE_TOKEN);
|
|
2769
|
+
}
|
|
2770
|
+
if (arg.withOptions) {
|
|
2771
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2772
|
+
token.innerTokens.push(arg.withOptions.accept(this));
|
|
2773
|
+
}
|
|
2774
|
+
if (arg.tablespace) {
|
|
2775
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2776
|
+
token.innerTokens.push(new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.keyword, 'tablespace'));
|
|
2777
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2778
|
+
token.innerTokens.push(arg.tablespace.accept(this));
|
|
2779
|
+
}
|
|
2780
|
+
if (arg.where) {
|
|
2781
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2782
|
+
token.innerTokens.push(new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.keyword, 'where'));
|
|
2783
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2784
|
+
token.innerTokens.push(this.visit(arg.where));
|
|
2785
|
+
}
|
|
1941
2786
|
return token;
|
|
1942
2787
|
}
|
|
2788
|
+
visitIndexColumnDefinition(arg) {
|
|
2789
|
+
const token = new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.container, '', SqlPrintToken_1.SqlPrintTokenContainerType.IndexColumnDefinition);
|
|
2790
|
+
token.innerTokens.push(this.visit(arg.expression));
|
|
2791
|
+
if (arg.collation) {
|
|
2792
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2793
|
+
token.innerTokens.push(new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.keyword, 'collate'));
|
|
2794
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2795
|
+
token.innerTokens.push(arg.collation.accept(this));
|
|
2796
|
+
}
|
|
2797
|
+
if (arg.operatorClass) {
|
|
2798
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2799
|
+
token.innerTokens.push(arg.operatorClass.accept(this));
|
|
2800
|
+
}
|
|
2801
|
+
if (arg.sortOrder) {
|
|
2802
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2803
|
+
token.innerTokens.push(new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.keyword, arg.sortOrder));
|
|
2804
|
+
}
|
|
2805
|
+
if (arg.nullsOrder) {
|
|
2806
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2807
|
+
token.innerTokens.push(new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.keyword, `nulls ${arg.nullsOrder}`));
|
|
2808
|
+
}
|
|
2809
|
+
return token;
|
|
2810
|
+
}
|
|
2811
|
+
visitDropTableStatement(arg) {
|
|
2812
|
+
const keyword = arg.ifExists ? 'drop table if exists' : 'drop table';
|
|
2813
|
+
const token = new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.keyword, keyword, SqlPrintToken_1.SqlPrintTokenContainerType.DropTableStatement);
|
|
2814
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2815
|
+
const tableList = new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.container, '', SqlPrintToken_1.SqlPrintTokenContainerType.ValueList);
|
|
2816
|
+
for (let i = 0; i < arg.tables.length; i++) {
|
|
2817
|
+
if (i > 0) {
|
|
2818
|
+
tableList.innerTokens.push(...SqlPrintTokenParser.commaSpaceTokens());
|
|
2819
|
+
}
|
|
2820
|
+
tableList.innerTokens.push(arg.tables[i].accept(this));
|
|
2821
|
+
}
|
|
2822
|
+
token.innerTokens.push(tableList);
|
|
2823
|
+
if (arg.behavior) {
|
|
2824
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2825
|
+
token.innerTokens.push(new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.keyword, arg.behavior));
|
|
2826
|
+
}
|
|
2827
|
+
return token;
|
|
2828
|
+
}
|
|
2829
|
+
visitDropIndexStatement(arg) {
|
|
2830
|
+
const keywordParts = ['drop', 'index'];
|
|
2831
|
+
if (arg.concurrently) {
|
|
2832
|
+
keywordParts.push('concurrently');
|
|
2833
|
+
}
|
|
2834
|
+
if (arg.ifExists) {
|
|
2835
|
+
keywordParts.push('if exists');
|
|
2836
|
+
}
|
|
2837
|
+
const token = new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.keyword, keywordParts.join(' '), SqlPrintToken_1.SqlPrintTokenContainerType.DropIndexStatement);
|
|
2838
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2839
|
+
const indexList = new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.container, '', SqlPrintToken_1.SqlPrintTokenContainerType.ValueList);
|
|
2840
|
+
for (let i = 0; i < arg.indexNames.length; i++) {
|
|
2841
|
+
if (i > 0) {
|
|
2842
|
+
indexList.innerTokens.push(...SqlPrintTokenParser.commaSpaceTokens());
|
|
2843
|
+
}
|
|
2844
|
+
indexList.innerTokens.push(arg.indexNames[i].accept(this));
|
|
2845
|
+
}
|
|
2846
|
+
token.innerTokens.push(indexList);
|
|
2847
|
+
if (arg.behavior) {
|
|
2848
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2849
|
+
token.innerTokens.push(new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.keyword, arg.behavior));
|
|
2850
|
+
}
|
|
2851
|
+
return token;
|
|
2852
|
+
}
|
|
2853
|
+
visitAlterTableStatement(arg) {
|
|
2854
|
+
const keywordParts = ['alter', 'table'];
|
|
2855
|
+
if (arg.ifExists) {
|
|
2856
|
+
keywordParts.push('if exists');
|
|
2857
|
+
}
|
|
2858
|
+
if (arg.only) {
|
|
2859
|
+
keywordParts.push('only');
|
|
2860
|
+
}
|
|
2861
|
+
const token = new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.keyword, keywordParts.join(' '), SqlPrintToken_1.SqlPrintTokenContainerType.AlterTableStatement);
|
|
2862
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2863
|
+
token.innerTokens.push(arg.table.accept(this));
|
|
2864
|
+
for (let i = 0; i < arg.actions.length; i++) {
|
|
2865
|
+
if (i === 0) {
|
|
2866
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2867
|
+
}
|
|
2868
|
+
else {
|
|
2869
|
+
token.innerTokens.push(SqlPrintTokenParser.COMMA_TOKEN);
|
|
2870
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2871
|
+
}
|
|
2872
|
+
token.innerTokens.push(arg.actions[i].accept(this));
|
|
2873
|
+
}
|
|
2874
|
+
return token;
|
|
2875
|
+
}
|
|
2876
|
+
visitAlterTableAddConstraint(arg) {
|
|
2877
|
+
const keyword = arg.ifNotExists ? 'add if not exists' : 'add';
|
|
2878
|
+
const token = new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.container, '', SqlPrintToken_1.SqlPrintTokenContainerType.AlterTableAddConstraint);
|
|
2879
|
+
token.innerTokens.push(new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.keyword, keyword));
|
|
2880
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2881
|
+
token.innerTokens.push(arg.constraint.accept(this));
|
|
2882
|
+
if (arg.notValid) {
|
|
2883
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2884
|
+
token.innerTokens.push(new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.keyword, 'not valid'));
|
|
2885
|
+
}
|
|
2886
|
+
return token;
|
|
2887
|
+
}
|
|
2888
|
+
visitAlterTableDropConstraint(arg) {
|
|
2889
|
+
let keyword = 'drop constraint';
|
|
2890
|
+
if (arg.ifExists) {
|
|
2891
|
+
keyword += ' if exists';
|
|
2892
|
+
}
|
|
2893
|
+
const token = new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.container, '', SqlPrintToken_1.SqlPrintTokenContainerType.AlterTableDropConstraint);
|
|
2894
|
+
token.innerTokens.push(new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.keyword, keyword));
|
|
2895
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2896
|
+
token.innerTokens.push(arg.constraintName.accept(this));
|
|
2897
|
+
if (arg.behavior) {
|
|
2898
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2899
|
+
token.innerTokens.push(new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.keyword, arg.behavior));
|
|
2900
|
+
}
|
|
2901
|
+
return token;
|
|
2902
|
+
}
|
|
2903
|
+
visitAlterTableDropColumn(arg) {
|
|
2904
|
+
let keyword = 'drop column';
|
|
2905
|
+
if (arg.ifExists) {
|
|
2906
|
+
keyword += ' if exists';
|
|
2907
|
+
}
|
|
2908
|
+
const token = new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.container, '', SqlPrintToken_1.SqlPrintTokenContainerType.AlterTableDropColumn);
|
|
2909
|
+
token.innerTokens.push(new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.keyword, keyword));
|
|
2910
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2911
|
+
token.innerTokens.push(arg.columnName.accept(this));
|
|
2912
|
+
if (arg.behavior) {
|
|
2913
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2914
|
+
token.innerTokens.push(new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.keyword, arg.behavior));
|
|
2915
|
+
}
|
|
2916
|
+
return token;
|
|
2917
|
+
}
|
|
2918
|
+
visitDropConstraintStatement(arg) {
|
|
2919
|
+
let keyword = 'drop constraint';
|
|
2920
|
+
if (arg.ifExists) {
|
|
2921
|
+
keyword += ' if exists';
|
|
2922
|
+
}
|
|
2923
|
+
const token = new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.keyword, keyword, SqlPrintToken_1.SqlPrintTokenContainerType.DropConstraintStatement);
|
|
2924
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2925
|
+
token.innerTokens.push(arg.constraintName.accept(this));
|
|
2926
|
+
if (arg.behavior) {
|
|
2927
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2928
|
+
token.innerTokens.push(new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.keyword, arg.behavior));
|
|
2929
|
+
}
|
|
2930
|
+
return token;
|
|
2931
|
+
}
|
|
2932
|
+
visitExplainStatement(arg) {
|
|
2933
|
+
const token = new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.container, '', SqlPrintToken_1.SqlPrintTokenContainerType.ExplainStatement);
|
|
2934
|
+
token.innerTokens.push(new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.keyword, 'explain'));
|
|
2935
|
+
const inlineFlags = [];
|
|
2936
|
+
const optionList = [];
|
|
2937
|
+
if (arg.options) {
|
|
2938
|
+
for (const option of arg.options) {
|
|
2939
|
+
if (this.isExplainLegacyFlag(option) && this.isExplainBooleanTrue(option.value)) {
|
|
2940
|
+
inlineFlags.push(option);
|
|
2941
|
+
}
|
|
2942
|
+
else {
|
|
2943
|
+
optionList.push(option);
|
|
2944
|
+
}
|
|
2945
|
+
}
|
|
2946
|
+
}
|
|
2947
|
+
for (const flag of inlineFlags) {
|
|
2948
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2949
|
+
token.innerTokens.push(new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.keyword, flag.name.name.toLowerCase()));
|
|
2950
|
+
}
|
|
2951
|
+
if (optionList.length > 0) {
|
|
2952
|
+
// Keep the option list immediately after EXPLAIN without an extra space.
|
|
2953
|
+
token.innerTokens.push(SqlPrintTokenParser.PAREN_OPEN_TOKEN);
|
|
2954
|
+
for (let i = 0; i < optionList.length; i++) {
|
|
2955
|
+
if (i > 0) {
|
|
2956
|
+
token.innerTokens.push(SqlPrintTokenParser.COMMA_TOKEN);
|
|
2957
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2958
|
+
}
|
|
2959
|
+
token.innerTokens.push(this.renderExplainOption(optionList[i]));
|
|
2960
|
+
}
|
|
2961
|
+
token.innerTokens.push(SqlPrintTokenParser.PAREN_CLOSE_TOKEN);
|
|
2962
|
+
}
|
|
2963
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2964
|
+
token.innerTokens.push(arg.statement.accept(this));
|
|
2965
|
+
return token;
|
|
2966
|
+
}
|
|
2967
|
+
visitAnalyzeStatement(arg) {
|
|
2968
|
+
const keywordParts = ['analyze'];
|
|
2969
|
+
if (arg.verbose) {
|
|
2970
|
+
keywordParts.push('verbose');
|
|
2971
|
+
}
|
|
2972
|
+
const token = new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.keyword, keywordParts.join(' '), SqlPrintToken_1.SqlPrintTokenContainerType.AnalyzeStatement);
|
|
2973
|
+
// Render relation target when provided.
|
|
2974
|
+
if (arg.target) {
|
|
2975
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2976
|
+
token.innerTokens.push(this.renderQualifiedNameInline(arg.target));
|
|
2977
|
+
// Render column list inline (comma space) when present.
|
|
2978
|
+
if (arg.columns && arg.columns.length > 0) {
|
|
2979
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2980
|
+
token.innerTokens.push(SqlPrintTokenParser.PAREN_OPEN_TOKEN);
|
|
2981
|
+
for (let i = 0; i < arg.columns.length; i++) {
|
|
2982
|
+
if (i > 0) {
|
|
2983
|
+
token.innerTokens.push(SqlPrintTokenParser.COMMA_TOKEN);
|
|
2984
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2985
|
+
}
|
|
2986
|
+
token.innerTokens.push(this.renderIdentifierInline(arg.columns[i]));
|
|
2987
|
+
}
|
|
2988
|
+
token.innerTokens.push(SqlPrintTokenParser.PAREN_CLOSE_TOKEN);
|
|
2989
|
+
}
|
|
2990
|
+
}
|
|
2991
|
+
return token;
|
|
2992
|
+
}
|
|
2993
|
+
renderExplainOption(option) {
|
|
2994
|
+
const token = new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.container, '', SqlPrintToken_1.SqlPrintTokenContainerType.ExplainOption);
|
|
2995
|
+
token.innerTokens.push(new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.keyword, option.name.name.toLowerCase()));
|
|
2996
|
+
if (option.value && !this.isExplainBooleanTrue(option.value)) {
|
|
2997
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2998
|
+
token.innerTokens.push(option.value.accept(this));
|
|
2999
|
+
}
|
|
3000
|
+
return token;
|
|
3001
|
+
}
|
|
3002
|
+
isExplainLegacyFlag(option) {
|
|
3003
|
+
const name = option.name.name.toLowerCase();
|
|
3004
|
+
return name === 'analyze' || name === 'verbose';
|
|
3005
|
+
}
|
|
3006
|
+
isExplainBooleanTrue(value) {
|
|
3007
|
+
if (!value) {
|
|
3008
|
+
return false;
|
|
3009
|
+
}
|
|
3010
|
+
if (value instanceof ValueComponent_1.RawString) {
|
|
3011
|
+
const normalized = value.value.toLowerCase();
|
|
3012
|
+
return normalized === 'true' || normalized === 't' || normalized === 'on' || normalized === 'yes' || normalized === '1';
|
|
3013
|
+
}
|
|
3014
|
+
if (value instanceof ValueComponent_1.LiteralValue) {
|
|
3015
|
+
if (typeof value.value === 'boolean') {
|
|
3016
|
+
return value.value;
|
|
3017
|
+
}
|
|
3018
|
+
if (typeof value.value === 'number') {
|
|
3019
|
+
return value.value !== 0;
|
|
3020
|
+
}
|
|
3021
|
+
if (typeof value.value === 'string') {
|
|
3022
|
+
const normalized = value.value.toLowerCase();
|
|
3023
|
+
return normalized === 'true' || normalized === 't' || normalized === 'on' || normalized === 'yes' || normalized === '1';
|
|
3024
|
+
}
|
|
3025
|
+
}
|
|
3026
|
+
return false;
|
|
3027
|
+
}
|
|
3028
|
+
renderQualifiedNameInline(arg) {
|
|
3029
|
+
const parts = [];
|
|
3030
|
+
if (arg.namespaces && arg.namespaces.length > 0) {
|
|
3031
|
+
for (const ns of arg.namespaces) {
|
|
3032
|
+
parts.push(this.renderIdentifierText(ns));
|
|
3033
|
+
}
|
|
3034
|
+
}
|
|
3035
|
+
parts.push(this.renderIdentifierText(arg.name));
|
|
3036
|
+
return new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.value, parts.join('.'), SqlPrintToken_1.SqlPrintTokenContainerType.QualifiedName);
|
|
3037
|
+
}
|
|
3038
|
+
renderIdentifierInline(component) {
|
|
3039
|
+
return new SqlPrintToken_1.SqlPrintToken(SqlPrintToken_1.SqlPrintTokenType.value, this.renderIdentifierText(component), SqlPrintToken_1.SqlPrintTokenContainerType.IdentifierString);
|
|
3040
|
+
}
|
|
3041
|
+
renderIdentifierText(component) {
|
|
3042
|
+
if (component instanceof ValueComponent_1.IdentifierString) {
|
|
3043
|
+
if (component.name === '*') {
|
|
3044
|
+
return component.name;
|
|
3045
|
+
}
|
|
3046
|
+
return this.identifierDecorator.decorate(component.name);
|
|
3047
|
+
}
|
|
3048
|
+
return component.value;
|
|
3049
|
+
}
|
|
1943
3050
|
}
|
|
1944
3051
|
exports.SqlPrintTokenParser = SqlPrintTokenParser;
|
|
1945
3052
|
// Static tokens for common symbols
|