rawsql-ts 0.11.43-beta → 0.11.44-beta
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -12
- package/dist/esm/index.js +18 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/index.min.js +15 -19
- package/dist/esm/index.min.js.map +4 -4
- package/dist/esm/src/index.d.ts +18 -0
- package/dist/esm/src/index.js +18 -0
- package/dist/esm/src/index.js.map +1 -1
- package/dist/esm/src/models/BinarySelectQuery.d.ts +25 -1
- package/dist/esm/src/models/BinarySelectQuery.js +28 -0
- package/dist/esm/src/models/BinarySelectQuery.js.map +1 -1
- package/dist/esm/src/models/Clause.d.ts +14 -2
- package/dist/esm/src/models/Clause.js +26 -1
- package/dist/esm/src/models/Clause.js.map +1 -1
- package/dist/esm/src/models/CreateTableQuery.d.ts +99 -5
- package/dist/esm/src/models/CreateTableQuery.js +85 -10
- package/dist/esm/src/models/CreateTableQuery.js.map +1 -1
- package/dist/esm/src/models/DDLStatements.d.ts +157 -0
- package/dist/esm/src/models/DDLStatements.js +141 -0
- package/dist/esm/src/models/DDLStatements.js.map +1 -0
- package/dist/esm/src/models/DeleteQuery.d.ts +17 -0
- package/dist/esm/src/models/DeleteQuery.js +16 -0
- package/dist/esm/src/models/DeleteQuery.js.map +1 -0
- package/dist/esm/src/models/InsertQuery.d.ts +7 -1
- package/dist/esm/src/models/InsertQuery.js +6 -2
- package/dist/esm/src/models/InsertQuery.js.map +1 -1
- package/dist/esm/src/models/MergeQuery.d.ts +63 -0
- package/dist/esm/src/models/MergeQuery.js +94 -0
- package/dist/esm/src/models/MergeQuery.js.map +1 -0
- package/dist/esm/src/models/SelectQuery.d.ts +37 -1
- package/dist/esm/src/models/SelectQuery.js +4 -1
- package/dist/esm/src/models/SelectQuery.js.map +1 -1
- package/dist/esm/src/models/SimpleSelectQuery.d.ts +29 -1
- package/dist/esm/src/models/SimpleSelectQuery.js +32 -0
- package/dist/esm/src/models/SimpleSelectQuery.js.map +1 -1
- package/dist/esm/src/models/SqlComponent.d.ts +2 -1
- package/dist/esm/src/models/SqlComponent.js +1 -1
- package/dist/esm/src/models/SqlComponent.js.map +1 -1
- package/dist/esm/src/models/SqlPrintToken.d.ts +33 -0
- package/dist/esm/src/models/SqlPrintToken.js +32 -0
- package/dist/esm/src/models/SqlPrintToken.js.map +1 -1
- package/dist/esm/src/models/ValuesQuery.d.ts +25 -1
- package/dist/esm/src/models/ValuesQuery.js +28 -0
- package/dist/esm/src/models/ValuesQuery.js.map +1 -1
- package/dist/esm/src/parsers/AlterTableParser.d.ts +25 -0
- package/dist/esm/src/parsers/AlterTableParser.js +428 -0
- package/dist/esm/src/parsers/AlterTableParser.js.map +1 -0
- package/dist/esm/src/parsers/CreateIndexParser.d.ts +16 -0
- package/dist/esm/src/parsers/CreateIndexParser.js +237 -0
- package/dist/esm/src/parsers/CreateIndexParser.js.map +1 -0
- package/dist/esm/src/parsers/CreateTableParser.d.ts +41 -0
- package/dist/esm/src/parsers/CreateTableParser.js +734 -0
- package/dist/esm/src/parsers/CreateTableParser.js.map +1 -0
- package/dist/esm/src/parsers/DeleteClauseParser.d.ts +11 -0
- package/dist/esm/src/parsers/DeleteClauseParser.js +33 -0
- package/dist/esm/src/parsers/DeleteClauseParser.js.map +1 -0
- package/dist/esm/src/parsers/DeleteQueryParser.d.ts +16 -0
- package/dist/esm/src/parsers/DeleteQueryParser.js +73 -0
- package/dist/esm/src/parsers/DeleteQueryParser.js.map +1 -0
- package/dist/esm/src/parsers/DropConstraintParser.d.ts +12 -0
- package/dist/esm/src/parsers/DropConstraintParser.js +47 -0
- package/dist/esm/src/parsers/DropConstraintParser.js.map +1 -0
- package/dist/esm/src/parsers/DropIndexParser.d.ts +12 -0
- package/dist/esm/src/parsers/DropIndexParser.js +69 -0
- package/dist/esm/src/parsers/DropIndexParser.js.map +1 -0
- package/dist/esm/src/parsers/DropTableParser.d.ts +12 -0
- package/dist/esm/src/parsers/DropTableParser.js +59 -0
- package/dist/esm/src/parsers/DropTableParser.js.map +1 -0
- package/dist/esm/src/parsers/FunctionExpressionParser.d.ts +4 -0
- package/dist/esm/src/parsers/FunctionExpressionParser.js +25 -8
- package/dist/esm/src/parsers/FunctionExpressionParser.js.map +1 -1
- package/dist/esm/src/parsers/InsertQueryParser.js +103 -31
- package/dist/esm/src/parsers/InsertQueryParser.js.map +1 -1
- package/dist/esm/src/parsers/MergeQueryParser.d.ts +26 -0
- package/dist/esm/src/parsers/MergeQueryParser.js +479 -0
- package/dist/esm/src/parsers/MergeQueryParser.js.map +1 -0
- package/dist/esm/src/parsers/ReturningClauseParser.js +50 -7
- package/dist/esm/src/parsers/ReturningClauseParser.js.map +1 -1
- package/dist/esm/src/parsers/SelectClauseParser.js +3 -3
- package/dist/esm/src/parsers/SelectClauseParser.js.map +1 -1
- package/dist/esm/src/parsers/SelectQueryParser.d.ts +4 -0
- package/dist/esm/src/parsers/SelectQueryParser.js +4 -0
- package/dist/esm/src/parsers/SelectQueryParser.js.map +1 -1
- package/dist/esm/src/parsers/SetClauseParser.js +97 -15
- package/dist/esm/src/parsers/SetClauseParser.js.map +1 -1
- package/dist/esm/src/parsers/SqlParser.d.ts +38 -0
- package/dist/esm/src/parsers/SqlParser.js +344 -0
- package/dist/esm/src/parsers/SqlParser.js.map +1 -0
- package/dist/esm/src/parsers/SqlPrintTokenParser.d.ts +57 -3
- package/dist/esm/src/parsers/SqlPrintTokenParser.js +1016 -33
- package/dist/esm/src/parsers/SqlPrintTokenParser.js.map +1 -1
- package/dist/esm/src/parsers/SqlTokenizer.d.ts +24 -2
- package/dist/esm/src/parsers/SqlTokenizer.js +135 -74
- package/dist/esm/src/parsers/SqlTokenizer.js.map +1 -1
- package/dist/esm/src/parsers/UpdateQueryParser.js +11 -1
- package/dist/esm/src/parsers/UpdateQueryParser.js.map +1 -1
- package/dist/esm/src/parsers/UsingClauseParser.d.ts +11 -0
- package/dist/esm/src/parsers/UsingClauseParser.js +29 -0
- package/dist/esm/src/parsers/UsingClauseParser.js.map +1 -0
- package/dist/esm/src/parsers/ValueParser.js +5 -1
- package/dist/esm/src/parsers/ValueParser.js.map +1 -1
- package/dist/esm/src/parsers/ValuesQueryParser.d.ts +0 -2
- package/dist/esm/src/parsers/ValuesQueryParser.js +5 -45
- package/dist/esm/src/parsers/ValuesQueryParser.js.map +1 -1
- package/dist/esm/src/parsers/utils/LexemeCommentUtils.d.ts +6 -0
- package/dist/esm/src/parsers/utils/LexemeCommentUtils.js +26 -0
- package/dist/esm/src/parsers/utils/LexemeCommentUtils.js.map +1 -0
- package/dist/esm/src/tokenReaders/CommandTokenReader.js +49 -2
- package/dist/esm/src/tokenReaders/CommandTokenReader.js.map +1 -1
- package/dist/esm/src/tokenReaders/LiteralTokenReader.js +8 -5
- package/dist/esm/src/tokenReaders/LiteralTokenReader.js.map +1 -1
- package/dist/esm/src/tokenReaders/OperatorTokenReader.js +10 -1
- package/dist/esm/src/tokenReaders/OperatorTokenReader.js.map +1 -1
- package/dist/esm/src/tokenReaders/TypeTokenReader.js +11 -1
- package/dist/esm/src/tokenReaders/TypeTokenReader.js.map +1 -1
- package/dist/esm/src/transformers/InsertQuerySelectValuesConverter.d.ts +18 -0
- package/dist/esm/src/transformers/InsertQuerySelectValuesConverter.js +118 -0
- package/dist/esm/src/transformers/InsertQuerySelectValuesConverter.js.map +1 -0
- package/dist/esm/src/transformers/LinePrinter.d.ts +1 -0
- package/dist/esm/src/transformers/LinePrinter.js +12 -0
- package/dist/esm/src/transformers/LinePrinter.js.map +1 -1
- package/dist/esm/src/transformers/OnelineFormattingHelper.d.ts +29 -0
- package/dist/esm/src/transformers/OnelineFormattingHelper.js +88 -0
- package/dist/esm/src/transformers/OnelineFormattingHelper.js.map +1 -0
- package/dist/esm/src/transformers/QueryBuilder.d.ts +47 -13
- package/dist/esm/src/transformers/QueryBuilder.js +424 -62
- package/dist/esm/src/transformers/QueryBuilder.js.map +1 -1
- package/dist/esm/src/transformers/SqlFormatter.d.ts +13 -1
- package/dist/esm/src/transformers/SqlFormatter.js +13 -4
- package/dist/esm/src/transformers/SqlFormatter.js.map +1 -1
- package/dist/esm/src/transformers/SqlPrinter.d.ts +46 -8
- package/dist/esm/src/transformers/SqlPrinter.js +596 -71
- package/dist/esm/src/transformers/SqlPrinter.js.map +1 -1
- package/dist/esm/src/types/Formatting.d.ts +8 -0
- package/dist/esm/src/types/Formatting.js +2 -0
- package/dist/esm/src/types/Formatting.js.map +1 -0
- package/dist/esm/src/utils/ParserStringUtils.d.ts +6 -0
- package/dist/esm/src/utils/ParserStringUtils.js +28 -0
- package/dist/esm/src/utils/ParserStringUtils.js.map +1 -0
- package/dist/esm/tsconfig.browser.tsbuildinfo +1 -1
- package/dist/index.min.js +14 -18
- package/dist/index.min.js.map +4 -4
- package/dist/src/index.d.ts +18 -0
- package/dist/src/index.js +18 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/models/BinarySelectQuery.d.ts +25 -1
- package/dist/src/models/BinarySelectQuery.js +28 -0
- package/dist/src/models/BinarySelectQuery.js.map +1 -1
- package/dist/src/models/Clause.d.ts +14 -2
- package/dist/src/models/Clause.js +29 -2
- package/dist/src/models/Clause.js.map +1 -1
- package/dist/src/models/CreateTableQuery.d.ts +99 -5
- package/dist/src/models/CreateTableQuery.js +90 -11
- package/dist/src/models/CreateTableQuery.js.map +1 -1
- package/dist/src/models/DDLStatements.d.ts +157 -0
- package/dist/src/models/DDLStatements.js +153 -0
- package/dist/src/models/DDLStatements.js.map +1 -0
- package/dist/src/models/DeleteQuery.d.ts +17 -0
- package/dist/src/models/DeleteQuery.js +20 -0
- package/dist/src/models/DeleteQuery.js.map +1 -0
- package/dist/src/models/InsertQuery.d.ts +7 -1
- package/dist/src/models/InsertQuery.js +6 -2
- package/dist/src/models/InsertQuery.js.map +1 -1
- package/dist/src/models/MergeQuery.d.ts +63 -0
- package/dist/src/models/MergeQuery.js +104 -0
- package/dist/src/models/MergeQuery.js.map +1 -0
- package/dist/src/models/SelectQuery.d.ts +37 -1
- package/dist/src/models/SelectQuery.js +7 -1
- package/dist/src/models/SelectQuery.js.map +1 -1
- package/dist/src/models/SimpleSelectQuery.d.ts +29 -1
- package/dist/src/models/SimpleSelectQuery.js +32 -0
- package/dist/src/models/SimpleSelectQuery.js.map +1 -1
- package/dist/src/models/SqlComponent.d.ts +2 -1
- package/dist/src/models/SqlComponent.js +1 -1
- package/dist/src/models/SqlComponent.js.map +1 -1
- package/dist/src/models/SqlPrintToken.d.ts +33 -0
- package/dist/src/models/SqlPrintToken.js +32 -0
- package/dist/src/models/SqlPrintToken.js.map +1 -1
- package/dist/src/models/ValuesQuery.d.ts +25 -1
- package/dist/src/models/ValuesQuery.js +28 -0
- package/dist/src/models/ValuesQuery.js.map +1 -1
- package/dist/src/parsers/AlterTableParser.d.ts +25 -0
- package/dist/src/parsers/AlterTableParser.js +432 -0
- package/dist/src/parsers/AlterTableParser.js.map +1 -0
- package/dist/src/parsers/CreateIndexParser.d.ts +16 -0
- package/dist/src/parsers/CreateIndexParser.js +241 -0
- package/dist/src/parsers/CreateIndexParser.js.map +1 -0
- package/dist/src/parsers/CreateTableParser.d.ts +41 -0
- package/dist/src/parsers/CreateTableParser.js +738 -0
- package/dist/src/parsers/CreateTableParser.js.map +1 -0
- package/dist/src/parsers/DeleteClauseParser.d.ts +11 -0
- package/dist/src/parsers/DeleteClauseParser.js +37 -0
- package/dist/src/parsers/DeleteClauseParser.js.map +1 -0
- package/dist/src/parsers/DeleteQueryParser.d.ts +16 -0
- package/dist/src/parsers/DeleteQueryParser.js +77 -0
- package/dist/src/parsers/DeleteQueryParser.js.map +1 -0
- package/dist/src/parsers/DropConstraintParser.d.ts +12 -0
- package/dist/src/parsers/DropConstraintParser.js +51 -0
- package/dist/src/parsers/DropConstraintParser.js.map +1 -0
- package/dist/src/parsers/DropIndexParser.d.ts +12 -0
- package/dist/src/parsers/DropIndexParser.js +73 -0
- package/dist/src/parsers/DropIndexParser.js.map +1 -0
- package/dist/src/parsers/DropTableParser.d.ts +12 -0
- package/dist/src/parsers/DropTableParser.js +63 -0
- package/dist/src/parsers/DropTableParser.js.map +1 -0
- package/dist/src/parsers/FunctionExpressionParser.d.ts +4 -0
- package/dist/src/parsers/FunctionExpressionParser.js +25 -8
- package/dist/src/parsers/FunctionExpressionParser.js.map +1 -1
- package/dist/src/parsers/InsertQueryParser.js +103 -31
- package/dist/src/parsers/InsertQueryParser.js.map +1 -1
- package/dist/src/parsers/MergeQueryParser.d.ts +26 -0
- package/dist/src/parsers/MergeQueryParser.js +483 -0
- package/dist/src/parsers/MergeQueryParser.js.map +1 -0
- package/dist/src/parsers/ReturningClauseParser.js +50 -7
- package/dist/src/parsers/ReturningClauseParser.js.map +1 -1
- package/dist/src/parsers/SelectClauseParser.js +2 -2
- package/dist/src/parsers/SelectClauseParser.js.map +1 -1
- package/dist/src/parsers/SelectQueryParser.d.ts +4 -0
- package/dist/src/parsers/SelectQueryParser.js +4 -0
- package/dist/src/parsers/SelectQueryParser.js.map +1 -1
- package/dist/src/parsers/SetClauseParser.js +97 -15
- package/dist/src/parsers/SetClauseParser.js.map +1 -1
- package/dist/src/parsers/SqlParser.d.ts +38 -0
- package/dist/src/parsers/SqlParser.js +353 -0
- package/dist/src/parsers/SqlParser.js.map +1 -0
- package/dist/src/parsers/SqlPrintTokenParser.d.ts +57 -3
- package/dist/src/parsers/SqlPrintTokenParser.js +1014 -31
- package/dist/src/parsers/SqlPrintTokenParser.js.map +1 -1
- package/dist/src/parsers/SqlTokenizer.d.ts +24 -2
- package/dist/src/parsers/SqlTokenizer.js +139 -74
- package/dist/src/parsers/SqlTokenizer.js.map +1 -1
- package/dist/src/parsers/UpdateQueryParser.js +11 -1
- package/dist/src/parsers/UpdateQueryParser.js.map +1 -1
- package/dist/src/parsers/UsingClauseParser.d.ts +11 -0
- package/dist/src/parsers/UsingClauseParser.js +33 -0
- package/dist/src/parsers/UsingClauseParser.js.map +1 -0
- package/dist/src/parsers/ValueParser.js +5 -1
- package/dist/src/parsers/ValueParser.js.map +1 -1
- package/dist/src/parsers/ValuesQueryParser.d.ts +0 -2
- package/dist/src/parsers/ValuesQueryParser.js +5 -45
- package/dist/src/parsers/ValuesQueryParser.js.map +1 -1
- package/dist/src/parsers/utils/LexemeCommentUtils.d.ts +6 -0
- package/dist/src/parsers/utils/LexemeCommentUtils.js +29 -0
- package/dist/src/parsers/utils/LexemeCommentUtils.js.map +1 -0
- package/dist/src/tokenReaders/CommandTokenReader.js +49 -2
- package/dist/src/tokenReaders/CommandTokenReader.js.map +1 -1
- package/dist/src/tokenReaders/LiteralTokenReader.js +8 -5
- package/dist/src/tokenReaders/LiteralTokenReader.js.map +1 -1
- package/dist/src/tokenReaders/OperatorTokenReader.js +10 -1
- package/dist/src/tokenReaders/OperatorTokenReader.js.map +1 -1
- package/dist/src/tokenReaders/TypeTokenReader.js +11 -1
- package/dist/src/tokenReaders/TypeTokenReader.js.map +1 -1
- package/dist/src/transformers/InsertQuerySelectValuesConverter.d.ts +18 -0
- package/dist/src/transformers/InsertQuerySelectValuesConverter.js +122 -0
- package/dist/src/transformers/InsertQuerySelectValuesConverter.js.map +1 -0
- package/dist/src/transformers/LinePrinter.d.ts +1 -0
- package/dist/src/transformers/LinePrinter.js +12 -0
- package/dist/src/transformers/LinePrinter.js.map +1 -1
- package/dist/src/transformers/OnelineFormattingHelper.d.ts +29 -0
- package/dist/src/transformers/OnelineFormattingHelper.js +92 -0
- package/dist/src/transformers/OnelineFormattingHelper.js.map +1 -0
- package/dist/src/transformers/QueryBuilder.d.ts +47 -13
- package/dist/src/transformers/QueryBuilder.js +433 -60
- package/dist/src/transformers/QueryBuilder.js.map +1 -1
- package/dist/src/transformers/SqlFormatter.d.ts +13 -1
- package/dist/src/transformers/SqlFormatter.js +20 -5
- package/dist/src/transformers/SqlFormatter.js.map +1 -1
- package/dist/src/transformers/SqlPrinter.d.ts +46 -8
- package/dist/src/transformers/SqlPrinter.js +596 -71
- package/dist/src/transformers/SqlPrinter.js.map +1 -1
- package/dist/src/types/Formatting.d.ts +8 -0
- package/dist/src/types/Formatting.js +3 -0
- package/dist/src/types/Formatting.js.map +1 -0
- package/dist/src/utils/ParserStringUtils.d.ts +6 -0
- package/dist/src/utils/ParserStringUtils.js +31 -0
- package/dist/src/utils/ParserStringUtils.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PartitionByClause, OrderByClause, OrderByItem, SelectClause, SelectItem, Distinct, DistinctOn, SortDirection, NullsSortDirection, TableSource, SourceExpression, FromClause, JoinClause, JoinOnClause, JoinUsingClause, FunctionSource, SourceAliasExpression, WhereClause, GroupByClause, HavingClause, SubQuerySource, WindowFrameClause, LimitClause, ForClause, OffsetClause, WindowsClause as WindowClause, CommonTable, WithClause, FetchClause, FetchExpression, InsertClause, UpdateClause, SetClause, ReturningClause, SetClauseItem } from "../models/Clause";
|
|
1
|
+
import { PartitionByClause, OrderByClause, OrderByItem, SelectClause, SelectItem, Distinct, DistinctOn, SortDirection, NullsSortDirection, TableSource, SourceExpression, FromClause, JoinClause, JoinOnClause, JoinUsingClause, FunctionSource, SourceAliasExpression, WhereClause, GroupByClause, HavingClause, SubQuerySource, WindowFrameClause, LimitClause, ForClause, OffsetClause, WindowsClause as WindowClause, CommonTable, WithClause, FetchClause, FetchExpression, InsertClause, UpdateClause, DeleteClause, UsingClause, SetClause, ReturningClause, SetClauseItem } from "../models/Clause";
|
|
2
2
|
import { HintClause } from "../models/HintClause";
|
|
3
3
|
import { BinarySelectQuery, SimpleSelectQuery, ValuesQuery } from "../models/SelectQuery";
|
|
4
4
|
import { SqlPrintToken, SqlPrintTokenType, SqlPrintTokenContainerType } from "../models/SqlPrintToken";
|
|
@@ -8,7 +8,10 @@ import { IdentifierDecorator } from "./IdentifierDecorator";
|
|
|
8
8
|
import { ParameterDecorator } from "./ParameterDecorator";
|
|
9
9
|
import { InsertQuery } from "../models/InsertQuery";
|
|
10
10
|
import { UpdateQuery } from "../models/UpdateQuery";
|
|
11
|
-
import {
|
|
11
|
+
import { DeleteQuery } from "../models/DeleteQuery";
|
|
12
|
+
import { CreateTableQuery, TableColumnDefinition, ColumnConstraintDefinition, TableConstraintDefinition, ReferenceDefinition } from "../models/CreateTableQuery";
|
|
13
|
+
import { MergeQuery, MergeWhenClause, MergeUpdateAction, MergeDeleteAction, MergeInsertAction, MergeDoNothingAction } from "../models/MergeQuery";
|
|
14
|
+
import { DropTableStatement, DropIndexStatement, CreateIndexStatement, IndexColumnDefinition, AlterTableStatement, AlterTableAddConstraint, AlterTableDropConstraint, AlterTableDropColumn, DropConstraintStatement } from "../models/DDLStatements";
|
|
12
15
|
export var ParameterStyle;
|
|
13
16
|
(function (ParameterStyle) {
|
|
14
17
|
ParameterStyle["Anonymous"] = "anonymous";
|
|
@@ -20,36 +23,45 @@ export const PRESETS = {
|
|
|
20
23
|
identifierEscape: { start: '`', end: '`' },
|
|
21
24
|
parameterSymbol: '?',
|
|
22
25
|
parameterStyle: ParameterStyle.Anonymous,
|
|
26
|
+
constraintStyle: 'mysql',
|
|
23
27
|
},
|
|
24
28
|
postgres: {
|
|
25
29
|
identifierEscape: { start: '"', end: '"' },
|
|
26
30
|
parameterSymbol: '$',
|
|
27
31
|
parameterStyle: ParameterStyle.Indexed,
|
|
32
|
+
castStyle: 'postgres',
|
|
33
|
+
constraintStyle: 'postgres',
|
|
28
34
|
},
|
|
29
35
|
postgresWithNamedParams: {
|
|
30
36
|
identifierEscape: { start: '"', end: '"' },
|
|
31
37
|
parameterSymbol: ':',
|
|
32
38
|
parameterStyle: ParameterStyle.Named,
|
|
39
|
+
castStyle: 'postgres',
|
|
40
|
+
constraintStyle: 'postgres',
|
|
33
41
|
},
|
|
34
42
|
sqlserver: {
|
|
35
43
|
identifierEscape: { start: '[', end: ']' },
|
|
36
44
|
parameterSymbol: '@',
|
|
37
45
|
parameterStyle: ParameterStyle.Named,
|
|
46
|
+
constraintStyle: 'postgres',
|
|
38
47
|
},
|
|
39
48
|
sqlite: {
|
|
40
49
|
identifierEscape: { start: '"', end: '"' },
|
|
41
50
|
parameterSymbol: ':',
|
|
42
51
|
parameterStyle: ParameterStyle.Named,
|
|
52
|
+
constraintStyle: 'postgres',
|
|
43
53
|
},
|
|
44
54
|
oracle: {
|
|
45
55
|
identifierEscape: { start: '"', end: '"' },
|
|
46
56
|
parameterSymbol: ':',
|
|
47
57
|
parameterStyle: ParameterStyle.Named,
|
|
58
|
+
constraintStyle: 'postgres',
|
|
48
59
|
},
|
|
49
60
|
clickhouse: {
|
|
50
61
|
identifierEscape: { start: '`', end: '`' },
|
|
51
62
|
parameterSymbol: '?',
|
|
52
63
|
parameterStyle: ParameterStyle.Anonymous,
|
|
64
|
+
constraintStyle: 'postgres',
|
|
53
65
|
},
|
|
54
66
|
firebird: {
|
|
55
67
|
identifierEscape: { start: '"', end: '"' },
|
|
@@ -80,6 +92,7 @@ export const PRESETS = {
|
|
|
80
92
|
identifierEscape: { start: '"', end: '"' },
|
|
81
93
|
parameterSymbol: '$',
|
|
82
94
|
parameterStyle: ParameterStyle.Indexed,
|
|
95
|
+
castStyle: 'postgres',
|
|
83
96
|
},
|
|
84
97
|
athena: {
|
|
85
98
|
identifierEscape: { start: '"', end: '"' },
|
|
@@ -105,6 +118,7 @@ export const PRESETS = {
|
|
|
105
118
|
identifierEscape: { start: '"', end: '"' },
|
|
106
119
|
parameterSymbol: '$',
|
|
107
120
|
parameterStyle: ParameterStyle.Indexed,
|
|
121
|
+
castStyle: 'postgres',
|
|
108
122
|
},
|
|
109
123
|
flinksql: {
|
|
110
124
|
identifierEscape: { start: '`', end: '`' },
|
|
@@ -139,9 +153,10 @@ export class SqlPrintTokenParser {
|
|
|
139
153
|
return this._selfHandlingComponentTypes;
|
|
140
154
|
}
|
|
141
155
|
constructor(options) {
|
|
142
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
156
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
143
157
|
this.handlers = new Map();
|
|
144
158
|
this.index = 1;
|
|
159
|
+
this.joinConditionContexts = [];
|
|
145
160
|
if (options === null || options === void 0 ? void 0 : options.preset) {
|
|
146
161
|
const preset = options.preset;
|
|
147
162
|
options = Object.assign(Object.assign({}, preset), options);
|
|
@@ -155,6 +170,9 @@ export class SqlPrintTokenParser {
|
|
|
155
170
|
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 : '"',
|
|
156
171
|
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 : '"'
|
|
157
172
|
});
|
|
173
|
+
this.castStyle = (_h = options === null || options === void 0 ? void 0 : options.castStyle) !== null && _h !== void 0 ? _h : 'standard';
|
|
174
|
+
this.constraintStyle = (_j = options === null || options === void 0 ? void 0 : options.constraintStyle) !== null && _j !== void 0 ? _j : 'postgres';
|
|
175
|
+
this.normalizeJoinConditionOrder = (_k = options === null || options === void 0 ? void 0 : options.joinConditionOrderByDeclaration) !== null && _k !== void 0 ? _k : false;
|
|
158
176
|
this.handlers.set(ValueList.kind, (expr) => this.visitValueList(expr));
|
|
159
177
|
this.handlers.set(ColumnReference.kind, (expr) => this.visitColumnReference(expr));
|
|
160
178
|
this.handlers.set(QualifiedName.kind, (expr) => this.visitQualifiedName(expr));
|
|
@@ -226,10 +244,32 @@ export class SqlPrintTokenParser {
|
|
|
226
244
|
this.handlers.set(InsertClause.kind, (expr) => this.visitInsertClause(expr));
|
|
227
245
|
this.handlers.set(UpdateQuery.kind, (expr) => this.visitUpdateQuery(expr));
|
|
228
246
|
this.handlers.set(UpdateClause.kind, (expr) => this.visitUpdateClause(expr));
|
|
247
|
+
this.handlers.set(DeleteQuery.kind, (expr) => this.visitDeleteQuery(expr));
|
|
248
|
+
this.handlers.set(DeleteClause.kind, (expr) => this.visitDeleteClause(expr));
|
|
249
|
+
this.handlers.set(UsingClause.kind, (expr) => this.visitUsingClause(expr));
|
|
229
250
|
this.handlers.set(SetClause.kind, (expr) => this.visitSetClause(expr));
|
|
230
251
|
this.handlers.set(SetClauseItem.kind, (expr) => this.visitSetClauseItem(expr));
|
|
231
252
|
this.handlers.set(ReturningClause.kind, (expr) => this.visitReturningClause(expr));
|
|
232
253
|
this.handlers.set(CreateTableQuery.kind, (expr) => this.visitCreateTableQuery(expr));
|
|
254
|
+
this.handlers.set(TableColumnDefinition.kind, (expr) => this.visitTableColumnDefinition(expr));
|
|
255
|
+
this.handlers.set(ColumnConstraintDefinition.kind, (expr) => this.visitColumnConstraintDefinition(expr));
|
|
256
|
+
this.handlers.set(TableConstraintDefinition.kind, (expr) => this.visitTableConstraintDefinition(expr));
|
|
257
|
+
this.handlers.set(ReferenceDefinition.kind, (expr) => this.visitReferenceDefinition(expr));
|
|
258
|
+
this.handlers.set(CreateIndexStatement.kind, (expr) => this.visitCreateIndexStatement(expr));
|
|
259
|
+
this.handlers.set(IndexColumnDefinition.kind, (expr) => this.visitIndexColumnDefinition(expr));
|
|
260
|
+
this.handlers.set(DropTableStatement.kind, (expr) => this.visitDropTableStatement(expr));
|
|
261
|
+
this.handlers.set(DropIndexStatement.kind, (expr) => this.visitDropIndexStatement(expr));
|
|
262
|
+
this.handlers.set(AlterTableStatement.kind, (expr) => this.visitAlterTableStatement(expr));
|
|
263
|
+
this.handlers.set(AlterTableAddConstraint.kind, (expr) => this.visitAlterTableAddConstraint(expr));
|
|
264
|
+
this.handlers.set(AlterTableDropConstraint.kind, (expr) => this.visitAlterTableDropConstraint(expr));
|
|
265
|
+
this.handlers.set(AlterTableDropColumn.kind, (expr) => this.visitAlterTableDropColumn(expr));
|
|
266
|
+
this.handlers.set(DropConstraintStatement.kind, (expr) => this.visitDropConstraintStatement(expr));
|
|
267
|
+
this.handlers.set(MergeQuery.kind, (expr) => this.visitMergeQuery(expr));
|
|
268
|
+
this.handlers.set(MergeWhenClause.kind, (expr) => this.visitMergeWhenClause(expr));
|
|
269
|
+
this.handlers.set(MergeUpdateAction.kind, (expr) => this.visitMergeUpdateAction(expr));
|
|
270
|
+
this.handlers.set(MergeDeleteAction.kind, (expr) => this.visitMergeDeleteAction(expr));
|
|
271
|
+
this.handlers.set(MergeInsertAction.kind, (expr) => this.visitMergeInsertAction(expr));
|
|
272
|
+
this.handlers.set(MergeDoNothingAction.kind, (expr) => this.visitMergeDoNothingAction(expr));
|
|
233
273
|
}
|
|
234
274
|
/**
|
|
235
275
|
* Pretty-prints a BinarySelectQuery (e.g., UNION, INTERSECT, EXCEPT).
|
|
@@ -250,7 +290,7 @@ export class SqlPrintTokenParser {
|
|
|
250
290
|
token.innerTokens.push(mergedHeaderComment);
|
|
251
291
|
}
|
|
252
292
|
else {
|
|
253
|
-
const headerCommentBlocks = this.createCommentBlocks(arg.headerComments);
|
|
293
|
+
const headerCommentBlocks = this.createCommentBlocks(arg.headerComments, true);
|
|
254
294
|
token.innerTokens.push(...headerCommentBlocks);
|
|
255
295
|
}
|
|
256
296
|
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
@@ -498,10 +538,11 @@ export class SqlPrintTokenParser {
|
|
|
498
538
|
}
|
|
499
539
|
/**
|
|
500
540
|
* Creates CommentBlock containers for the given comments.
|
|
501
|
-
* Each CommentBlock contains: Comment -> CommentNewline -> Space
|
|
502
|
-
*
|
|
541
|
+
* Each CommentBlock contains: Comment -> CommentNewline -> Space.
|
|
542
|
+
* @param comments Raw comment strings to convert into CommentBlock tokens.
|
|
543
|
+
* @param isHeaderComment Marks the generated blocks as originating from header comments when true.
|
|
503
544
|
*/
|
|
504
|
-
createCommentBlocks(comments) {
|
|
545
|
+
createCommentBlocks(comments, isHeaderComment = false) {
|
|
505
546
|
// Create individual comment blocks for each comment entry
|
|
506
547
|
const commentBlocks = [];
|
|
507
548
|
for (const comment of comments) {
|
|
@@ -509,7 +550,7 @@ export class SqlPrintTokenParser {
|
|
|
509
550
|
const trimmed = comment.trim();
|
|
510
551
|
const isSeparatorLine = /^[-=_+*#]+$/.test(trimmed);
|
|
511
552
|
if (trimmed || isSeparatorLine || comment === '') {
|
|
512
|
-
commentBlocks.push(this.createSingleCommentBlock(comment));
|
|
553
|
+
commentBlocks.push(this.createSingleCommentBlock(comment, isHeaderComment));
|
|
513
554
|
}
|
|
514
555
|
}
|
|
515
556
|
return commentBlocks;
|
|
@@ -549,8 +590,11 @@ export class SqlPrintTokenParser {
|
|
|
549
590
|
* - Multiline mode: Comment + newline (space is filtered as leading space)
|
|
550
591
|
* - Oneliner mode: Comment + space (commentNewline is skipped)
|
|
551
592
|
*/
|
|
552
|
-
createSingleCommentBlock(comment) {
|
|
593
|
+
createSingleCommentBlock(comment, isHeaderComment = false) {
|
|
553
594
|
const commentBlock = new SqlPrintToken(SqlPrintTokenType.container, '', SqlPrintTokenContainerType.CommentBlock);
|
|
595
|
+
if (isHeaderComment) {
|
|
596
|
+
commentBlock.markAsHeaderComment();
|
|
597
|
+
}
|
|
554
598
|
// Add comment token - preserve original format for line comments
|
|
555
599
|
const commentToken = new SqlPrintToken(SqlPrintTokenType.comment, this.formatComment(comment));
|
|
556
600
|
commentBlock.innerTokens.push(commentToken);
|
|
@@ -748,6 +792,7 @@ export class SqlPrintTokenParser {
|
|
|
748
792
|
}
|
|
749
793
|
createHeaderMultiLineCommentBlock(headerComments) {
|
|
750
794
|
const commentBlock = new SqlPrintToken(SqlPrintTokenType.container, '', SqlPrintTokenContainerType.CommentBlock);
|
|
795
|
+
commentBlock.markAsHeaderComment();
|
|
751
796
|
if (headerComments.length === 0) {
|
|
752
797
|
const commentToken = new SqlPrintToken(SqlPrintTokenType.comment, '/* */');
|
|
753
798
|
commentBlock.innerTokens.push(commentToken);
|
|
@@ -818,7 +863,6 @@ export class SqlPrintTokenParser {
|
|
|
818
863
|
}
|
|
819
864
|
visitFunctionCall(arg) {
|
|
820
865
|
const token = new SqlPrintToken(SqlPrintTokenType.container, '', SqlPrintTokenContainerType.FunctionCall);
|
|
821
|
-
this.addComponentComments(token, arg);
|
|
822
866
|
token.innerTokens.push(arg.qualifiedName.accept(this));
|
|
823
867
|
token.innerTokens.push(SqlPrintTokenParser.PAREN_OPEN_TOKEN);
|
|
824
868
|
if (arg.argument) {
|
|
@@ -856,6 +900,7 @@ export class SqlPrintTokenParser {
|
|
|
856
900
|
token.innerTokens.push(SqlPrintTokenParser.PAREN_CLOSE_TOKEN);
|
|
857
901
|
}
|
|
858
902
|
}
|
|
903
|
+
this.addComponentComments(token, arg);
|
|
859
904
|
return token;
|
|
860
905
|
}
|
|
861
906
|
visitUnaryExpression(arg) {
|
|
@@ -1060,9 +1105,22 @@ export class SqlPrintTokenParser {
|
|
|
1060
1105
|
}
|
|
1061
1106
|
visitCastExpression(arg) {
|
|
1062
1107
|
const token = new SqlPrintToken(SqlPrintTokenType.container, '', SqlPrintTokenContainerType.CastExpression);
|
|
1108
|
+
// Use PostgreSQL-specific :: casts only when the preset explicitly opts in.
|
|
1109
|
+
if (this.castStyle === 'postgres') {
|
|
1110
|
+
token.innerTokens.push(this.visit(arg.input));
|
|
1111
|
+
token.innerTokens.push(new SqlPrintToken(SqlPrintTokenType.operator, '::'));
|
|
1112
|
+
token.innerTokens.push(this.visit(arg.castType));
|
|
1113
|
+
return token;
|
|
1114
|
+
}
|
|
1115
|
+
// Default to ANSI-compliant CAST(expression AS type) syntax for broader compatibility.
|
|
1116
|
+
token.innerTokens.push(new SqlPrintToken(SqlPrintTokenType.keyword, 'cast'));
|
|
1117
|
+
token.innerTokens.push(SqlPrintTokenParser.PAREN_OPEN_TOKEN);
|
|
1063
1118
|
token.innerTokens.push(this.visit(arg.input));
|
|
1064
|
-
token.innerTokens.push(
|
|
1119
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
1120
|
+
token.innerTokens.push(new SqlPrintToken(SqlPrintTokenType.keyword, 'as'));
|
|
1121
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
1065
1122
|
token.innerTokens.push(this.visit(arg.castType));
|
|
1123
|
+
token.innerTokens.push(SqlPrintTokenParser.PAREN_CLOSE_TOKEN);
|
|
1066
1124
|
return token;
|
|
1067
1125
|
}
|
|
1068
1126
|
visitCaseExpression(arg) {
|
|
@@ -1073,20 +1131,148 @@ export class SqlPrintTokenParser {
|
|
|
1073
1131
|
// Clear positioned comments to prevent duplicate processing
|
|
1074
1132
|
arg.positionedComments = null;
|
|
1075
1133
|
}
|
|
1134
|
+
const promotedComments = [];
|
|
1135
|
+
const trailingSwitchComments = this.extractSwitchAfterComments(arg.switchCase);
|
|
1136
|
+
let conditionToken = null;
|
|
1137
|
+
if (arg.condition) {
|
|
1138
|
+
conditionToken = this.visit(arg.condition);
|
|
1139
|
+
promotedComments.push(...this.collectCaseLeadingCommentBlocks(conditionToken));
|
|
1140
|
+
}
|
|
1141
|
+
const switchToken = this.visit(arg.switchCase);
|
|
1142
|
+
promotedComments.push(...this.collectCaseLeadingCommentsFromSwitch(switchToken));
|
|
1143
|
+
if (promotedComments.length > 0) {
|
|
1144
|
+
token.innerTokens.push(...promotedComments);
|
|
1145
|
+
}
|
|
1076
1146
|
// Add the CASE keyword
|
|
1077
1147
|
token.innerTokens.push(new SqlPrintToken(SqlPrintTokenType.keyword, 'case'));
|
|
1078
1148
|
// Add the condition if exists
|
|
1079
|
-
if (
|
|
1149
|
+
if (conditionToken) {
|
|
1080
1150
|
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
1081
|
-
token.innerTokens.push(
|
|
1151
|
+
token.innerTokens.push(conditionToken);
|
|
1082
1152
|
}
|
|
1083
1153
|
// Add the WHEN/THEN pairs and ELSE
|
|
1084
|
-
token.innerTokens.push(
|
|
1154
|
+
token.innerTokens.push(switchToken);
|
|
1085
1155
|
// Add the END keyword
|
|
1086
1156
|
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
1087
1157
|
token.innerTokens.push(new SqlPrintToken(SqlPrintTokenType.keyword, 'end'));
|
|
1158
|
+
if (trailingSwitchComments.length > 0) {
|
|
1159
|
+
token.innerTokens.push(new SqlPrintToken(SqlPrintTokenType.commentNewline, ''));
|
|
1160
|
+
const trailingBlocks = this.createCommentBlocks(trailingSwitchComments);
|
|
1161
|
+
token.innerTokens.push(...trailingBlocks);
|
|
1162
|
+
}
|
|
1088
1163
|
return token;
|
|
1089
1164
|
}
|
|
1165
|
+
extractSwitchAfterComments(arg) {
|
|
1166
|
+
if (!arg.positionedComments || arg.positionedComments.length === 0) {
|
|
1167
|
+
return [];
|
|
1168
|
+
}
|
|
1169
|
+
const trailing = [];
|
|
1170
|
+
const retained = [];
|
|
1171
|
+
for (const entry of arg.positionedComments) {
|
|
1172
|
+
if (entry.position === 'after') {
|
|
1173
|
+
trailing.push(...entry.comments);
|
|
1174
|
+
}
|
|
1175
|
+
else {
|
|
1176
|
+
retained.push(entry);
|
|
1177
|
+
}
|
|
1178
|
+
}
|
|
1179
|
+
arg.positionedComments = retained.length > 0 ? retained : null;
|
|
1180
|
+
return trailing;
|
|
1181
|
+
}
|
|
1182
|
+
collectCaseLeadingCommentsFromSwitch(token) {
|
|
1183
|
+
if (!token.innerTokens || token.innerTokens.length === 0) {
|
|
1184
|
+
return [];
|
|
1185
|
+
}
|
|
1186
|
+
const pairToken = token.innerTokens.find(child => child.containerType === SqlPrintTokenContainerType.CaseKeyValuePair);
|
|
1187
|
+
if (!pairToken) {
|
|
1188
|
+
return [];
|
|
1189
|
+
}
|
|
1190
|
+
const keyToken = this.findCaseKeyToken(pairToken);
|
|
1191
|
+
if (!keyToken) {
|
|
1192
|
+
return [];
|
|
1193
|
+
}
|
|
1194
|
+
return this.collectCaseLeadingCommentBlocks(keyToken);
|
|
1195
|
+
}
|
|
1196
|
+
findCaseKeyToken(pairToken) {
|
|
1197
|
+
for (const child of pairToken.innerTokens) {
|
|
1198
|
+
if (child.containerType === SqlPrintTokenContainerType.CommentBlock) {
|
|
1199
|
+
continue;
|
|
1200
|
+
}
|
|
1201
|
+
if (child.type === SqlPrintTokenType.space) {
|
|
1202
|
+
continue;
|
|
1203
|
+
}
|
|
1204
|
+
if (child.type === SqlPrintTokenType.keyword) {
|
|
1205
|
+
continue;
|
|
1206
|
+
}
|
|
1207
|
+
if (child.containerType === SqlPrintTokenContainerType.CaseThenValue) {
|
|
1208
|
+
continue;
|
|
1209
|
+
}
|
|
1210
|
+
return child;
|
|
1211
|
+
}
|
|
1212
|
+
return undefined;
|
|
1213
|
+
}
|
|
1214
|
+
collectCaseLeadingCommentBlocks(token) {
|
|
1215
|
+
if (!token.innerTokens || token.innerTokens.length === 0) {
|
|
1216
|
+
return [];
|
|
1217
|
+
}
|
|
1218
|
+
const collected = [];
|
|
1219
|
+
this.collectCaseLeadingCommentBlocksRecursive(token, collected, new Set(), 0);
|
|
1220
|
+
return collected;
|
|
1221
|
+
}
|
|
1222
|
+
collectCaseLeadingCommentBlocksRecursive(token, collected, seen, depth) {
|
|
1223
|
+
if (!token.innerTokens || token.innerTokens.length === 0) {
|
|
1224
|
+
return;
|
|
1225
|
+
}
|
|
1226
|
+
let removedAny = false;
|
|
1227
|
+
while (token.innerTokens.length > 0) {
|
|
1228
|
+
const first = token.innerTokens[0];
|
|
1229
|
+
if (first.containerType === SqlPrintTokenContainerType.CommentBlock) {
|
|
1230
|
+
token.innerTokens.shift();
|
|
1231
|
+
const signature = this.commentBlockSignature(first);
|
|
1232
|
+
if (!(depth > 0 && seen.has(signature))) {
|
|
1233
|
+
collected.push(first);
|
|
1234
|
+
seen.add(signature);
|
|
1235
|
+
}
|
|
1236
|
+
removedAny = true;
|
|
1237
|
+
continue;
|
|
1238
|
+
}
|
|
1239
|
+
if (!removedAny && first.type === SqlPrintTokenType.space) {
|
|
1240
|
+
return;
|
|
1241
|
+
}
|
|
1242
|
+
break;
|
|
1243
|
+
}
|
|
1244
|
+
if (!token.innerTokens || token.innerTokens.length === 0) {
|
|
1245
|
+
return;
|
|
1246
|
+
}
|
|
1247
|
+
const firstChild = token.innerTokens[0];
|
|
1248
|
+
if (this.isTransparentCaseWrapper(firstChild)) {
|
|
1249
|
+
this.collectCaseLeadingCommentBlocksRecursive(firstChild, collected, seen, depth + 1);
|
|
1250
|
+
}
|
|
1251
|
+
}
|
|
1252
|
+
isTransparentCaseWrapper(token) {
|
|
1253
|
+
if (!token) {
|
|
1254
|
+
return false;
|
|
1255
|
+
}
|
|
1256
|
+
const transparentContainers = [
|
|
1257
|
+
SqlPrintTokenContainerType.ColumnReference,
|
|
1258
|
+
SqlPrintTokenContainerType.QualifiedName,
|
|
1259
|
+
SqlPrintTokenContainerType.IdentifierString,
|
|
1260
|
+
SqlPrintTokenContainerType.RawString,
|
|
1261
|
+
SqlPrintTokenContainerType.LiteralValue,
|
|
1262
|
+
SqlPrintTokenContainerType.ParenExpression,
|
|
1263
|
+
SqlPrintTokenContainerType.UnaryExpression,
|
|
1264
|
+
];
|
|
1265
|
+
return transparentContainers.includes(token.containerType);
|
|
1266
|
+
}
|
|
1267
|
+
commentBlockSignature(commentBlock) {
|
|
1268
|
+
if (!commentBlock.innerTokens || commentBlock.innerTokens.length === 0) {
|
|
1269
|
+
return '';
|
|
1270
|
+
}
|
|
1271
|
+
return commentBlock.innerTokens
|
|
1272
|
+
.filter(inner => inner.text !== '')
|
|
1273
|
+
.map(inner => inner.text)
|
|
1274
|
+
.join('|');
|
|
1275
|
+
}
|
|
1090
1276
|
visitArrayExpression(arg) {
|
|
1091
1277
|
const token = new SqlPrintToken(SqlPrintTokenType.container, '', SqlPrintTokenContainerType.ArrayExpression);
|
|
1092
1278
|
token.innerTokens.push(new SqlPrintToken(SqlPrintTokenType.keyword, 'array'));
|
|
@@ -1172,6 +1358,7 @@ export class SqlPrintTokenParser {
|
|
|
1172
1358
|
}
|
|
1173
1359
|
visitTupleExpression(arg) {
|
|
1174
1360
|
const token = new SqlPrintToken(SqlPrintTokenType.container, '', SqlPrintTokenContainerType.TupleExpression);
|
|
1361
|
+
const requiresMultiline = this.tupleRequiresMultiline(arg);
|
|
1175
1362
|
token.innerTokens.push(SqlPrintTokenParser.PAREN_OPEN_TOKEN);
|
|
1176
1363
|
for (let i = 0; i < arg.values.length; i++) {
|
|
1177
1364
|
if (i > 0) {
|
|
@@ -1179,10 +1366,38 @@ export class SqlPrintTokenParser {
|
|
|
1179
1366
|
}
|
|
1180
1367
|
token.innerTokens.push(this.visit(arg.values[i]));
|
|
1181
1368
|
}
|
|
1369
|
+
if (requiresMultiline) {
|
|
1370
|
+
token.innerTokens.push(new SqlPrintToken(SqlPrintTokenType.commentNewline, '', SqlPrintTokenContainerType.TupleExpression));
|
|
1371
|
+
}
|
|
1182
1372
|
token.innerTokens.push(SqlPrintTokenParser.PAREN_CLOSE_TOKEN);
|
|
1183
|
-
this.addComponentComments(token, arg);
|
|
1184
1373
|
return token;
|
|
1185
1374
|
}
|
|
1375
|
+
tupleRequiresMultiline(tuple) {
|
|
1376
|
+
for (const value of tuple.values) {
|
|
1377
|
+
if (this.hasInlineComments(value)) {
|
|
1378
|
+
return true;
|
|
1379
|
+
}
|
|
1380
|
+
}
|
|
1381
|
+
return false;
|
|
1382
|
+
}
|
|
1383
|
+
hasInlineComments(component) {
|
|
1384
|
+
if (this.hasLeadingComments(component)) {
|
|
1385
|
+
return true;
|
|
1386
|
+
}
|
|
1387
|
+
if (component instanceof TupleExpression) {
|
|
1388
|
+
return this.tupleRequiresMultiline(component);
|
|
1389
|
+
}
|
|
1390
|
+
return false;
|
|
1391
|
+
}
|
|
1392
|
+
hasLeadingComments(component) {
|
|
1393
|
+
var _a;
|
|
1394
|
+
const positioned = (_a = component.positionedComments) !== null && _a !== void 0 ? _a : [];
|
|
1395
|
+
const before = positioned.find(pc => pc.position === 'before');
|
|
1396
|
+
if (before && before.comments.some(comment => comment.trim().length > 0)) {
|
|
1397
|
+
return true;
|
|
1398
|
+
}
|
|
1399
|
+
return false;
|
|
1400
|
+
}
|
|
1186
1401
|
visitWindowFrameExpression(arg) {
|
|
1187
1402
|
// Compose window frame expression: over(partition by ... order by ... rows ...)
|
|
1188
1403
|
const token = new SqlPrintToken(SqlPrintTokenType.container, '', SqlPrintTokenContainerType.WindowFrameExpression);
|
|
@@ -1264,7 +1479,7 @@ export class SqlPrintTokenParser {
|
|
|
1264
1479
|
// Add positioned comments in recorded order
|
|
1265
1480
|
const beforeComments = arg.getPositionedComments('before');
|
|
1266
1481
|
const afterComments = arg.getPositionedComments('after');
|
|
1267
|
-
const isParenExpression = arg.value
|
|
1482
|
+
const isParenExpression = arg.value instanceof ParenExpression;
|
|
1268
1483
|
if (beforeComments.length > 0) {
|
|
1269
1484
|
const commentTokens = this.createInlineCommentSequence(beforeComments);
|
|
1270
1485
|
token.innerTokens.push(...commentTokens);
|
|
@@ -1463,16 +1678,32 @@ export class SqlPrintTokenParser {
|
|
|
1463
1678
|
}
|
|
1464
1679
|
}
|
|
1465
1680
|
visitFromClause(arg) {
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1681
|
+
// Build a declaration order map so JOIN ON operands can be normalized later.
|
|
1682
|
+
let contextPushed = false;
|
|
1683
|
+
if (this.normalizeJoinConditionOrder) {
|
|
1684
|
+
const aliasOrder = this.buildJoinAliasOrder(arg);
|
|
1685
|
+
if (aliasOrder.size > 0) {
|
|
1686
|
+
this.joinConditionContexts.push({ aliasOrder });
|
|
1687
|
+
contextPushed = true;
|
|
1688
|
+
}
|
|
1689
|
+
}
|
|
1690
|
+
try {
|
|
1691
|
+
const token = new SqlPrintToken(SqlPrintTokenType.keyword, 'from', SqlPrintTokenContainerType.FromClause);
|
|
1692
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
1693
|
+
token.innerTokens.push(this.visit(arg.source));
|
|
1694
|
+
if (arg.joins) {
|
|
1695
|
+
for (let i = 0; i < arg.joins.length; i++) {
|
|
1696
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
1697
|
+
token.innerTokens.push(this.visit(arg.joins[i]));
|
|
1698
|
+
}
|
|
1699
|
+
}
|
|
1700
|
+
return token;
|
|
1701
|
+
}
|
|
1702
|
+
finally {
|
|
1703
|
+
if (contextPushed) {
|
|
1704
|
+
this.joinConditionContexts.pop();
|
|
1473
1705
|
}
|
|
1474
1706
|
}
|
|
1475
|
-
return token;
|
|
1476
1707
|
}
|
|
1477
1708
|
visitJoinClause(arg) {
|
|
1478
1709
|
// Print join clause: [joinType] [lateral] [source] [on/using ...]
|
|
@@ -1522,12 +1753,123 @@ export class SqlPrintTokenParser {
|
|
|
1522
1753
|
return token;
|
|
1523
1754
|
}
|
|
1524
1755
|
visitJoinOnClause(arg) {
|
|
1756
|
+
// Normalize JOIN ON predicate columns to follow declaration order when enabled.
|
|
1757
|
+
if (this.normalizeJoinConditionOrder) {
|
|
1758
|
+
const aliasOrder = this.getCurrentJoinAliasOrder();
|
|
1759
|
+
if (aliasOrder) {
|
|
1760
|
+
this.normalizeJoinConditionValue(arg.condition, aliasOrder);
|
|
1761
|
+
}
|
|
1762
|
+
}
|
|
1525
1763
|
const token = new SqlPrintToken(SqlPrintTokenType.container, '', SqlPrintTokenContainerType.JoinOnClause);
|
|
1526
1764
|
token.innerTokens.push(new SqlPrintToken(SqlPrintTokenType.keyword, 'on'));
|
|
1527
1765
|
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
1528
1766
|
token.innerTokens.push(this.visit(arg.condition));
|
|
1529
1767
|
return token;
|
|
1530
1768
|
}
|
|
1769
|
+
getCurrentJoinAliasOrder() {
|
|
1770
|
+
if (this.joinConditionContexts.length === 0) {
|
|
1771
|
+
return null;
|
|
1772
|
+
}
|
|
1773
|
+
return this.joinConditionContexts[this.joinConditionContexts.length - 1].aliasOrder;
|
|
1774
|
+
}
|
|
1775
|
+
buildJoinAliasOrder(fromClause) {
|
|
1776
|
+
const aliasOrder = new Map();
|
|
1777
|
+
let nextIndex = 0;
|
|
1778
|
+
const registerSource = (source) => {
|
|
1779
|
+
const identifiers = this.collectSourceIdentifiers(source);
|
|
1780
|
+
if (identifiers.length === 0) {
|
|
1781
|
+
return;
|
|
1782
|
+
}
|
|
1783
|
+
// Track the earliest declaration index for each identifier found in the FROM clause.
|
|
1784
|
+
for (const identifier of identifiers) {
|
|
1785
|
+
const key = identifier.toLowerCase();
|
|
1786
|
+
if (!aliasOrder.has(key)) {
|
|
1787
|
+
aliasOrder.set(key, nextIndex);
|
|
1788
|
+
}
|
|
1789
|
+
}
|
|
1790
|
+
nextIndex++;
|
|
1791
|
+
};
|
|
1792
|
+
registerSource(fromClause.source);
|
|
1793
|
+
if (fromClause.joins) {
|
|
1794
|
+
for (const joinClause of fromClause.joins) {
|
|
1795
|
+
registerSource(joinClause.source);
|
|
1796
|
+
}
|
|
1797
|
+
}
|
|
1798
|
+
return aliasOrder;
|
|
1799
|
+
}
|
|
1800
|
+
collectSourceIdentifiers(source) {
|
|
1801
|
+
const identifiers = [];
|
|
1802
|
+
const aliasName = source.getAliasName();
|
|
1803
|
+
if (aliasName) {
|
|
1804
|
+
identifiers.push(aliasName);
|
|
1805
|
+
}
|
|
1806
|
+
// Capture table identifiers so unaliased tables can still be matched.
|
|
1807
|
+
if (source.datasource instanceof TableSource) {
|
|
1808
|
+
const tableComponent = source.datasource.table.name;
|
|
1809
|
+
identifiers.push(tableComponent);
|
|
1810
|
+
const fullName = source.datasource.getSourceName();
|
|
1811
|
+
if (fullName && fullName !== tableComponent) {
|
|
1812
|
+
identifiers.push(fullName);
|
|
1813
|
+
}
|
|
1814
|
+
}
|
|
1815
|
+
return identifiers;
|
|
1816
|
+
}
|
|
1817
|
+
normalizeJoinConditionValue(condition, aliasOrder) {
|
|
1818
|
+
// Walk the value tree so every comparison within the JOIN predicate is inspected.
|
|
1819
|
+
const kind = condition.getKind();
|
|
1820
|
+
if (kind === ParenExpression.kind) {
|
|
1821
|
+
const paren = condition;
|
|
1822
|
+
this.normalizeJoinConditionValue(paren.expression, aliasOrder);
|
|
1823
|
+
return;
|
|
1824
|
+
}
|
|
1825
|
+
if (kind === BinaryExpression.kind) {
|
|
1826
|
+
const binary = condition;
|
|
1827
|
+
this.normalizeJoinConditionValue(binary.left, aliasOrder);
|
|
1828
|
+
this.normalizeJoinConditionValue(binary.right, aliasOrder);
|
|
1829
|
+
this.normalizeBinaryEquality(binary, aliasOrder);
|
|
1830
|
+
}
|
|
1831
|
+
}
|
|
1832
|
+
normalizeBinaryEquality(binary, aliasOrder) {
|
|
1833
|
+
// Only normalize simple equality comparisons, leaving other operators untouched.
|
|
1834
|
+
const operatorValue = binary.operator.value.toLowerCase();
|
|
1835
|
+
if (operatorValue !== '=') {
|
|
1836
|
+
return;
|
|
1837
|
+
}
|
|
1838
|
+
const leftOwner = this.resolveColumnOwner(binary.left);
|
|
1839
|
+
const rightOwner = this.resolveColumnOwner(binary.right);
|
|
1840
|
+
if (!leftOwner || !rightOwner || leftOwner === rightOwner) {
|
|
1841
|
+
return;
|
|
1842
|
+
}
|
|
1843
|
+
const leftOrder = aliasOrder.get(leftOwner);
|
|
1844
|
+
const rightOrder = aliasOrder.get(rightOwner);
|
|
1845
|
+
if (leftOrder === undefined || rightOrder === undefined) {
|
|
1846
|
+
return;
|
|
1847
|
+
}
|
|
1848
|
+
if (leftOrder > rightOrder) {
|
|
1849
|
+
// Swap operands so the earlier declared table appears on the left.
|
|
1850
|
+
const originalLeft = binary.left;
|
|
1851
|
+
binary.left = binary.right;
|
|
1852
|
+
binary.right = originalLeft;
|
|
1853
|
+
}
|
|
1854
|
+
}
|
|
1855
|
+
resolveColumnOwner(value) {
|
|
1856
|
+
var _a;
|
|
1857
|
+
const kind = value.getKind();
|
|
1858
|
+
if (kind === ColumnReference.kind) {
|
|
1859
|
+
// Column references expose their qualifier namespace, which we normalize for lookups.
|
|
1860
|
+
const columnRef = value;
|
|
1861
|
+
const namespace = columnRef.getNamespace();
|
|
1862
|
+
if (!namespace) {
|
|
1863
|
+
return null;
|
|
1864
|
+
}
|
|
1865
|
+
const qualifier = namespace.includes('.') ? (_a = namespace.split('.').pop()) !== null && _a !== void 0 ? _a : '' : namespace;
|
|
1866
|
+
return qualifier.toLowerCase();
|
|
1867
|
+
}
|
|
1868
|
+
if (kind === ParenExpression.kind) {
|
|
1869
|
+
return this.resolveColumnOwner(value.expression);
|
|
1870
|
+
}
|
|
1871
|
+
return null;
|
|
1872
|
+
}
|
|
1531
1873
|
visitJoinUsingClause(arg) {
|
|
1532
1874
|
const token = new SqlPrintToken(SqlPrintTokenType.container, '', SqlPrintTokenContainerType.JoinUsingClause);
|
|
1533
1875
|
token.innerTokens.push(new SqlPrintToken(SqlPrintTokenType.keyword, 'using'));
|
|
@@ -1711,7 +2053,7 @@ export class SqlPrintTokenParser {
|
|
|
1711
2053
|
token.innerTokens.push(mergedHeaderComment);
|
|
1712
2054
|
}
|
|
1713
2055
|
else {
|
|
1714
|
-
const headerCommentBlocks = this.createCommentBlocks(arg.headerComments);
|
|
2056
|
+
const headerCommentBlocks = this.createCommentBlocks(arg.headerComments, true);
|
|
1715
2057
|
token.innerTokens.push(...headerCommentBlocks);
|
|
1716
2058
|
}
|
|
1717
2059
|
if (arg.withClause) {
|
|
@@ -1798,7 +2140,7 @@ export class SqlPrintTokenParser {
|
|
|
1798
2140
|
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
1799
2141
|
}
|
|
1800
2142
|
else {
|
|
1801
|
-
const headerCommentBlocks = this.createCommentBlocks(arg.headerComments);
|
|
2143
|
+
const headerCommentBlocks = this.createCommentBlocks(arg.headerComments, true);
|
|
1802
2144
|
for (const commentBlock of headerCommentBlocks) {
|
|
1803
2145
|
token.innerTokens.push(commentBlock);
|
|
1804
2146
|
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
@@ -1839,22 +2181,158 @@ export class SqlPrintTokenParser {
|
|
|
1839
2181
|
}
|
|
1840
2182
|
visitInsertQuery(arg) {
|
|
1841
2183
|
const token = new SqlPrintToken(SqlPrintTokenType.container, '', SqlPrintTokenContainerType.InsertQuery);
|
|
1842
|
-
|
|
2184
|
+
if (arg.withClause) {
|
|
2185
|
+
token.innerTokens.push(arg.withClause.accept(this));
|
|
2186
|
+
}
|
|
1843
2187
|
token.innerTokens.push(this.visit(arg.insertClause));
|
|
1844
2188
|
// Process the select query if present
|
|
1845
2189
|
if (arg.selectQuery) {
|
|
1846
2190
|
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
1847
2191
|
token.innerTokens.push(this.visit(arg.selectQuery));
|
|
1848
2192
|
}
|
|
2193
|
+
if (arg.returningClause) {
|
|
2194
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2195
|
+
token.innerTokens.push(arg.returningClause.accept(this));
|
|
2196
|
+
}
|
|
1849
2197
|
return token;
|
|
1850
2198
|
}
|
|
1851
2199
|
visitInsertClause(arg) {
|
|
1852
|
-
const token = new SqlPrintToken(SqlPrintTokenType.container, '');
|
|
1853
|
-
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2200
|
+
const token = new SqlPrintToken(SqlPrintTokenType.container, '', SqlPrintTokenContainerType.InsertClause);
|
|
1854
2201
|
token.innerTokens.push(new SqlPrintToken(SqlPrintTokenType.keyword, 'insert into'));
|
|
1855
2202
|
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
1856
2203
|
token.innerTokens.push(arg.source.accept(this));
|
|
1857
|
-
if (arg.columns.length > 0) {
|
|
2204
|
+
if (arg.columns && arg.columns.length > 0) {
|
|
2205
|
+
token.innerTokens.push(SqlPrintTokenParser.PAREN_OPEN_TOKEN);
|
|
2206
|
+
for (let i = 0; i < arg.columns.length; i++) {
|
|
2207
|
+
if (i > 0) {
|
|
2208
|
+
token.innerTokens.push(...SqlPrintTokenParser.commaSpaceTokens());
|
|
2209
|
+
}
|
|
2210
|
+
token.innerTokens.push(arg.columns[i].accept(this));
|
|
2211
|
+
}
|
|
2212
|
+
token.innerTokens.push(SqlPrintTokenParser.PAREN_CLOSE_TOKEN);
|
|
2213
|
+
}
|
|
2214
|
+
return token;
|
|
2215
|
+
}
|
|
2216
|
+
visitDeleteQuery(arg) {
|
|
2217
|
+
const token = new SqlPrintToken(SqlPrintTokenType.container, '', SqlPrintTokenContainerType.DeleteQuery);
|
|
2218
|
+
// Attach WITH clause tokens when present before the DELETE command.
|
|
2219
|
+
if (arg.withClause) {
|
|
2220
|
+
token.innerTokens.push(arg.withClause.accept(this));
|
|
2221
|
+
}
|
|
2222
|
+
token.innerTokens.push(arg.deleteClause.accept(this));
|
|
2223
|
+
// Append USING clause when the DELETE references additional sources.
|
|
2224
|
+
if (arg.usingClause) {
|
|
2225
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2226
|
+
token.innerTokens.push(arg.usingClause.accept(this));
|
|
2227
|
+
}
|
|
2228
|
+
// Append WHERE clause to restrict affected rows.
|
|
2229
|
+
if (arg.whereClause) {
|
|
2230
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2231
|
+
token.innerTokens.push(arg.whereClause.accept(this));
|
|
2232
|
+
}
|
|
2233
|
+
// Append RETURNING clause when the DELETE yields output columns.
|
|
2234
|
+
if (arg.returningClause) {
|
|
2235
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2236
|
+
token.innerTokens.push(arg.returningClause.accept(this));
|
|
2237
|
+
}
|
|
2238
|
+
return token;
|
|
2239
|
+
}
|
|
2240
|
+
visitDeleteClause(arg) {
|
|
2241
|
+
const token = new SqlPrintToken(SqlPrintTokenType.keyword, 'delete from', SqlPrintTokenContainerType.DeleteClause);
|
|
2242
|
+
// Render the target relation immediately after the DELETE FROM keyword.
|
|
2243
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2244
|
+
token.innerTokens.push(arg.source.accept(this));
|
|
2245
|
+
return token;
|
|
2246
|
+
}
|
|
2247
|
+
visitUsingClause(arg) {
|
|
2248
|
+
const token = new SqlPrintToken(SqlPrintTokenType.keyword, 'using', SqlPrintTokenContainerType.UsingClause);
|
|
2249
|
+
if (arg.sources.length > 0) {
|
|
2250
|
+
// Attach the first USING source directly after the keyword.
|
|
2251
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2252
|
+
for (let i = 0; i < arg.sources.length; i++) {
|
|
2253
|
+
if (i > 0) {
|
|
2254
|
+
// Separate subsequent sources with comma and space for clarity.
|
|
2255
|
+
token.innerTokens.push(...SqlPrintTokenParser.commaSpaceTokens());
|
|
2256
|
+
}
|
|
2257
|
+
token.innerTokens.push(this.visit(arg.sources[i]));
|
|
2258
|
+
}
|
|
2259
|
+
}
|
|
2260
|
+
return token;
|
|
2261
|
+
}
|
|
2262
|
+
visitMergeQuery(arg) {
|
|
2263
|
+
const token = new SqlPrintToken(SqlPrintTokenType.container, '', SqlPrintTokenContainerType.MergeQuery);
|
|
2264
|
+
if (arg.withClause) {
|
|
2265
|
+
token.innerTokens.push(arg.withClause.accept(this));
|
|
2266
|
+
}
|
|
2267
|
+
token.innerTokens.push(new SqlPrintToken(SqlPrintTokenType.keyword, 'merge into'));
|
|
2268
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2269
|
+
token.innerTokens.push(arg.target.accept(this));
|
|
2270
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2271
|
+
token.innerTokens.push(new SqlPrintToken(SqlPrintTokenType.keyword, 'using'));
|
|
2272
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2273
|
+
token.innerTokens.push(arg.source.accept(this));
|
|
2274
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2275
|
+
const onClauseToken = new SqlPrintToken(SqlPrintTokenType.container, '', SqlPrintTokenContainerType.JoinOnClause);
|
|
2276
|
+
onClauseToken.innerTokens.push(new SqlPrintToken(SqlPrintTokenType.keyword, 'on'));
|
|
2277
|
+
onClauseToken.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2278
|
+
onClauseToken.innerTokens.push(arg.onCondition.accept(this));
|
|
2279
|
+
token.innerTokens.push(onClauseToken);
|
|
2280
|
+
for (const clause of arg.whenClauses) {
|
|
2281
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2282
|
+
token.innerTokens.push(clause.accept(this));
|
|
2283
|
+
}
|
|
2284
|
+
return token;
|
|
2285
|
+
}
|
|
2286
|
+
visitMergeWhenClause(arg) {
|
|
2287
|
+
const token = new SqlPrintToken(SqlPrintTokenType.container, '', SqlPrintTokenContainerType.MergeWhenClause);
|
|
2288
|
+
token.innerTokens.push(new SqlPrintToken(SqlPrintTokenType.keyword, this.mergeMatchTypeToKeyword(arg.matchType)));
|
|
2289
|
+
if (arg.condition) {
|
|
2290
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2291
|
+
token.innerTokens.push(new SqlPrintToken(SqlPrintTokenType.keyword, 'and'));
|
|
2292
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2293
|
+
token.innerTokens.push(arg.condition.accept(this));
|
|
2294
|
+
}
|
|
2295
|
+
const thenLeadingComments = arg.getThenLeadingComments();
|
|
2296
|
+
const thenKeywordToken = new SqlPrintToken(SqlPrintTokenType.keyword, 'then');
|
|
2297
|
+
if (thenLeadingComments.length > 0) {
|
|
2298
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2299
|
+
const commentBlocks = this.createCommentBlocks(thenLeadingComments);
|
|
2300
|
+
token.innerTokens.push(...commentBlocks);
|
|
2301
|
+
token.innerTokens.push(thenKeywordToken);
|
|
2302
|
+
}
|
|
2303
|
+
else {
|
|
2304
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2305
|
+
token.innerTokens.push(thenKeywordToken);
|
|
2306
|
+
}
|
|
2307
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2308
|
+
token.innerTokens.push(arg.action.accept(this));
|
|
2309
|
+
return token;
|
|
2310
|
+
}
|
|
2311
|
+
visitMergeUpdateAction(arg) {
|
|
2312
|
+
const token = new SqlPrintToken(SqlPrintTokenType.container, '', SqlPrintTokenContainerType.MergeUpdateAction);
|
|
2313
|
+
token.innerTokens.push(new SqlPrintToken(SqlPrintTokenType.keyword, 'update'));
|
|
2314
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2315
|
+
token.innerTokens.push(arg.setClause.accept(this));
|
|
2316
|
+
if (arg.whereClause) {
|
|
2317
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2318
|
+
token.innerTokens.push(arg.whereClause.accept(this));
|
|
2319
|
+
}
|
|
2320
|
+
return token;
|
|
2321
|
+
}
|
|
2322
|
+
visitMergeDeleteAction(arg) {
|
|
2323
|
+
const token = new SqlPrintToken(SqlPrintTokenType.container, '', SqlPrintTokenContainerType.MergeDeleteAction);
|
|
2324
|
+
token.innerTokens.push(new SqlPrintToken(SqlPrintTokenType.keyword, 'delete'));
|
|
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
|
+
visitMergeInsertAction(arg) {
|
|
2332
|
+
const token = new SqlPrintToken(SqlPrintTokenType.container, '', SqlPrintTokenContainerType.MergeInsertAction);
|
|
2333
|
+
token.innerTokens.push(new SqlPrintToken(SqlPrintTokenType.keyword, 'insert'));
|
|
2334
|
+
if (arg.columns && arg.columns.length > 0) {
|
|
2335
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
1858
2336
|
token.innerTokens.push(SqlPrintTokenParser.PAREN_OPEN_TOKEN);
|
|
1859
2337
|
for (let i = 0; i < arg.columns.length; i++) {
|
|
1860
2338
|
if (i > 0) {
|
|
@@ -1864,8 +2342,47 @@ export class SqlPrintTokenParser {
|
|
|
1864
2342
|
}
|
|
1865
2343
|
token.innerTokens.push(SqlPrintTokenParser.PAREN_CLOSE_TOKEN);
|
|
1866
2344
|
}
|
|
2345
|
+
if (arg.defaultValues) {
|
|
2346
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2347
|
+
token.innerTokens.push(new SqlPrintToken(SqlPrintTokenType.keyword, 'default values'));
|
|
2348
|
+
return token;
|
|
2349
|
+
}
|
|
2350
|
+
if (arg.values) {
|
|
2351
|
+
const leadingValuesComments = arg.getValuesLeadingComments();
|
|
2352
|
+
if (leadingValuesComments.length > 0) {
|
|
2353
|
+
token.innerTokens.push(new SqlPrintToken(SqlPrintTokenType.commentNewline, ''));
|
|
2354
|
+
const commentBlocks = this.createCommentBlocks(leadingValuesComments);
|
|
2355
|
+
token.innerTokens.push(...commentBlocks);
|
|
2356
|
+
}
|
|
2357
|
+
else {
|
|
2358
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2359
|
+
}
|
|
2360
|
+
const valuesKeywordToken = new SqlPrintToken(SqlPrintTokenType.keyword, 'values');
|
|
2361
|
+
token.innerTokens.push(valuesKeywordToken);
|
|
2362
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2363
|
+
token.innerTokens.push(SqlPrintTokenParser.PAREN_OPEN_TOKEN);
|
|
2364
|
+
token.innerTokens.push(arg.values.accept(this));
|
|
2365
|
+
token.innerTokens.push(SqlPrintTokenParser.PAREN_CLOSE_TOKEN);
|
|
2366
|
+
}
|
|
1867
2367
|
return token;
|
|
1868
2368
|
}
|
|
2369
|
+
visitMergeDoNothingAction(_) {
|
|
2370
|
+
return new SqlPrintToken(SqlPrintTokenType.keyword, 'do nothing', SqlPrintTokenContainerType.MergeDoNothingAction);
|
|
2371
|
+
}
|
|
2372
|
+
mergeMatchTypeToKeyword(matchType) {
|
|
2373
|
+
switch (matchType) {
|
|
2374
|
+
case 'matched':
|
|
2375
|
+
return 'when matched';
|
|
2376
|
+
case 'not_matched':
|
|
2377
|
+
return 'when not matched';
|
|
2378
|
+
case 'not_matched_by_source':
|
|
2379
|
+
return 'when not matched by source';
|
|
2380
|
+
case 'not_matched_by_target':
|
|
2381
|
+
return 'when not matched by target';
|
|
2382
|
+
default:
|
|
2383
|
+
return 'when';
|
|
2384
|
+
}
|
|
2385
|
+
}
|
|
1869
2386
|
visitUpdateQuery(arg) {
|
|
1870
2387
|
const token = new SqlPrintToken(SqlPrintTokenType.container, '', SqlPrintTokenContainerType.UpdateQuery);
|
|
1871
2388
|
if (arg.withClause) {
|
|
@@ -1895,7 +2412,7 @@ export class SqlPrintTokenParser {
|
|
|
1895
2412
|
return token;
|
|
1896
2413
|
}
|
|
1897
2414
|
visitSetClause(arg) {
|
|
1898
|
-
const token = new SqlPrintToken(SqlPrintTokenType.keyword, 'set', SqlPrintTokenContainerType.
|
|
2415
|
+
const token = new SqlPrintToken(SqlPrintTokenType.keyword, 'set', SqlPrintTokenContainerType.SetClause);
|
|
1899
2416
|
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
1900
2417
|
for (let i = 0; i < arg.items.length; i++) {
|
|
1901
2418
|
if (i > 0) {
|
|
@@ -1926,15 +2443,481 @@ export class SqlPrintTokenParser {
|
|
|
1926
2443
|
return token;
|
|
1927
2444
|
}
|
|
1928
2445
|
visitCreateTableQuery(arg) {
|
|
1929
|
-
|
|
2446
|
+
var _a;
|
|
2447
|
+
const baseKeyword = arg.isTemporary ? 'create temporary table' : 'create table';
|
|
2448
|
+
let keywordText = arg.ifNotExists ? `${baseKeyword} if not exists` : baseKeyword;
|
|
2449
|
+
const token = new SqlPrintToken(SqlPrintTokenType.keyword, keywordText, SqlPrintTokenContainerType.CreateTableQuery);
|
|
1930
2450
|
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
1931
|
-
|
|
2451
|
+
const qualifiedName = new QualifiedName((_a = arg.namespaces) !== null && _a !== void 0 ? _a : null, arg.tableName);
|
|
2452
|
+
token.innerTokens.push(qualifiedName.accept(this));
|
|
2453
|
+
const definitionEntries = [...arg.columns, ...arg.tableConstraints];
|
|
2454
|
+
if (definitionEntries.length > 0) {
|
|
2455
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2456
|
+
token.innerTokens.push(SqlPrintTokenParser.PAREN_OPEN_TOKEN);
|
|
2457
|
+
const definitionToken = new SqlPrintToken(SqlPrintTokenType.container, '', SqlPrintTokenContainerType.CreateTableDefinition);
|
|
2458
|
+
for (let i = 0; i < definitionEntries.length; i++) {
|
|
2459
|
+
if (i > 0) {
|
|
2460
|
+
definitionToken.innerTokens.push(...SqlPrintTokenParser.commaSpaceTokens());
|
|
2461
|
+
}
|
|
2462
|
+
definitionToken.innerTokens.push(definitionEntries[i].accept(this));
|
|
2463
|
+
}
|
|
2464
|
+
token.innerTokens.push(definitionToken);
|
|
2465
|
+
token.innerTokens.push(SqlPrintTokenParser.PAREN_CLOSE_TOKEN);
|
|
2466
|
+
}
|
|
2467
|
+
if (arg.tableOptions) {
|
|
2468
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2469
|
+
token.innerTokens.push(arg.tableOptions.accept(this));
|
|
2470
|
+
}
|
|
1932
2471
|
if (arg.asSelectQuery) {
|
|
1933
2472
|
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
1934
2473
|
token.innerTokens.push(new SqlPrintToken(SqlPrintTokenType.keyword, 'as'));
|
|
1935
2474
|
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
1936
2475
|
token.innerTokens.push(arg.asSelectQuery.accept(this));
|
|
1937
2476
|
}
|
|
2477
|
+
if (arg.withDataOption) {
|
|
2478
|
+
// Reconstruct WITH [NO] DATA clause to mirror PostgreSQL CREATE TABLE semantics.
|
|
2479
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2480
|
+
token.innerTokens.push(new SqlPrintToken(SqlPrintTokenType.keyword, 'with'));
|
|
2481
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2482
|
+
if (arg.withDataOption === 'with-no-data') {
|
|
2483
|
+
token.innerTokens.push(new SqlPrintToken(SqlPrintTokenType.keyword, 'no'));
|
|
2484
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2485
|
+
}
|
|
2486
|
+
token.innerTokens.push(new SqlPrintToken(SqlPrintTokenType.keyword, 'data'));
|
|
2487
|
+
}
|
|
2488
|
+
return token;
|
|
2489
|
+
}
|
|
2490
|
+
visitTableColumnDefinition(arg) {
|
|
2491
|
+
const token = new SqlPrintToken(SqlPrintTokenType.container, '', SqlPrintTokenContainerType.TableColumnDefinition);
|
|
2492
|
+
token.innerTokens.push(arg.name.accept(this));
|
|
2493
|
+
if (arg.dataType) {
|
|
2494
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2495
|
+
token.innerTokens.push(arg.dataType.accept(this));
|
|
2496
|
+
}
|
|
2497
|
+
for (const constraint of arg.constraints) {
|
|
2498
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2499
|
+
token.innerTokens.push(constraint.accept(this));
|
|
2500
|
+
}
|
|
2501
|
+
return token;
|
|
2502
|
+
}
|
|
2503
|
+
visitColumnConstraintDefinition(arg) {
|
|
2504
|
+
const token = new SqlPrintToken(SqlPrintTokenType.container, '', SqlPrintTokenContainerType.ColumnConstraintDefinition);
|
|
2505
|
+
if (arg.constraintName) {
|
|
2506
|
+
token.innerTokens.push(new SqlPrintToken(SqlPrintTokenType.keyword, 'constraint'));
|
|
2507
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2508
|
+
token.innerTokens.push(arg.constraintName.accept(this));
|
|
2509
|
+
}
|
|
2510
|
+
const appendKeyword = (text) => {
|
|
2511
|
+
if (token.innerTokens.length > 0) {
|
|
2512
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2513
|
+
}
|
|
2514
|
+
token.innerTokens.push(new SqlPrintToken(SqlPrintTokenType.keyword, text));
|
|
2515
|
+
};
|
|
2516
|
+
const appendComponent = (component) => {
|
|
2517
|
+
if (token.innerTokens.length > 0) {
|
|
2518
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2519
|
+
}
|
|
2520
|
+
token.innerTokens.push(component.accept(this));
|
|
2521
|
+
};
|
|
2522
|
+
switch (arg.kind) {
|
|
2523
|
+
case 'not-null':
|
|
2524
|
+
appendKeyword('not null');
|
|
2525
|
+
break;
|
|
2526
|
+
case 'null':
|
|
2527
|
+
appendKeyword('null');
|
|
2528
|
+
break;
|
|
2529
|
+
case 'default':
|
|
2530
|
+
appendKeyword('default');
|
|
2531
|
+
if (arg.defaultValue) {
|
|
2532
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2533
|
+
token.innerTokens.push(arg.defaultValue.accept(this));
|
|
2534
|
+
}
|
|
2535
|
+
break;
|
|
2536
|
+
case 'primary-key':
|
|
2537
|
+
appendKeyword('primary key');
|
|
2538
|
+
break;
|
|
2539
|
+
case 'unique':
|
|
2540
|
+
appendKeyword('unique');
|
|
2541
|
+
break;
|
|
2542
|
+
case 'references':
|
|
2543
|
+
if (arg.reference) {
|
|
2544
|
+
appendComponent(arg.reference);
|
|
2545
|
+
}
|
|
2546
|
+
break;
|
|
2547
|
+
case 'check':
|
|
2548
|
+
if (arg.checkExpression) {
|
|
2549
|
+
appendKeyword('check');
|
|
2550
|
+
token.innerTokens.push(this.wrapWithParenExpression(arg.checkExpression));
|
|
2551
|
+
}
|
|
2552
|
+
break;
|
|
2553
|
+
case 'generated-always-identity':
|
|
2554
|
+
case 'generated-by-default-identity':
|
|
2555
|
+
case 'raw':
|
|
2556
|
+
if (arg.rawClause) {
|
|
2557
|
+
appendComponent(arg.rawClause);
|
|
2558
|
+
}
|
|
2559
|
+
break;
|
|
2560
|
+
}
|
|
2561
|
+
return token;
|
|
2562
|
+
}
|
|
2563
|
+
visitTableConstraintDefinition(arg) {
|
|
2564
|
+
var _a, _b, _c;
|
|
2565
|
+
const token = new SqlPrintToken(SqlPrintTokenType.container, '', SqlPrintTokenContainerType.TableConstraintDefinition);
|
|
2566
|
+
const appendKeyword = (text) => {
|
|
2567
|
+
if (token.innerTokens.length > 0) {
|
|
2568
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2569
|
+
}
|
|
2570
|
+
token.innerTokens.push(new SqlPrintToken(SqlPrintTokenType.keyword, text));
|
|
2571
|
+
};
|
|
2572
|
+
const appendComponent = (component) => {
|
|
2573
|
+
if (token.innerTokens.length > 0) {
|
|
2574
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2575
|
+
}
|
|
2576
|
+
token.innerTokens.push(component.accept(this));
|
|
2577
|
+
};
|
|
2578
|
+
const appendColumns = (columns) => {
|
|
2579
|
+
if (!columns || columns.length === 0) {
|
|
2580
|
+
return;
|
|
2581
|
+
}
|
|
2582
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2583
|
+
token.innerTokens.push(SqlPrintTokenParser.PAREN_OPEN_TOKEN);
|
|
2584
|
+
const listToken = new SqlPrintToken(SqlPrintTokenType.container, '', SqlPrintTokenContainerType.ValueList);
|
|
2585
|
+
for (let i = 0; i < columns.length; i++) {
|
|
2586
|
+
if (i > 0) {
|
|
2587
|
+
listToken.innerTokens.push(...SqlPrintTokenParser.commaSpaceTokens());
|
|
2588
|
+
}
|
|
2589
|
+
listToken.innerTokens.push(columns[i].accept(this));
|
|
2590
|
+
}
|
|
2591
|
+
token.innerTokens.push(listToken);
|
|
2592
|
+
token.innerTokens.push(SqlPrintTokenParser.PAREN_CLOSE_TOKEN);
|
|
2593
|
+
};
|
|
2594
|
+
const useMysqlConstraintStyle = this.constraintStyle === 'mysql';
|
|
2595
|
+
const inlineNameKinds = new Set(['primary-key', 'unique', 'foreign-key']);
|
|
2596
|
+
const shouldInlineConstraintName = useMysqlConstraintStyle && !!arg.constraintName && inlineNameKinds.has(arg.kind);
|
|
2597
|
+
if (arg.constraintName && !shouldInlineConstraintName) {
|
|
2598
|
+
appendKeyword('constraint');
|
|
2599
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2600
|
+
token.innerTokens.push(arg.constraintName.accept(this));
|
|
2601
|
+
}
|
|
2602
|
+
switch (arg.kind) {
|
|
2603
|
+
case 'primary-key':
|
|
2604
|
+
appendKeyword('primary key');
|
|
2605
|
+
if (shouldInlineConstraintName && arg.constraintName) {
|
|
2606
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2607
|
+
token.innerTokens.push(arg.constraintName.accept(this));
|
|
2608
|
+
}
|
|
2609
|
+
appendColumns((_a = arg.columns) !== null && _a !== void 0 ? _a : []);
|
|
2610
|
+
break;
|
|
2611
|
+
case 'unique':
|
|
2612
|
+
if (useMysqlConstraintStyle) {
|
|
2613
|
+
appendKeyword('unique key');
|
|
2614
|
+
if (shouldInlineConstraintName && arg.constraintName) {
|
|
2615
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2616
|
+
token.innerTokens.push(arg.constraintName.accept(this));
|
|
2617
|
+
}
|
|
2618
|
+
}
|
|
2619
|
+
else {
|
|
2620
|
+
appendKeyword('unique');
|
|
2621
|
+
}
|
|
2622
|
+
appendColumns((_b = arg.columns) !== null && _b !== void 0 ? _b : []);
|
|
2623
|
+
break;
|
|
2624
|
+
case 'foreign-key':
|
|
2625
|
+
appendKeyword('foreign key');
|
|
2626
|
+
if (shouldInlineConstraintName && arg.constraintName) {
|
|
2627
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2628
|
+
token.innerTokens.push(arg.constraintName.accept(this));
|
|
2629
|
+
}
|
|
2630
|
+
appendColumns((_c = arg.columns) !== null && _c !== void 0 ? _c : []);
|
|
2631
|
+
if (arg.reference) {
|
|
2632
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2633
|
+
token.innerTokens.push(arg.reference.accept(this));
|
|
2634
|
+
}
|
|
2635
|
+
break;
|
|
2636
|
+
case 'check':
|
|
2637
|
+
if (arg.checkExpression) {
|
|
2638
|
+
appendKeyword('check');
|
|
2639
|
+
token.innerTokens.push(this.wrapWithParenExpression(arg.checkExpression));
|
|
2640
|
+
}
|
|
2641
|
+
break;
|
|
2642
|
+
case 'raw':
|
|
2643
|
+
if (arg.rawClause) {
|
|
2644
|
+
appendComponent(arg.rawClause);
|
|
2645
|
+
}
|
|
2646
|
+
break;
|
|
2647
|
+
}
|
|
2648
|
+
return token;
|
|
2649
|
+
}
|
|
2650
|
+
wrapWithParenExpression(expression) {
|
|
2651
|
+
// Reuse existing parentheses groups to avoid double-wrapping when callers already provided them.
|
|
2652
|
+
if (expression instanceof ParenExpression) {
|
|
2653
|
+
return this.visit(expression);
|
|
2654
|
+
}
|
|
2655
|
+
// Synthesize a ParenExpression wrapper so nested boolean groups render with consistent indentation.
|
|
2656
|
+
const synthetic = new ParenExpression(expression);
|
|
2657
|
+
return this.visit(synthetic);
|
|
2658
|
+
}
|
|
2659
|
+
visitReferenceDefinition(arg) {
|
|
2660
|
+
const token = new SqlPrintToken(SqlPrintTokenType.container, '', SqlPrintTokenContainerType.ReferenceDefinition);
|
|
2661
|
+
token.innerTokens.push(new SqlPrintToken(SqlPrintTokenType.keyword, 'references'));
|
|
2662
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2663
|
+
token.innerTokens.push(arg.targetTable.accept(this));
|
|
2664
|
+
if (arg.columns && arg.columns.length > 0) {
|
|
2665
|
+
token.innerTokens.push(SqlPrintTokenParser.PAREN_OPEN_TOKEN);
|
|
2666
|
+
const columnList = new SqlPrintToken(SqlPrintTokenType.container, '', SqlPrintTokenContainerType.ValueList);
|
|
2667
|
+
for (let i = 0; i < arg.columns.length; i++) {
|
|
2668
|
+
if (i > 0) {
|
|
2669
|
+
columnList.innerTokens.push(...SqlPrintTokenParser.commaSpaceTokens());
|
|
2670
|
+
}
|
|
2671
|
+
columnList.innerTokens.push(arg.columns[i].accept(this));
|
|
2672
|
+
}
|
|
2673
|
+
token.innerTokens.push(columnList);
|
|
2674
|
+
token.innerTokens.push(SqlPrintTokenParser.PAREN_CLOSE_TOKEN);
|
|
2675
|
+
}
|
|
2676
|
+
if (arg.matchType) {
|
|
2677
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2678
|
+
token.innerTokens.push(new SqlPrintToken(SqlPrintTokenType.keyword, `match ${arg.matchType}`));
|
|
2679
|
+
}
|
|
2680
|
+
if (arg.onDelete) {
|
|
2681
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2682
|
+
token.innerTokens.push(new SqlPrintToken(SqlPrintTokenType.keyword, 'on delete'));
|
|
2683
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2684
|
+
token.innerTokens.push(new SqlPrintToken(SqlPrintTokenType.keyword, arg.onDelete));
|
|
2685
|
+
}
|
|
2686
|
+
if (arg.onUpdate) {
|
|
2687
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2688
|
+
token.innerTokens.push(new SqlPrintToken(SqlPrintTokenType.keyword, 'on update'));
|
|
2689
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2690
|
+
token.innerTokens.push(new SqlPrintToken(SqlPrintTokenType.keyword, arg.onUpdate));
|
|
2691
|
+
}
|
|
2692
|
+
if (arg.deferrable === 'deferrable') {
|
|
2693
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2694
|
+
token.innerTokens.push(new SqlPrintToken(SqlPrintTokenType.keyword, 'deferrable'));
|
|
2695
|
+
}
|
|
2696
|
+
else if (arg.deferrable === 'not deferrable') {
|
|
2697
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2698
|
+
token.innerTokens.push(new SqlPrintToken(SqlPrintTokenType.keyword, 'not deferrable'));
|
|
2699
|
+
}
|
|
2700
|
+
if (arg.initially === 'immediate') {
|
|
2701
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2702
|
+
token.innerTokens.push(new SqlPrintToken(SqlPrintTokenType.keyword, 'initially immediate'));
|
|
2703
|
+
}
|
|
2704
|
+
else if (arg.initially === 'deferred') {
|
|
2705
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2706
|
+
token.innerTokens.push(new SqlPrintToken(SqlPrintTokenType.keyword, 'initially deferred'));
|
|
2707
|
+
}
|
|
2708
|
+
return token;
|
|
2709
|
+
}
|
|
2710
|
+
visitCreateIndexStatement(arg) {
|
|
2711
|
+
const keywordParts = ['create'];
|
|
2712
|
+
if (arg.unique) {
|
|
2713
|
+
keywordParts.push('unique');
|
|
2714
|
+
}
|
|
2715
|
+
keywordParts.push('index');
|
|
2716
|
+
if (arg.concurrently) {
|
|
2717
|
+
keywordParts.push('concurrently');
|
|
2718
|
+
}
|
|
2719
|
+
if (arg.ifNotExists) {
|
|
2720
|
+
keywordParts.push('if not exists');
|
|
2721
|
+
}
|
|
2722
|
+
const token = new SqlPrintToken(SqlPrintTokenType.keyword, keywordParts.join(' '), SqlPrintTokenContainerType.CreateIndexStatement);
|
|
2723
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2724
|
+
token.innerTokens.push(arg.indexName.accept(this));
|
|
2725
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2726
|
+
token.innerTokens.push(new SqlPrintToken(SqlPrintTokenType.keyword, 'on'));
|
|
2727
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2728
|
+
token.innerTokens.push(arg.tableName.accept(this));
|
|
2729
|
+
if (arg.usingMethod) {
|
|
2730
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2731
|
+
token.innerTokens.push(new SqlPrintToken(SqlPrintTokenType.keyword, 'using'));
|
|
2732
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2733
|
+
token.innerTokens.push(arg.usingMethod.accept(this));
|
|
2734
|
+
}
|
|
2735
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2736
|
+
token.innerTokens.push(SqlPrintTokenParser.PAREN_OPEN_TOKEN);
|
|
2737
|
+
const columnList = new SqlPrintToken(SqlPrintTokenType.container, '', SqlPrintTokenContainerType.IndexColumnList);
|
|
2738
|
+
for (let i = 0; i < arg.columns.length; i++) {
|
|
2739
|
+
if (i > 0) {
|
|
2740
|
+
columnList.innerTokens.push(...SqlPrintTokenParser.commaSpaceTokens());
|
|
2741
|
+
}
|
|
2742
|
+
columnList.innerTokens.push(arg.columns[i].accept(this));
|
|
2743
|
+
}
|
|
2744
|
+
token.innerTokens.push(columnList);
|
|
2745
|
+
token.innerTokens.push(SqlPrintTokenParser.PAREN_CLOSE_TOKEN);
|
|
2746
|
+
if (arg.include && arg.include.length > 0) {
|
|
2747
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2748
|
+
token.innerTokens.push(new SqlPrintToken(SqlPrintTokenType.keyword, 'include'));
|
|
2749
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2750
|
+
token.innerTokens.push(SqlPrintTokenParser.PAREN_OPEN_TOKEN);
|
|
2751
|
+
const includeList = new SqlPrintToken(SqlPrintTokenType.container, '', SqlPrintTokenContainerType.ValueList);
|
|
2752
|
+
for (let i = 0; i < arg.include.length; i++) {
|
|
2753
|
+
if (i > 0) {
|
|
2754
|
+
includeList.innerTokens.push(...SqlPrintTokenParser.commaSpaceTokens());
|
|
2755
|
+
}
|
|
2756
|
+
includeList.innerTokens.push(arg.include[i].accept(this));
|
|
2757
|
+
}
|
|
2758
|
+
token.innerTokens.push(includeList);
|
|
2759
|
+
token.innerTokens.push(SqlPrintTokenParser.PAREN_CLOSE_TOKEN);
|
|
2760
|
+
}
|
|
2761
|
+
if (arg.withOptions) {
|
|
2762
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2763
|
+
token.innerTokens.push(arg.withOptions.accept(this));
|
|
2764
|
+
}
|
|
2765
|
+
if (arg.tablespace) {
|
|
2766
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2767
|
+
token.innerTokens.push(new SqlPrintToken(SqlPrintTokenType.keyword, 'tablespace'));
|
|
2768
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2769
|
+
token.innerTokens.push(arg.tablespace.accept(this));
|
|
2770
|
+
}
|
|
2771
|
+
if (arg.where) {
|
|
2772
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2773
|
+
token.innerTokens.push(new SqlPrintToken(SqlPrintTokenType.keyword, 'where'));
|
|
2774
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2775
|
+
token.innerTokens.push(this.visit(arg.where));
|
|
2776
|
+
}
|
|
2777
|
+
return token;
|
|
2778
|
+
}
|
|
2779
|
+
visitIndexColumnDefinition(arg) {
|
|
2780
|
+
const token = new SqlPrintToken(SqlPrintTokenType.container, '', SqlPrintTokenContainerType.IndexColumnDefinition);
|
|
2781
|
+
token.innerTokens.push(this.visit(arg.expression));
|
|
2782
|
+
if (arg.collation) {
|
|
2783
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2784
|
+
token.innerTokens.push(new SqlPrintToken(SqlPrintTokenType.keyword, 'collate'));
|
|
2785
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2786
|
+
token.innerTokens.push(arg.collation.accept(this));
|
|
2787
|
+
}
|
|
2788
|
+
if (arg.operatorClass) {
|
|
2789
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2790
|
+
token.innerTokens.push(arg.operatorClass.accept(this));
|
|
2791
|
+
}
|
|
2792
|
+
if (arg.sortOrder) {
|
|
2793
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2794
|
+
token.innerTokens.push(new SqlPrintToken(SqlPrintTokenType.keyword, arg.sortOrder));
|
|
2795
|
+
}
|
|
2796
|
+
if (arg.nullsOrder) {
|
|
2797
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2798
|
+
token.innerTokens.push(new SqlPrintToken(SqlPrintTokenType.keyword, `nulls ${arg.nullsOrder}`));
|
|
2799
|
+
}
|
|
2800
|
+
return token;
|
|
2801
|
+
}
|
|
2802
|
+
visitDropTableStatement(arg) {
|
|
2803
|
+
const keyword = arg.ifExists ? 'drop table if exists' : 'drop table';
|
|
2804
|
+
const token = new SqlPrintToken(SqlPrintTokenType.keyword, keyword, SqlPrintTokenContainerType.DropTableStatement);
|
|
2805
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2806
|
+
const tableList = new SqlPrintToken(SqlPrintTokenType.container, '', SqlPrintTokenContainerType.ValueList);
|
|
2807
|
+
for (let i = 0; i < arg.tables.length; i++) {
|
|
2808
|
+
if (i > 0) {
|
|
2809
|
+
tableList.innerTokens.push(...SqlPrintTokenParser.commaSpaceTokens());
|
|
2810
|
+
}
|
|
2811
|
+
tableList.innerTokens.push(arg.tables[i].accept(this));
|
|
2812
|
+
}
|
|
2813
|
+
token.innerTokens.push(tableList);
|
|
2814
|
+
if (arg.behavior) {
|
|
2815
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2816
|
+
token.innerTokens.push(new SqlPrintToken(SqlPrintTokenType.keyword, arg.behavior));
|
|
2817
|
+
}
|
|
2818
|
+
return token;
|
|
2819
|
+
}
|
|
2820
|
+
visitDropIndexStatement(arg) {
|
|
2821
|
+
const keywordParts = ['drop', 'index'];
|
|
2822
|
+
if (arg.concurrently) {
|
|
2823
|
+
keywordParts.push('concurrently');
|
|
2824
|
+
}
|
|
2825
|
+
if (arg.ifExists) {
|
|
2826
|
+
keywordParts.push('if exists');
|
|
2827
|
+
}
|
|
2828
|
+
const token = new SqlPrintToken(SqlPrintTokenType.keyword, keywordParts.join(' '), SqlPrintTokenContainerType.DropIndexStatement);
|
|
2829
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2830
|
+
const indexList = new SqlPrintToken(SqlPrintTokenType.container, '', SqlPrintTokenContainerType.ValueList);
|
|
2831
|
+
for (let i = 0; i < arg.indexNames.length; i++) {
|
|
2832
|
+
if (i > 0) {
|
|
2833
|
+
indexList.innerTokens.push(...SqlPrintTokenParser.commaSpaceTokens());
|
|
2834
|
+
}
|
|
2835
|
+
indexList.innerTokens.push(arg.indexNames[i].accept(this));
|
|
2836
|
+
}
|
|
2837
|
+
token.innerTokens.push(indexList);
|
|
2838
|
+
if (arg.behavior) {
|
|
2839
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2840
|
+
token.innerTokens.push(new SqlPrintToken(SqlPrintTokenType.keyword, arg.behavior));
|
|
2841
|
+
}
|
|
2842
|
+
return token;
|
|
2843
|
+
}
|
|
2844
|
+
visitAlterTableStatement(arg) {
|
|
2845
|
+
const keywordParts = ['alter', 'table'];
|
|
2846
|
+
if (arg.ifExists) {
|
|
2847
|
+
keywordParts.push('if exists');
|
|
2848
|
+
}
|
|
2849
|
+
if (arg.only) {
|
|
2850
|
+
keywordParts.push('only');
|
|
2851
|
+
}
|
|
2852
|
+
const token = new SqlPrintToken(SqlPrintTokenType.keyword, keywordParts.join(' '), SqlPrintTokenContainerType.AlterTableStatement);
|
|
2853
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2854
|
+
token.innerTokens.push(arg.table.accept(this));
|
|
2855
|
+
for (let i = 0; i < arg.actions.length; i++) {
|
|
2856
|
+
if (i === 0) {
|
|
2857
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2858
|
+
}
|
|
2859
|
+
else {
|
|
2860
|
+
token.innerTokens.push(SqlPrintTokenParser.COMMA_TOKEN);
|
|
2861
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2862
|
+
}
|
|
2863
|
+
token.innerTokens.push(arg.actions[i].accept(this));
|
|
2864
|
+
}
|
|
2865
|
+
return token;
|
|
2866
|
+
}
|
|
2867
|
+
visitAlterTableAddConstraint(arg) {
|
|
2868
|
+
const keyword = arg.ifNotExists ? 'add if not exists' : 'add';
|
|
2869
|
+
const token = new SqlPrintToken(SqlPrintTokenType.container, '', SqlPrintTokenContainerType.AlterTableAddConstraint);
|
|
2870
|
+
token.innerTokens.push(new SqlPrintToken(SqlPrintTokenType.keyword, keyword));
|
|
2871
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2872
|
+
token.innerTokens.push(arg.constraint.accept(this));
|
|
2873
|
+
if (arg.notValid) {
|
|
2874
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2875
|
+
token.innerTokens.push(new SqlPrintToken(SqlPrintTokenType.keyword, 'not valid'));
|
|
2876
|
+
}
|
|
2877
|
+
return token;
|
|
2878
|
+
}
|
|
2879
|
+
visitAlterTableDropConstraint(arg) {
|
|
2880
|
+
let keyword = 'drop constraint';
|
|
2881
|
+
if (arg.ifExists) {
|
|
2882
|
+
keyword += ' if exists';
|
|
2883
|
+
}
|
|
2884
|
+
const token = new SqlPrintToken(SqlPrintTokenType.container, '', SqlPrintTokenContainerType.AlterTableDropConstraint);
|
|
2885
|
+
token.innerTokens.push(new SqlPrintToken(SqlPrintTokenType.keyword, keyword));
|
|
2886
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2887
|
+
token.innerTokens.push(arg.constraintName.accept(this));
|
|
2888
|
+
if (arg.behavior) {
|
|
2889
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2890
|
+
token.innerTokens.push(new SqlPrintToken(SqlPrintTokenType.keyword, arg.behavior));
|
|
2891
|
+
}
|
|
2892
|
+
return token;
|
|
2893
|
+
}
|
|
2894
|
+
visitAlterTableDropColumn(arg) {
|
|
2895
|
+
let keyword = 'drop column';
|
|
2896
|
+
if (arg.ifExists) {
|
|
2897
|
+
keyword += ' if exists';
|
|
2898
|
+
}
|
|
2899
|
+
const token = new SqlPrintToken(SqlPrintTokenType.container, '', SqlPrintTokenContainerType.AlterTableDropColumn);
|
|
2900
|
+
token.innerTokens.push(new SqlPrintToken(SqlPrintTokenType.keyword, keyword));
|
|
2901
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2902
|
+
token.innerTokens.push(arg.columnName.accept(this));
|
|
2903
|
+
if (arg.behavior) {
|
|
2904
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2905
|
+
token.innerTokens.push(new SqlPrintToken(SqlPrintTokenType.keyword, arg.behavior));
|
|
2906
|
+
}
|
|
2907
|
+
return token;
|
|
2908
|
+
}
|
|
2909
|
+
visitDropConstraintStatement(arg) {
|
|
2910
|
+
let keyword = 'drop constraint';
|
|
2911
|
+
if (arg.ifExists) {
|
|
2912
|
+
keyword += ' if exists';
|
|
2913
|
+
}
|
|
2914
|
+
const token = new SqlPrintToken(SqlPrintTokenType.keyword, keyword, SqlPrintTokenContainerType.DropConstraintStatement);
|
|
2915
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2916
|
+
token.innerTokens.push(arg.constraintName.accept(this));
|
|
2917
|
+
if (arg.behavior) {
|
|
2918
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
|
2919
|
+
token.innerTokens.push(new SqlPrintToken(SqlPrintTokenType.keyword, arg.behavior));
|
|
2920
|
+
}
|
|
1938
2921
|
return token;
|
|
1939
2922
|
}
|
|
1940
2923
|
}
|