rawsql-ts 0.5.0-beta → 0.7.0-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 +152 -121
- package/dist/esm/index.js +1 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/models/Clause.js +185 -19
- package/dist/esm/models/Clause.js.map +1 -1
- package/dist/esm/models/CreateTableQuery.js +12 -22
- package/dist/esm/models/CreateTableQuery.js.map +1 -1
- package/dist/esm/models/InsertQuery.js +2 -9
- package/dist/esm/models/InsertQuery.js.map +1 -1
- package/dist/esm/models/KeywordTrie.js +2 -0
- package/dist/esm/models/KeywordTrie.js.map +1 -1
- package/dist/esm/models/SimpleSelectQuery.js +17 -15
- package/dist/esm/models/SimpleSelectQuery.js.map +1 -1
- package/dist/esm/models/SqlPrintToken.js +94 -0
- package/dist/esm/models/SqlPrintToken.js.map +1 -0
- package/dist/esm/models/UpdateQuery.js +25 -0
- package/dist/esm/models/UpdateQuery.js.map +1 -0
- package/dist/esm/models/ValueComponent.js +105 -19
- package/dist/esm/models/ValueComponent.js.map +1 -1
- package/dist/esm/parsers/FetchClauseParser.js +84 -0
- package/dist/esm/parsers/FetchClauseParser.js.map +1 -0
- package/dist/esm/parsers/FullNameParser.js +94 -0
- package/dist/esm/parsers/FullNameParser.js.map +1 -0
- package/dist/esm/parsers/FunctionExpressionParser.js +33 -32
- package/dist/esm/parsers/FunctionExpressionParser.js.map +1 -1
- package/dist/esm/parsers/IdentifierDecorator.js +13 -0
- package/dist/esm/parsers/IdentifierDecorator.js.map +1 -0
- package/dist/esm/parsers/IdentifierParser.js +5 -30
- package/dist/esm/parsers/IdentifierParser.js.map +1 -1
- package/dist/esm/parsers/InsertQueryParser.js +7 -28
- package/dist/esm/parsers/InsertQueryParser.js.map +1 -1
- package/dist/esm/parsers/JoinClauseParser.js +13 -35
- package/dist/esm/parsers/JoinClauseParser.js.map +1 -1
- package/dist/esm/parsers/JoinOnClauseParser.js +17 -0
- package/dist/esm/parsers/JoinOnClauseParser.js.map +1 -0
- package/dist/esm/parsers/JoinUsingClauseParser.js +19 -0
- package/dist/esm/parsers/JoinUsingClauseParser.js.map +1 -0
- package/dist/esm/parsers/LimitClauseParser.js +1 -13
- package/dist/esm/parsers/LimitClauseParser.js.map +1 -1
- package/dist/esm/parsers/OffsetClauseParser.js +38 -0
- package/dist/esm/parsers/OffsetClauseParser.js.map +1 -0
- package/dist/esm/parsers/ParameterDecorator.js +36 -0
- package/dist/esm/parsers/ParameterDecorator.js.map +1 -0
- package/dist/esm/parsers/ReturningClauseParser.js +31 -0
- package/dist/esm/parsers/ReturningClauseParser.js.map +1 -0
- package/dist/esm/parsers/SelectClauseParser.js +25 -2
- package/dist/esm/parsers/SelectClauseParser.js.map +1 -1
- package/dist/esm/parsers/SelectQueryParser.js +40 -13
- package/dist/esm/parsers/SelectQueryParser.js.map +1 -1
- package/dist/esm/parsers/SetClauseParser.js +39 -0
- package/dist/esm/parsers/SetClauseParser.js.map +1 -0
- package/dist/esm/parsers/SourceExpressionParser.js +19 -0
- package/dist/esm/parsers/SourceExpressionParser.js.map +1 -1
- package/dist/esm/parsers/SourceParser.js +31 -19
- package/dist/esm/parsers/SourceParser.js.map +1 -1
- package/dist/esm/parsers/SqlPrintTokenParser.js +1058 -0
- package/dist/esm/parsers/SqlPrintTokenParser.js.map +1 -0
- package/dist/esm/parsers/UpdateClauseParser.js +17 -0
- package/dist/esm/parsers/UpdateClauseParser.js.map +1 -0
- package/dist/esm/parsers/UpdateQueryParser.js +84 -0
- package/dist/esm/parsers/UpdateQueryParser.js.map +1 -0
- package/dist/esm/parsers/ValueParser.js +13 -11
- package/dist/esm/parsers/ValueParser.js.map +1 -1
- package/dist/esm/parsers/WindowClauseParser.js +27 -15
- package/dist/esm/parsers/WindowClauseParser.js.map +1 -1
- package/dist/esm/tokenReaders/BaseTokenReader.js +3 -3
- package/dist/esm/tokenReaders/BaseTokenReader.js.map +1 -1
- package/dist/esm/tokenReaders/CommandTokenReader.js +8 -2
- package/dist/esm/tokenReaders/CommandTokenReader.js.map +1 -1
- package/dist/esm/transformers/CTECollector.js +9 -10
- package/dist/esm/transformers/CTECollector.js.map +1 -1
- package/dist/esm/transformers/CTEDisabler.js +12 -11
- package/dist/esm/transformers/CTEDisabler.js.map +1 -1
- package/dist/esm/transformers/CTEInjector.js +2 -2
- package/dist/esm/transformers/Formatter.js +19 -569
- package/dist/esm/transformers/Formatter.js.map +1 -1
- package/dist/esm/transformers/LinePrinter.js +81 -0
- package/dist/esm/transformers/LinePrinter.js.map +1 -0
- package/dist/esm/transformers/QueryBuilder.js +62 -24
- package/dist/esm/transformers/QueryBuilder.js.map +1 -1
- package/dist/esm/transformers/SelectValueCollector.js +4 -4
- package/dist/esm/transformers/SelectableColumnCollector.js +26 -9
- package/dist/esm/transformers/SelectableColumnCollector.js.map +1 -1
- package/dist/esm/transformers/SqlFormatter.js +31 -0
- package/dist/esm/transformers/SqlFormatter.js.map +1 -0
- package/dist/esm/transformers/SqlOutputToken.js +9 -0
- package/dist/esm/transformers/SqlOutputToken.js.map +1 -0
- package/dist/esm/transformers/SqlPrinter.js +144 -0
- package/dist/esm/transformers/SqlPrinter.js.map +1 -0
- package/dist/esm/transformers/TableSourceCollector.js +32 -16
- package/dist/esm/transformers/TableSourceCollector.js.map +1 -1
- package/dist/esm/transformers/UpstreamSelectQueryFinder.js +1 -1
- package/dist/esm/types/index.d.ts +1 -0
- package/dist/esm/types/models/Clause.d.ts +119 -14
- package/dist/esm/types/models/InsertQuery.d.ts +4 -9
- package/dist/esm/types/models/SimpleSelectQuery.d.ts +20 -5
- package/dist/esm/types/models/SqlPrintToken.d.ts +102 -0
- package/dist/esm/types/models/UpdateQuery.d.ts +31 -0
- package/dist/esm/types/models/ValueComponent.d.ts +45 -8
- package/dist/esm/types/parsers/FetchClauseParser.d.ts +24 -0
- package/dist/esm/types/parsers/FullNameParser.d.ts +27 -0
- package/dist/esm/types/parsers/IdentifierDecorator.d.ts +9 -0
- package/dist/esm/types/parsers/InsertQueryParser.d.ts +0 -1
- package/dist/esm/types/parsers/JoinClauseParser.d.ts +0 -2
- package/dist/esm/types/parsers/JoinOnClauseParser.d.ts +8 -0
- package/dist/esm/types/parsers/JoinUsingClauseParser.d.ts +8 -0
- package/dist/esm/types/parsers/OffsetClauseParser.d.ts +9 -0
- package/dist/esm/types/parsers/ParameterDecorator.d.ts +20 -0
- package/dist/esm/types/parsers/ReturningClauseParser.d.ts +12 -0
- package/dist/esm/types/parsers/SelectClauseParser.d.ts +19 -2
- package/dist/esm/types/parsers/SetClauseParser.d.ts +11 -0
- package/dist/esm/types/parsers/SourceExpressionParser.d.ts +8 -0
- package/dist/esm/types/parsers/SourceParser.d.ts +14 -0
- package/dist/esm/types/parsers/SqlPrintTokenParser.d.ts +144 -0
- package/dist/esm/types/parsers/UpdateClauseParser.d.ts +15 -0
- package/dist/esm/types/parsers/UpdateQueryParser.d.ts +16 -0
- package/dist/esm/types/parsers/WindowClauseParser.d.ts +3 -3
- package/dist/esm/types/transformers/Formatter.d.ts +8 -99
- package/dist/esm/types/transformers/LinePrinter.d.ts +41 -0
- package/dist/esm/types/transformers/QueryBuilder.d.ts +9 -0
- package/dist/esm/types/transformers/SelectableColumnCollector.d.ts +2 -0
- package/dist/esm/types/transformers/SqlFormatter.d.ts +40 -0
- package/dist/esm/types/transformers/SqlOutputToken.d.ts +6 -0
- package/dist/esm/types/transformers/SqlPrinter.d.ts +54 -0
- package/dist/esm/types/transformers/TableSourceCollector.d.ts +2 -0
- package/dist/esm/utils/stringUtils.js +17 -0
- package/dist/esm/utils/stringUtils.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/models/Clause.d.ts +119 -14
- package/dist/models/Clause.js +194 -20
- package/dist/models/Clause.js.map +1 -1
- package/dist/models/CreateTableQuery.js +12 -22
- package/dist/models/CreateTableQuery.js.map +1 -1
- package/dist/models/InsertQuery.d.ts +4 -9
- package/dist/models/InsertQuery.js +2 -9
- package/dist/models/InsertQuery.js.map +1 -1
- package/dist/models/KeywordTrie.js +2 -0
- package/dist/models/KeywordTrie.js.map +1 -1
- package/dist/models/SimpleSelectQuery.d.ts +20 -5
- package/dist/models/SimpleSelectQuery.js +17 -15
- package/dist/models/SimpleSelectQuery.js.map +1 -1
- package/dist/models/SqlPrintToken.d.ts +102 -0
- package/dist/models/SqlPrintToken.js +98 -0
- package/dist/models/SqlPrintToken.js.map +1 -0
- package/dist/models/UpdateQuery.d.ts +31 -0
- package/dist/models/UpdateQuery.js +29 -0
- package/dist/models/UpdateQuery.js.map +1 -0
- package/dist/models/ValueComponent.d.ts +45 -8
- package/dist/models/ValueComponent.js +107 -20
- package/dist/models/ValueComponent.js.map +1 -1
- package/dist/parsers/FetchClauseParser.d.ts +24 -0
- package/dist/parsers/FetchClauseParser.js +89 -0
- package/dist/parsers/FetchClauseParser.js.map +1 -0
- package/dist/parsers/FullNameParser.d.ts +27 -0
- package/dist/parsers/FullNameParser.js +98 -0
- package/dist/parsers/FullNameParser.js.map +1 -0
- package/dist/parsers/FunctionExpressionParser.js +32 -31
- package/dist/parsers/FunctionExpressionParser.js.map +1 -1
- package/dist/parsers/IdentifierDecorator.d.ts +9 -0
- package/dist/parsers/IdentifierDecorator.js +17 -0
- package/dist/parsers/IdentifierDecorator.js.map +1 -0
- package/dist/parsers/IdentifierParser.js +5 -30
- package/dist/parsers/IdentifierParser.js.map +1 -1
- package/dist/parsers/InsertQueryParser.d.ts +0 -1
- package/dist/parsers/InsertQueryParser.js +7 -28
- package/dist/parsers/InsertQueryParser.js.map +1 -1
- package/dist/parsers/JoinClauseParser.d.ts +0 -2
- package/dist/parsers/JoinClauseParser.js +12 -34
- package/dist/parsers/JoinClauseParser.js.map +1 -1
- package/dist/parsers/JoinOnClauseParser.d.ts +8 -0
- package/dist/parsers/JoinOnClauseParser.js +21 -0
- package/dist/parsers/JoinOnClauseParser.js.map +1 -0
- package/dist/parsers/JoinUsingClauseParser.d.ts +8 -0
- package/dist/parsers/JoinUsingClauseParser.js +23 -0
- package/dist/parsers/JoinUsingClauseParser.js.map +1 -0
- package/dist/parsers/LimitClauseParser.js +1 -13
- package/dist/parsers/LimitClauseParser.js.map +1 -1
- package/dist/parsers/OffsetClauseParser.d.ts +9 -0
- package/dist/parsers/OffsetClauseParser.js +42 -0
- package/dist/parsers/OffsetClauseParser.js.map +1 -0
- package/dist/parsers/ParameterDecorator.d.ts +20 -0
- package/dist/parsers/ParameterDecorator.js +40 -0
- package/dist/parsers/ParameterDecorator.js.map +1 -0
- package/dist/parsers/ReturningClauseParser.d.ts +12 -0
- package/dist/parsers/ReturningClauseParser.js +35 -0
- package/dist/parsers/ReturningClauseParser.js.map +1 -0
- package/dist/parsers/SelectClauseParser.d.ts +19 -2
- package/dist/parsers/SelectClauseParser.js +28 -4
- package/dist/parsers/SelectClauseParser.js.map +1 -1
- package/dist/parsers/SelectQueryParser.js +40 -13
- package/dist/parsers/SelectQueryParser.js.map +1 -1
- package/dist/parsers/SetClauseParser.d.ts +11 -0
- package/dist/parsers/SetClauseParser.js +43 -0
- package/dist/parsers/SetClauseParser.js.map +1 -0
- package/dist/parsers/SourceExpressionParser.d.ts +8 -0
- package/dist/parsers/SourceExpressionParser.js +19 -0
- package/dist/parsers/SourceExpressionParser.js.map +1 -1
- package/dist/parsers/SourceParser.d.ts +14 -0
- package/dist/parsers/SourceParser.js +31 -19
- package/dist/parsers/SourceParser.js.map +1 -1
- package/dist/parsers/SqlPrintTokenParser.d.ts +144 -0
- package/dist/parsers/SqlPrintTokenParser.js +1062 -0
- package/dist/parsers/SqlPrintTokenParser.js.map +1 -0
- package/dist/parsers/UpdateClauseParser.d.ts +15 -0
- package/dist/parsers/UpdateClauseParser.js +21 -0
- package/dist/parsers/UpdateClauseParser.js.map +1 -0
- package/dist/parsers/UpdateQueryParser.d.ts +16 -0
- package/dist/parsers/UpdateQueryParser.js +88 -0
- package/dist/parsers/UpdateQueryParser.js.map +1 -0
- package/dist/parsers/ValueParser.js +13 -11
- package/dist/parsers/ValueParser.js.map +1 -1
- package/dist/parsers/WindowClauseParser.d.ts +3 -3
- package/dist/parsers/WindowClauseParser.js +26 -14
- package/dist/parsers/WindowClauseParser.js.map +1 -1
- package/dist/tokenReaders/BaseTokenReader.js +3 -3
- package/dist/tokenReaders/BaseTokenReader.js.map +1 -1
- package/dist/tokenReaders/CommandTokenReader.js +8 -2
- package/dist/tokenReaders/CommandTokenReader.js.map +1 -1
- package/dist/transformers/CTECollector.js +9 -10
- package/dist/transformers/CTECollector.js.map +1 -1
- package/dist/transformers/CTEDisabler.js +11 -10
- package/dist/transformers/CTEDisabler.js.map +1 -1
- package/dist/transformers/CTEInjector.js +2 -2
- package/dist/transformers/Formatter.d.ts +8 -99
- package/dist/transformers/Formatter.js +20 -570
- package/dist/transformers/Formatter.js.map +1 -1
- package/dist/transformers/LinePrinter.d.ts +41 -0
- package/dist/transformers/LinePrinter.js +86 -0
- package/dist/transformers/LinePrinter.js.map +1 -0
- package/dist/transformers/QueryBuilder.d.ts +9 -0
- package/dist/transformers/QueryBuilder.js +61 -23
- package/dist/transformers/QueryBuilder.js.map +1 -1
- package/dist/transformers/SelectValueCollector.js +4 -4
- package/dist/transformers/SelectableColumnCollector.d.ts +2 -0
- package/dist/transformers/SelectableColumnCollector.js +25 -8
- package/dist/transformers/SelectableColumnCollector.js.map +1 -1
- package/dist/transformers/SqlFormatter.d.ts +40 -0
- package/dist/transformers/SqlFormatter.js +35 -0
- package/dist/transformers/SqlFormatter.js.map +1 -0
- package/dist/transformers/SqlOutputToken.d.ts +6 -0
- package/dist/transformers/SqlOutputToken.js +13 -0
- package/dist/transformers/SqlOutputToken.js.map +1 -0
- package/dist/transformers/SqlPrinter.d.ts +54 -0
- package/dist/transformers/SqlPrinter.js +148 -0
- package/dist/transformers/SqlPrinter.js.map +1 -0
- package/dist/transformers/TableSourceCollector.d.ts +2 -0
- package/dist/transformers/TableSourceCollector.js +30 -14
- package/dist/transformers/TableSourceCollector.js.map +1 -1
- package/dist/transformers/UpstreamSelectQueryFinder.js +1 -1
- package/dist/utils/stringUtils.js +17 -0
- package/dist/utils/stringUtils.js.map +1 -1
- package/package.json +2 -1
- package/dist/esm/types/utils/extractNamespacesAndName.d.ts +0 -5
- package/dist/esm/types/utils/parseEscapedOrDotSeparatedIdentifiers.d.ts +0 -9
- package/dist/esm/utils/extractNamespacesAndName.js +0 -16
- package/dist/esm/utils/extractNamespacesAndName.js.map +0 -1
- package/dist/esm/utils/parseEscapedOrDotSeparatedIdentifiers.js +0 -39
- package/dist/esm/utils/parseEscapedOrDotSeparatedIdentifiers.js.map +0 -1
- package/dist/utils/extractNamespacesAndName.d.ts +0 -5
- package/dist/utils/extractNamespacesAndName.js +0 -18
- package/dist/utils/extractNamespacesAndName.js.map +0 -1
- package/dist/utils/parseEscapedOrDotSeparatedIdentifiers.d.ts +0 -9
- package/dist/utils/parseEscapedOrDotSeparatedIdentifiers.js +0 -42
- package/dist/utils/parseEscapedOrDotSeparatedIdentifiers.js.map +0 -1
@@ -0,0 +1,1058 @@
|
|
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";
|
2
|
+
import { BinarySelectQuery, SimpleSelectQuery, ValuesQuery } from "../models/SelectQuery";
|
3
|
+
import { SqlPrintToken, SqlPrintTokenType, SqlPrintTokenContainerType } from "../models/SqlPrintToken";
|
4
|
+
import { ValueList, ColumnReference, FunctionCall, UnaryExpression, BinaryExpression, LiteralValue, ParameterExpression, SwitchCaseArgument, CaseKeyValuePair, RawString, IdentifierString, ParenExpression, CastExpression, CaseExpression, ArrayExpression, BetweenExpression, StringSpecifierExpression, TypeValue, TupleExpression, WindowFrameExpression, QualifiedName, InlineQuery, WindowFrameSpec, WindowFrameBoundStatic, WindowFrameBoundaryValue } from "../models/ValueComponent";
|
5
|
+
import { ParameterCollector } from "../transformers/ParameterCollector";
|
6
|
+
import { IdentifierDecorator } from "./IdentifierDecorator";
|
7
|
+
import { ParameterDecorator } from "./ParameterDecorator";
|
8
|
+
import { InsertQuery } from "../models/InsertQuery";
|
9
|
+
import { UpdateQuery } from "../models/UpdateQuery";
|
10
|
+
import { CreateTableQuery } from "../models/CreateTableQuery";
|
11
|
+
export var ParameterStyle;
|
12
|
+
(function (ParameterStyle) {
|
13
|
+
ParameterStyle["Anonymous"] = "anonymous";
|
14
|
+
ParameterStyle["Indexed"] = "indexed";
|
15
|
+
ParameterStyle["Named"] = "named";
|
16
|
+
})(ParameterStyle || (ParameterStyle = {}));
|
17
|
+
export const PRESETS = {
|
18
|
+
mysql: {
|
19
|
+
identifierEscape: { start: '`', end: '`' },
|
20
|
+
parameterSymbol: '?',
|
21
|
+
parameterStyle: ParameterStyle.Anonymous,
|
22
|
+
},
|
23
|
+
postgres: {
|
24
|
+
identifierEscape: { start: '"', end: '"' },
|
25
|
+
parameterSymbol: '$',
|
26
|
+
parameterStyle: ParameterStyle.Indexed,
|
27
|
+
},
|
28
|
+
postgresWithNamedParams: {
|
29
|
+
identifierEscape: { start: '"', end: '"' },
|
30
|
+
parameterSymbol: ':',
|
31
|
+
parameterStyle: ParameterStyle.Named,
|
32
|
+
},
|
33
|
+
sqlserver: {
|
34
|
+
identifierEscape: { start: '[', end: ']' },
|
35
|
+
parameterSymbol: '@',
|
36
|
+
parameterStyle: ParameterStyle.Named,
|
37
|
+
},
|
38
|
+
sqlite: {
|
39
|
+
identifierEscape: { start: '"', end: '"' },
|
40
|
+
parameterSymbol: ':',
|
41
|
+
parameterStyle: ParameterStyle.Named,
|
42
|
+
},
|
43
|
+
oracle: {
|
44
|
+
identifierEscape: { start: '"', end: '"' },
|
45
|
+
parameterSymbol: ':',
|
46
|
+
parameterStyle: ParameterStyle.Named,
|
47
|
+
},
|
48
|
+
clickhouse: {
|
49
|
+
identifierEscape: { start: '`', end: '`' },
|
50
|
+
parameterSymbol: '?',
|
51
|
+
parameterStyle: ParameterStyle.Anonymous,
|
52
|
+
},
|
53
|
+
firebird: {
|
54
|
+
identifierEscape: { start: '"', end: '"' },
|
55
|
+
parameterSymbol: '?',
|
56
|
+
parameterStyle: ParameterStyle.Anonymous,
|
57
|
+
},
|
58
|
+
db2: {
|
59
|
+
identifierEscape: { start: '"', end: '"' },
|
60
|
+
parameterSymbol: '?',
|
61
|
+
parameterStyle: ParameterStyle.Anonymous,
|
62
|
+
},
|
63
|
+
snowflake: {
|
64
|
+
identifierEscape: { start: '"', end: '"' },
|
65
|
+
parameterSymbol: '?',
|
66
|
+
parameterStyle: ParameterStyle.Anonymous,
|
67
|
+
},
|
68
|
+
cloudspanner: {
|
69
|
+
identifierEscape: { start: '`', end: '`' },
|
70
|
+
parameterSymbol: '@',
|
71
|
+
parameterStyle: ParameterStyle.Named,
|
72
|
+
},
|
73
|
+
duckdb: {
|
74
|
+
identifierEscape: { start: '"', end: '"' },
|
75
|
+
parameterSymbol: '?',
|
76
|
+
parameterStyle: ParameterStyle.Anonymous,
|
77
|
+
},
|
78
|
+
cockroachdb: {
|
79
|
+
identifierEscape: { start: '"', end: '"' },
|
80
|
+
parameterSymbol: '$',
|
81
|
+
parameterStyle: ParameterStyle.Indexed,
|
82
|
+
},
|
83
|
+
athena: {
|
84
|
+
identifierEscape: { start: '"', end: '"' },
|
85
|
+
parameterSymbol: '?',
|
86
|
+
parameterStyle: ParameterStyle.Anonymous,
|
87
|
+
},
|
88
|
+
bigquery: {
|
89
|
+
identifierEscape: { start: '`', end: '`' },
|
90
|
+
parameterSymbol: '@',
|
91
|
+
parameterStyle: ParameterStyle.Named,
|
92
|
+
},
|
93
|
+
hive: {
|
94
|
+
identifierEscape: { start: '`', end: '`' },
|
95
|
+
parameterSymbol: '?',
|
96
|
+
parameterStyle: ParameterStyle.Anonymous,
|
97
|
+
},
|
98
|
+
mariadb: {
|
99
|
+
identifierEscape: { start: '`', end: '`' },
|
100
|
+
parameterSymbol: '?',
|
101
|
+
parameterStyle: ParameterStyle.Anonymous,
|
102
|
+
},
|
103
|
+
redshift: {
|
104
|
+
identifierEscape: { start: '"', end: '"' },
|
105
|
+
parameterSymbol: '$',
|
106
|
+
parameterStyle: ParameterStyle.Indexed,
|
107
|
+
},
|
108
|
+
flinksql: {
|
109
|
+
identifierEscape: { start: '`', end: '`' },
|
110
|
+
parameterSymbol: '?',
|
111
|
+
parameterStyle: ParameterStyle.Anonymous,
|
112
|
+
},
|
113
|
+
mongodb: {
|
114
|
+
identifierEscape: { start: '"', end: '"' },
|
115
|
+
parameterSymbol: '?',
|
116
|
+
parameterStyle: ParameterStyle.Anonymous,
|
117
|
+
},
|
118
|
+
};
|
119
|
+
export class SqlPrintTokenParser {
|
120
|
+
constructor(options) {
|
121
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
122
|
+
this.handlers = new Map();
|
123
|
+
this.index = 1;
|
124
|
+
if (options === null || options === void 0 ? void 0 : options.preset) {
|
125
|
+
const preset = options.preset;
|
126
|
+
options = Object.assign(Object.assign({}, preset), options);
|
127
|
+
}
|
128
|
+
this.parameterDecorator = new ParameterDecorator({
|
129
|
+
prefix: typeof (options === null || options === void 0 ? void 0 : options.parameterSymbol) === 'string' ? options.parameterSymbol : (_b = (_a = options === null || options === void 0 ? void 0 : options.parameterSymbol) === null || _a === void 0 ? void 0 : _a.start) !== null && _b !== void 0 ? _b : ':',
|
130
|
+
suffix: typeof (options === null || options === void 0 ? void 0 : options.parameterSymbol) === 'object' ? options.parameterSymbol.end : '',
|
131
|
+
style: (_c = options === null || options === void 0 ? void 0 : options.parameterStyle) !== null && _c !== void 0 ? _c : 'named'
|
132
|
+
});
|
133
|
+
this.identifierDecorator = new IdentifierDecorator({
|
134
|
+
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 : '"',
|
135
|
+
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 : '"'
|
136
|
+
});
|
137
|
+
this.handlers.set(ValueList.kind, (expr) => this.visitValueList(expr));
|
138
|
+
this.handlers.set(ColumnReference.kind, (expr) => this.visitColumnReference(expr));
|
139
|
+
this.handlers.set(QualifiedName.kind, (expr) => this.visitQualifiedName(expr));
|
140
|
+
this.handlers.set(FunctionCall.kind, (expr) => this.visitFunctionCall(expr));
|
141
|
+
this.handlers.set(UnaryExpression.kind, (expr) => this.visitUnaryExpression(expr));
|
142
|
+
this.handlers.set(BinaryExpression.kind, (expr) => this.visitBinaryExpression(expr));
|
143
|
+
this.handlers.set(LiteralValue.kind, (expr) => this.visitLiteralValue(expr));
|
144
|
+
this.handlers.set(ParameterExpression.kind, (expr) => this.visitParameterExpression(expr));
|
145
|
+
this.handlers.set(SwitchCaseArgument.kind, (expr) => this.visitSwitchCaseArgument(expr));
|
146
|
+
this.handlers.set(CaseKeyValuePair.kind, (expr) => this.visitCaseKeyValuePair(expr));
|
147
|
+
this.handlers.set(RawString.kind, (expr) => this.visitRawString(expr));
|
148
|
+
this.handlers.set(IdentifierString.kind, (expr) => this.visitIdentifierString(expr));
|
149
|
+
this.handlers.set(ParenExpression.kind, (expr) => this.visitParenExpression(expr));
|
150
|
+
this.handlers.set(CastExpression.kind, (expr) => this.visitCastExpression(expr));
|
151
|
+
this.handlers.set(CaseExpression.kind, (expr) => this.visitCaseExpression(expr));
|
152
|
+
this.handlers.set(ArrayExpression.kind, (expr) => this.visitArrayExpression(expr));
|
153
|
+
this.handlers.set(BetweenExpression.kind, (expr) => this.visitBetweenExpression(expr));
|
154
|
+
this.handlers.set(StringSpecifierExpression.kind, (expr) => this.visitStringSpecifierExpression(expr));
|
155
|
+
this.handlers.set(TypeValue.kind, (expr) => this.visitTypeValue(expr));
|
156
|
+
this.handlers.set(TupleExpression.kind, (expr) => this.visitTupleExpression(expr));
|
157
|
+
this.handlers.set(InlineQuery.kind, (expr) => this.visitInlineQuery(expr));
|
158
|
+
this.handlers.set(WindowFrameExpression.kind, (expr) => this.visitWindowFrameExpression(expr));
|
159
|
+
this.handlers.set(WindowFrameSpec.kind, (expr) => this.visitWindowFrameSpec(expr));
|
160
|
+
this.handlers.set(WindowFrameBoundStatic.kind, (expr) => this.visitWindowFrameBoundStatic(expr));
|
161
|
+
this.handlers.set(WindowFrameBoundaryValue.kind, (expr) => this.visitWindowFrameBoundaryValue(expr));
|
162
|
+
this.handlers.set(PartitionByClause.kind, (expr) => this.visitPartitionByClause(expr));
|
163
|
+
this.handlers.set(OrderByClause.kind, (expr) => this.visitOrderByClause(expr));
|
164
|
+
this.handlers.set(OrderByItem.kind, (expr) => this.visitOrderByItem(expr));
|
165
|
+
// select
|
166
|
+
this.handlers.set(SelectItem.kind, (expr) => this.visitSelectItem(expr));
|
167
|
+
this.handlers.set(SelectClause.kind, (expr) => this.visitSelectClause(expr));
|
168
|
+
this.handlers.set(Distinct.kind, (expr) => this.visitDistinct(expr));
|
169
|
+
this.handlers.set(DistinctOn.kind, (expr) => this.visitDistinctOn(expr));
|
170
|
+
// from
|
171
|
+
this.handlers.set(TableSource.kind, (expr) => this.visitTableSource(expr));
|
172
|
+
this.handlers.set(FunctionSource.kind, (expr) => this.visitFunctionSource(expr));
|
173
|
+
this.handlers.set(SourceExpression.kind, (expr) => this.visitSourceExpression(expr));
|
174
|
+
this.handlers.set(SourceAliasExpression.kind, (expr) => this.visitSourceAliasExpression(expr));
|
175
|
+
this.handlers.set(FromClause.kind, (expr) => this.visitFromClause(expr));
|
176
|
+
this.handlers.set(JoinClause.kind, (expr) => this.visitJoinClause(expr));
|
177
|
+
this.handlers.set(JoinOnClause.kind, (expr) => this.visitJoinOnClause(expr));
|
178
|
+
this.handlers.set(JoinUsingClause.kind, (expr) => this.visitJoinUsingClause(expr));
|
179
|
+
// where
|
180
|
+
this.handlers.set(WhereClause.kind, (expr) => this.visitWhereClause(expr));
|
181
|
+
// group
|
182
|
+
this.handlers.set(GroupByClause.kind, (expr) => this.visitGroupByClause(expr));
|
183
|
+
this.handlers.set(HavingClause.kind, (expr) => this.visitHavingClause(expr));
|
184
|
+
this.handlers.set(WindowClause.kind, (expr) => this.visitWindowClause(expr));
|
185
|
+
this.handlers.set(WindowFrameClause.kind, (expr) => this.visitWindowFrameClause(expr));
|
186
|
+
this.handlers.set(LimitClause.kind, (expr) => this.visitLimitClause(expr));
|
187
|
+
this.handlers.set(OffsetClause.kind, (expr) => this.visitOffsetClause(expr));
|
188
|
+
this.handlers.set(FetchClause.kind, (expr) => this.visitFetchClause(expr));
|
189
|
+
this.handlers.set(FetchExpression.kind, (expr) => this.visitFetchExpression(expr));
|
190
|
+
this.handlers.set(ForClause.kind, (expr) => this.visitForClause(expr));
|
191
|
+
// With
|
192
|
+
this.handlers.set(WithClause.kind, (expr) => this.visitWithClause(expr));
|
193
|
+
this.handlers.set(CommonTable.kind, (expr) => this.visitCommonTable(expr));
|
194
|
+
// Query
|
195
|
+
this.handlers.set(SimpleSelectQuery.kind, (expr) => this.visitSimpleQuery(expr));
|
196
|
+
this.handlers.set(SubQuerySource.kind, (expr) => this.visitSubQuerySource(expr));
|
197
|
+
this.handlers.set(BinarySelectQuery.kind, (expr) => this.visitBinarySelectQuery(expr));
|
198
|
+
this.handlers.set(ValuesQuery.kind, (expr) => this.visitValuesQuery(expr));
|
199
|
+
this.handlers.set(TupleExpression.kind, (expr) => this.visitTupleExpression(expr));
|
200
|
+
this.handlers.set(InsertQuery.kind, (expr) => this.visitInsertQuery(expr));
|
201
|
+
this.handlers.set(InsertClause.kind, (expr) => this.visitInsertClause(expr));
|
202
|
+
this.handlers.set(UpdateQuery.kind, (expr) => this.visitUpdateQuery(expr));
|
203
|
+
this.handlers.set(UpdateClause.kind, (expr) => this.visitUpdateClause(expr));
|
204
|
+
this.handlers.set(SetClause.kind, (expr) => this.visitSetClause(expr));
|
205
|
+
this.handlers.set(SetClauseItem.kind, (expr) => this.visitSetClauseItem(expr));
|
206
|
+
this.handlers.set(ReturningClause.kind, (expr) => this.visitReturningClause(expr));
|
207
|
+
this.handlers.set(CreateTableQuery.kind, (expr) => this.visitCreateTableQuery(expr));
|
208
|
+
}
|
209
|
+
/**
|
210
|
+
* Pretty-prints a BinarySelectQuery (e.g., UNION, INTERSECT, EXCEPT).
|
211
|
+
* This will recursively print left and right queries, separated by the operator.
|
212
|
+
* @param arg BinarySelectQuery
|
213
|
+
*/
|
214
|
+
visitBinarySelectQuery(arg) {
|
215
|
+
const token = new SqlPrintToken(SqlPrintTokenType.container, '');
|
216
|
+
token.innerTokens.push(this.visit(arg.left));
|
217
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
218
|
+
token.innerTokens.push(new SqlPrintToken(SqlPrintTokenType.keyword, arg.operator.value, SqlPrintTokenContainerType.BinarySelectQueryOperator));
|
219
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
220
|
+
token.innerTokens.push(this.visit(arg.right));
|
221
|
+
return token;
|
222
|
+
}
|
223
|
+
/**
|
224
|
+
* Returns an array of tokens representing a comma followed by a space.
|
225
|
+
* This is a common pattern in SQL pretty-printing.
|
226
|
+
*/
|
227
|
+
static commaSpaceTokens() {
|
228
|
+
return [SqlPrintTokenParser.COMMA_TOKEN, SqlPrintTokenParser.SPACE_TOKEN];
|
229
|
+
}
|
230
|
+
static argumentCommaSpaceTokens() {
|
231
|
+
return [SqlPrintTokenParser.ARGUMENT_SPLIT_COMMA_TOKEN, SqlPrintTokenParser.SPACE_TOKEN];
|
232
|
+
}
|
233
|
+
visitQualifiedName(arg) {
|
234
|
+
const token = new SqlPrintToken(SqlPrintTokenType.container, '', SqlPrintTokenContainerType.QualifiedName);
|
235
|
+
if (arg.namespaces) {
|
236
|
+
for (let i = 0; i < arg.namespaces.length; i++) {
|
237
|
+
token.innerTokens.push(arg.namespaces[i].accept(this));
|
238
|
+
token.innerTokens.push(SqlPrintTokenParser.DOT_TOKEN);
|
239
|
+
}
|
240
|
+
}
|
241
|
+
token.innerTokens.push(arg.name.accept(this));
|
242
|
+
return token;
|
243
|
+
}
|
244
|
+
visitPartitionByClause(arg) {
|
245
|
+
// Print as: partition by ...
|
246
|
+
const token = new SqlPrintToken(SqlPrintTokenType.keyword, 'partition by', SqlPrintTokenContainerType.PartitionByClause);
|
247
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
248
|
+
token.innerTokens.push(this.visit(arg.value));
|
249
|
+
return token;
|
250
|
+
}
|
251
|
+
visitOrderByClause(arg) {
|
252
|
+
// Print as: order by ...
|
253
|
+
const token = new SqlPrintToken(SqlPrintTokenType.keyword, 'order by', SqlPrintTokenContainerType.OrderByClause);
|
254
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
255
|
+
for (let i = 0; i < arg.order.length; i++) {
|
256
|
+
if (i > 0)
|
257
|
+
token.innerTokens.push(...SqlPrintTokenParser.commaSpaceTokens());
|
258
|
+
token.innerTokens.push(this.visit(arg.order[i]));
|
259
|
+
}
|
260
|
+
return token;
|
261
|
+
}
|
262
|
+
/**
|
263
|
+
* Print an OrderByItem (expression [asc|desc] [nulls first|last])
|
264
|
+
*/
|
265
|
+
visitOrderByItem(arg) {
|
266
|
+
// arg: OrderByItem
|
267
|
+
const token = new SqlPrintToken(SqlPrintTokenType.container, '', SqlPrintTokenContainerType.OrderByItem);
|
268
|
+
token.innerTokens.push(this.visit(arg.value));
|
269
|
+
if (arg.sortDirection && arg.sortDirection !== SortDirection.Ascending) {
|
270
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
271
|
+
token.innerTokens.push(new SqlPrintToken(SqlPrintTokenType.keyword, 'desc'));
|
272
|
+
}
|
273
|
+
if (arg.nullsPosition) {
|
274
|
+
if (arg.nullsPosition === NullsSortDirection.First) {
|
275
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
276
|
+
token.innerTokens.push(new SqlPrintToken(SqlPrintTokenType.keyword, 'nulls first'));
|
277
|
+
}
|
278
|
+
else if (arg.nullsPosition === NullsSortDirection.Last) {
|
279
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
280
|
+
token.innerTokens.push(new SqlPrintToken(SqlPrintTokenType.keyword, 'nulls last'));
|
281
|
+
}
|
282
|
+
}
|
283
|
+
return token;
|
284
|
+
}
|
285
|
+
parse(arg) {
|
286
|
+
const token = this.visit(arg);
|
287
|
+
const paramsRaw = ParameterCollector.collect(arg).sort((a, b) => { var _a, _b; return ((_a = a.index) !== null && _a !== void 0 ? _a : 0) - ((_b = b.index) !== null && _b !== void 0 ? _b : 0); });
|
288
|
+
const style = this.parameterDecorator.style;
|
289
|
+
if (style === ParameterStyle.Named) {
|
290
|
+
// Named: { name: value, ... }
|
291
|
+
const paramsObj = {};
|
292
|
+
for (const p of paramsRaw) {
|
293
|
+
const key = p.name.value;
|
294
|
+
if (paramsObj.hasOwnProperty(key)) {
|
295
|
+
if (paramsObj[key] !== p.value) {
|
296
|
+
throw new Error(`Duplicate parameter name '${key}' with different values detected during query composition.`);
|
297
|
+
}
|
298
|
+
// If value is the same, skip (already set)
|
299
|
+
continue;
|
300
|
+
}
|
301
|
+
paramsObj[key] = p.value;
|
302
|
+
}
|
303
|
+
return { token, params: paramsObj };
|
304
|
+
}
|
305
|
+
else if (style === ParameterStyle.Indexed) {
|
306
|
+
// Indexed: [value1, value2, ...] (sorted by index)
|
307
|
+
const paramsArr = paramsRaw.map(p => p.value);
|
308
|
+
return { token, params: paramsArr };
|
309
|
+
}
|
310
|
+
else if (style === ParameterStyle.Anonymous) {
|
311
|
+
// Anonymous: [value1, value2, ...] (sorted by index, name is empty)
|
312
|
+
const paramsArr = paramsRaw.map(p => p.value);
|
313
|
+
return { token, params: paramsArr };
|
314
|
+
}
|
315
|
+
// Fallback (just in case)
|
316
|
+
return { token, params: [] };
|
317
|
+
}
|
318
|
+
visit(arg) {
|
319
|
+
const handler = this.handlers.get(arg.getKind());
|
320
|
+
if (handler) {
|
321
|
+
return handler(arg);
|
322
|
+
}
|
323
|
+
throw new Error(`[SqlPrintTokenParser] No handler for kind: ${arg.getKind().toString()}`);
|
324
|
+
}
|
325
|
+
visitValueList(arg) {
|
326
|
+
const token = new SqlPrintToken(SqlPrintTokenType.container, '', SqlPrintTokenContainerType.ValueList);
|
327
|
+
for (let i = 0; i < arg.values.length; i++) {
|
328
|
+
if (i > 0) {
|
329
|
+
token.innerTokens.push(...SqlPrintTokenParser.argumentCommaSpaceTokens());
|
330
|
+
}
|
331
|
+
token.innerTokens.push(this.visit(arg.values[i]));
|
332
|
+
}
|
333
|
+
return token;
|
334
|
+
}
|
335
|
+
visitColumnReference(arg) {
|
336
|
+
const token = new SqlPrintToken(SqlPrintTokenType.container, '', SqlPrintTokenContainerType.ColumnReference);
|
337
|
+
token.innerTokens.push(arg.qualifiedName.accept(this));
|
338
|
+
return token;
|
339
|
+
}
|
340
|
+
visitFunctionCall(arg) {
|
341
|
+
const token = new SqlPrintToken(SqlPrintTokenType.container, '', SqlPrintTokenContainerType.FunctionCall);
|
342
|
+
token.innerTokens.push(arg.qualifiedName.accept(this));
|
343
|
+
token.innerTokens.push(SqlPrintTokenParser.PAREN_OPEN_TOKEN);
|
344
|
+
if (arg.argument) {
|
345
|
+
token.innerTokens.push(this.visit(arg.argument));
|
346
|
+
}
|
347
|
+
token.innerTokens.push(SqlPrintTokenParser.PAREN_CLOSE_TOKEN);
|
348
|
+
if (arg.over) {
|
349
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
350
|
+
token.innerTokens.push(new SqlPrintToken(SqlPrintTokenType.keyword, 'over'));
|
351
|
+
if (arg.over instanceof IdentifierString) {
|
352
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
353
|
+
token.innerTokens.push(arg.over.accept(this));
|
354
|
+
}
|
355
|
+
else {
|
356
|
+
token.innerTokens.push(SqlPrintTokenParser.PAREN_OPEN_TOKEN);
|
357
|
+
token.innerTokens.push(this.visit(arg.over));
|
358
|
+
token.innerTokens.push(SqlPrintTokenParser.PAREN_CLOSE_TOKEN);
|
359
|
+
}
|
360
|
+
}
|
361
|
+
return token;
|
362
|
+
}
|
363
|
+
visitUnaryExpression(arg) {
|
364
|
+
const token = new SqlPrintToken(SqlPrintTokenType.container, '', SqlPrintTokenContainerType.UnaryExpression);
|
365
|
+
token.innerTokens.push(this.visit(arg.operator));
|
366
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
367
|
+
token.innerTokens.push(this.visit(arg.expression));
|
368
|
+
return token;
|
369
|
+
}
|
370
|
+
visitBinaryExpression(arg) {
|
371
|
+
const token = new SqlPrintToken(SqlPrintTokenType.container, '', SqlPrintTokenContainerType.BinaryExpression);
|
372
|
+
token.innerTokens.push(this.visit(arg.left));
|
373
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
374
|
+
token.innerTokens.push(new SqlPrintToken(SqlPrintTokenType.operator, arg.operator.value));
|
375
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
376
|
+
token.innerTokens.push(this.visit(arg.right));
|
377
|
+
return token;
|
378
|
+
}
|
379
|
+
visitLiteralValue(arg) {
|
380
|
+
let text;
|
381
|
+
if (typeof arg.value === "string") {
|
382
|
+
text = `'${arg.value.replace(/'/g, "''")}'`;
|
383
|
+
}
|
384
|
+
else if (arg.value === null) {
|
385
|
+
text = "null";
|
386
|
+
}
|
387
|
+
else {
|
388
|
+
text = arg.value.toString();
|
389
|
+
}
|
390
|
+
return new SqlPrintToken(SqlPrintTokenType.value, text, SqlPrintTokenContainerType.LiteralValue);
|
391
|
+
}
|
392
|
+
visitParameterExpression(arg) {
|
393
|
+
// Create a parameter token and decorate it using the parameterDecorator
|
394
|
+
arg.index = this.index;
|
395
|
+
const text = this.parameterDecorator.decorate(arg.name.value, arg.index);
|
396
|
+
const token = new SqlPrintToken(SqlPrintTokenType.parameter, text);
|
397
|
+
this.index++;
|
398
|
+
return token;
|
399
|
+
}
|
400
|
+
visitSwitchCaseArgument(arg) {
|
401
|
+
const token = new SqlPrintToken(SqlPrintTokenType.container, '', SqlPrintTokenContainerType.SwitchCaseArgument);
|
402
|
+
for (const kv of arg.cases) {
|
403
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
404
|
+
token.innerTokens.push(kv.accept(this));
|
405
|
+
}
|
406
|
+
if (arg.elseValue) {
|
407
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
408
|
+
token.innerTokens.push(this.createElseToken(arg.elseValue));
|
409
|
+
}
|
410
|
+
return token;
|
411
|
+
}
|
412
|
+
createElseToken(elseValue) {
|
413
|
+
// Creates a token for the ELSE clause in a CASE expression.
|
414
|
+
const elseToken = new SqlPrintToken(SqlPrintTokenType.container, '', SqlPrintTokenContainerType.ElseClause);
|
415
|
+
elseToken.innerTokens.push(new SqlPrintToken(SqlPrintTokenType.keyword, 'else'));
|
416
|
+
elseToken.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
417
|
+
elseToken.innerTokens.push(this.visit(elseValue));
|
418
|
+
return elseToken;
|
419
|
+
}
|
420
|
+
visitCaseKeyValuePair(arg) {
|
421
|
+
const token = new SqlPrintToken(SqlPrintTokenType.container, '', SqlPrintTokenContainerType.CaseKeyValuePair);
|
422
|
+
token.innerTokens.push(new SqlPrintToken(SqlPrintTokenType.keyword, 'when'));
|
423
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
424
|
+
token.innerTokens.push(this.visit(arg.key));
|
425
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
426
|
+
token.innerTokens.push(new SqlPrintToken(SqlPrintTokenType.keyword, 'then'));
|
427
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
428
|
+
token.innerTokens.push(this.visit(arg.value));
|
429
|
+
return token;
|
430
|
+
}
|
431
|
+
visitRawString(arg) {
|
432
|
+
// Even for non-container tokens, set the container type for context
|
433
|
+
return new SqlPrintToken(SqlPrintTokenType.value, arg.value, SqlPrintTokenContainerType.RawString);
|
434
|
+
}
|
435
|
+
visitIdentifierString(arg) {
|
436
|
+
// Create an identifier token and decorate it using the identifierDecorator
|
437
|
+
const text = arg.name === "*" ? arg.name : this.identifierDecorator.decorate(arg.name);
|
438
|
+
const token = new SqlPrintToken(SqlPrintTokenType.value, text, SqlPrintTokenContainerType.IdentifierString);
|
439
|
+
return token;
|
440
|
+
}
|
441
|
+
visitParenExpression(arg) {
|
442
|
+
const token = new SqlPrintToken(SqlPrintTokenType.container, '', SqlPrintTokenContainerType.ParenExpression);
|
443
|
+
token.innerTokens.push(SqlPrintTokenParser.PAREN_OPEN_TOKEN);
|
444
|
+
token.innerTokens.push(this.visit(arg.expression));
|
445
|
+
token.innerTokens.push(SqlPrintTokenParser.PAREN_CLOSE_TOKEN);
|
446
|
+
return token;
|
447
|
+
}
|
448
|
+
visitCastExpression(arg) {
|
449
|
+
const token = new SqlPrintToken(SqlPrintTokenType.container, '', SqlPrintTokenContainerType.CastExpression);
|
450
|
+
token.innerTokens.push(this.visit(arg.input));
|
451
|
+
token.innerTokens.push(new SqlPrintToken(SqlPrintTokenType.operator, '::'));
|
452
|
+
token.innerTokens.push(this.visit(arg.castType));
|
453
|
+
return token;
|
454
|
+
}
|
455
|
+
visitCaseExpression(arg) {
|
456
|
+
const token = new SqlPrintToken(SqlPrintTokenType.container, '', SqlPrintTokenContainerType.CaseExpression);
|
457
|
+
token.innerTokens.push(new SqlPrintToken(SqlPrintTokenType.keyword, 'case'));
|
458
|
+
if (arg.condition) {
|
459
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
460
|
+
token.innerTokens.push(this.visit(arg.condition));
|
461
|
+
}
|
462
|
+
token.innerTokens.push(this.visit(arg.switchCase));
|
463
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
464
|
+
token.innerTokens.push(new SqlPrintToken(SqlPrintTokenType.keyword, 'end'));
|
465
|
+
return token;
|
466
|
+
}
|
467
|
+
visitArrayExpression(arg) {
|
468
|
+
const token = new SqlPrintToken(SqlPrintTokenType.container, '', SqlPrintTokenContainerType.ArrayExpression);
|
469
|
+
token.innerTokens.push(new SqlPrintToken(SqlPrintTokenType.keyword, 'array'));
|
470
|
+
token.innerTokens.push(new SqlPrintToken(SqlPrintTokenType.parenthesis, '['));
|
471
|
+
token.innerTokens.push(this.visit(arg.expression));
|
472
|
+
token.innerTokens.push(new SqlPrintToken(SqlPrintTokenType.parenthesis, ']'));
|
473
|
+
return token;
|
474
|
+
}
|
475
|
+
visitBetweenExpression(arg) {
|
476
|
+
const token = new SqlPrintToken(SqlPrintTokenType.container, '', SqlPrintTokenContainerType.BetweenExpression);
|
477
|
+
token.innerTokens.push(this.visit(arg.expression));
|
478
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
479
|
+
if (arg.negated) {
|
480
|
+
token.innerTokens.push(new SqlPrintToken(SqlPrintTokenType.keyword, 'not'));
|
481
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
482
|
+
}
|
483
|
+
token.innerTokens.push(new SqlPrintToken(SqlPrintTokenType.keyword, 'between'));
|
484
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
485
|
+
token.innerTokens.push(this.visit(arg.lower));
|
486
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
487
|
+
token.innerTokens.push(new SqlPrintToken(SqlPrintTokenType.keyword, 'and'));
|
488
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
489
|
+
token.innerTokens.push(this.visit(arg.upper));
|
490
|
+
return token;
|
491
|
+
}
|
492
|
+
visitStringSpecifierExpression(arg) {
|
493
|
+
// Combine specifier and value into a single token
|
494
|
+
const specifier = arg.specifier.accept(this).text;
|
495
|
+
const value = arg.value.accept(this).text;
|
496
|
+
return new SqlPrintToken(SqlPrintTokenType.value, specifier + value, SqlPrintTokenContainerType.StringSpecifierExpression);
|
497
|
+
}
|
498
|
+
visitTypeValue(arg) {
|
499
|
+
const token = new SqlPrintToken(SqlPrintTokenType.container, '', SqlPrintTokenContainerType.TypeValue);
|
500
|
+
token.innerTokens.push(arg.qualifiedName.accept(this));
|
501
|
+
if (arg.argument) {
|
502
|
+
token.innerTokens.push(SqlPrintTokenParser.PAREN_OPEN_TOKEN);
|
503
|
+
token.innerTokens.push(this.visit(arg.argument));
|
504
|
+
token.innerTokens.push(SqlPrintTokenParser.PAREN_CLOSE_TOKEN);
|
505
|
+
}
|
506
|
+
return token;
|
507
|
+
}
|
508
|
+
visitTupleExpression(arg) {
|
509
|
+
const token = new SqlPrintToken(SqlPrintTokenType.container, '', SqlPrintTokenContainerType.TupleExpression);
|
510
|
+
token.innerTokens.push(SqlPrintTokenParser.PAREN_OPEN_TOKEN);
|
511
|
+
for (let i = 0; i < arg.values.length; i++) {
|
512
|
+
if (i > 0) {
|
513
|
+
token.innerTokens.push(...SqlPrintTokenParser.argumentCommaSpaceTokens());
|
514
|
+
}
|
515
|
+
token.innerTokens.push(this.visit(arg.values[i]));
|
516
|
+
}
|
517
|
+
token.innerTokens.push(SqlPrintTokenParser.PAREN_CLOSE_TOKEN);
|
518
|
+
return token;
|
519
|
+
}
|
520
|
+
visitWindowFrameExpression(arg) {
|
521
|
+
// Compose window frame expression: over(partition by ... order by ... rows ...)
|
522
|
+
const token = new SqlPrintToken(SqlPrintTokenType.container, '', SqlPrintTokenContainerType.WindowFrameExpression);
|
523
|
+
let first = true;
|
524
|
+
if (arg.partition) {
|
525
|
+
token.innerTokens.push(this.visit(arg.partition));
|
526
|
+
first = false;
|
527
|
+
}
|
528
|
+
if (arg.order) {
|
529
|
+
if (!first) {
|
530
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
531
|
+
}
|
532
|
+
else {
|
533
|
+
first = false;
|
534
|
+
}
|
535
|
+
token.innerTokens.push(this.visit(arg.order));
|
536
|
+
}
|
537
|
+
if (arg.frameSpec) {
|
538
|
+
if (!first) {
|
539
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
540
|
+
}
|
541
|
+
else {
|
542
|
+
first = false;
|
543
|
+
}
|
544
|
+
token.innerTokens.push(this.visit(arg.frameSpec));
|
545
|
+
}
|
546
|
+
return token;
|
547
|
+
}
|
548
|
+
visitWindowFrameSpec(arg) {
|
549
|
+
// This method prints a window frame specification, such as "rows between ... and ..." or "range ...".
|
550
|
+
const token = new SqlPrintToken(SqlPrintTokenType.container, '', SqlPrintTokenContainerType.WindowFrameSpec);
|
551
|
+
// Add frame type (e.g., "rows", "range", "groups")
|
552
|
+
token.innerTokens.push(new SqlPrintToken(SqlPrintTokenType.keyword, arg.frameType));
|
553
|
+
if (arg.endBound === null) {
|
554
|
+
// Only start bound: e.g., "rows unbounded preceding"
|
555
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
556
|
+
token.innerTokens.push(arg.startBound.accept(this));
|
557
|
+
}
|
558
|
+
else {
|
559
|
+
// Between: e.g., "rows between unbounded preceding and current row"
|
560
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
561
|
+
token.innerTokens.push(new SqlPrintToken(SqlPrintTokenType.keyword, 'between'));
|
562
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
563
|
+
token.innerTokens.push(arg.startBound.accept(this));
|
564
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
565
|
+
token.innerTokens.push(new SqlPrintToken(SqlPrintTokenType.keyword, 'and'));
|
566
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
567
|
+
token.innerTokens.push(arg.endBound.accept(this));
|
568
|
+
}
|
569
|
+
return token;
|
570
|
+
}
|
571
|
+
/**
|
572
|
+
* Prints a window frame boundary value, such as "5 preceding" or "3 following".
|
573
|
+
* @param arg WindowFrameBoundaryValue
|
574
|
+
*/
|
575
|
+
visitWindowFrameBoundaryValue(arg) {
|
576
|
+
const token = new SqlPrintToken(SqlPrintTokenType.container, '', SqlPrintTokenContainerType.WindowFrameBoundaryValue);
|
577
|
+
token.innerTokens.push(arg.value.accept(this));
|
578
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
579
|
+
// true for "FOLLOWING", false for "PRECEDING"
|
580
|
+
token.innerTokens.push(new SqlPrintToken(SqlPrintTokenType.keyword, arg.isFollowing ? 'following' : 'preceding'));
|
581
|
+
return token;
|
582
|
+
}
|
583
|
+
/**
|
584
|
+
* Prints a static window frame bound, such as "unbounded preceding", "current row", or "unbounded following".
|
585
|
+
* @param arg WindowFrameBoundStatic
|
586
|
+
*/
|
587
|
+
visitWindowFrameBoundStatic(arg) {
|
588
|
+
const token = new SqlPrintToken(SqlPrintTokenType.keyword, arg.bound);
|
589
|
+
return token;
|
590
|
+
}
|
591
|
+
visitSelectItem(arg) {
|
592
|
+
const token = new SqlPrintToken(SqlPrintTokenType.container, '', SqlPrintTokenContainerType.SelectItem);
|
593
|
+
token.innerTokens.push(this.visit(arg.value));
|
594
|
+
if (!arg.identifier) {
|
595
|
+
return token;
|
596
|
+
}
|
597
|
+
// No alias needed if it matches the default name
|
598
|
+
if (arg.value instanceof ColumnReference) {
|
599
|
+
const defaultName = arg.value.column.name;
|
600
|
+
if (arg.identifier.name === defaultName) {
|
601
|
+
return token;
|
602
|
+
}
|
603
|
+
}
|
604
|
+
// Add alias if it is different from the default name
|
605
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
606
|
+
token.innerTokens.push(new SqlPrintToken(SqlPrintTokenType.keyword, 'as'));
|
607
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
608
|
+
token.innerTokens.push(this.visit(arg.identifier));
|
609
|
+
return token;
|
610
|
+
}
|
611
|
+
visitSelectClause(arg) {
|
612
|
+
const token = new SqlPrintToken(SqlPrintTokenType.keyword, 'select', SqlPrintTokenContainerType.SelectClause);
|
613
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
614
|
+
if (arg.distinct) {
|
615
|
+
token.keywordTokens = [];
|
616
|
+
token.keywordTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
617
|
+
token.keywordTokens.push(arg.distinct.accept(this));
|
618
|
+
}
|
619
|
+
for (let i = 0; i < arg.items.length; i++) {
|
620
|
+
if (i > 0) {
|
621
|
+
token.innerTokens.push(...SqlPrintTokenParser.commaSpaceTokens());
|
622
|
+
}
|
623
|
+
token.innerTokens.push(this.visit(arg.items[i]));
|
624
|
+
}
|
625
|
+
return token;
|
626
|
+
}
|
627
|
+
visitDistinct(arg) {
|
628
|
+
const token = new SqlPrintToken(SqlPrintTokenType.keyword, 'distinct');
|
629
|
+
return token;
|
630
|
+
}
|
631
|
+
visitDistinctOn(arg) {
|
632
|
+
const token = new SqlPrintToken(SqlPrintTokenType.container, '', SqlPrintTokenContainerType.DistinctOn);
|
633
|
+
token.innerTokens.push(new SqlPrintToken(SqlPrintTokenType.keyword, 'distinct on'));
|
634
|
+
token.innerTokens.push(SqlPrintTokenParser.PAREN_OPEN_TOKEN);
|
635
|
+
token.innerTokens.push(arg.value.accept(this));
|
636
|
+
token.innerTokens.push(SqlPrintTokenParser.PAREN_CLOSE_TOKEN);
|
637
|
+
return token;
|
638
|
+
}
|
639
|
+
visitTableSource(arg) {
|
640
|
+
// Print table name with optional namespaces and alias
|
641
|
+
let fullName = '';
|
642
|
+
if (Array.isArray(arg.namespaces) && arg.namespaces.length > 0) {
|
643
|
+
fullName = arg.namespaces.map(ns => ns.accept(this).text).join('.') + '.';
|
644
|
+
}
|
645
|
+
fullName += arg.table.accept(this).text;
|
646
|
+
const token = new SqlPrintToken(SqlPrintTokenType.value, fullName);
|
647
|
+
// alias (if present and different from table name)
|
648
|
+
if (arg.identifier && arg.identifier.name !== arg.table.name) {
|
649
|
+
}
|
650
|
+
return token;
|
651
|
+
}
|
652
|
+
visitSourceExpression(arg) {
|
653
|
+
// Print source expression (e.g. "table", "table as t", "schema.table t")
|
654
|
+
const token = new SqlPrintToken(SqlPrintTokenType.container, '', SqlPrintTokenContainerType.SourceExpression);
|
655
|
+
token.innerTokens.push(arg.datasource.accept(this));
|
656
|
+
if (!arg.aliasExpression) {
|
657
|
+
return token;
|
658
|
+
}
|
659
|
+
if (arg.datasource instanceof TableSource) {
|
660
|
+
// No alias needed if it matches the default name
|
661
|
+
const defaultName = arg.datasource.table.name;
|
662
|
+
if (arg.aliasExpression.table.name === defaultName) {
|
663
|
+
return token;
|
664
|
+
}
|
665
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
666
|
+
token.innerTokens.push(new SqlPrintToken(SqlPrintTokenType.keyword, 'as'));
|
667
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
668
|
+
// exclude column aliases
|
669
|
+
token.innerTokens.push(arg.aliasExpression.accept(this));
|
670
|
+
return token;
|
671
|
+
}
|
672
|
+
else {
|
673
|
+
// For other source types, just print the alias
|
674
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
675
|
+
token.innerTokens.push(new SqlPrintToken(SqlPrintTokenType.keyword, 'as'));
|
676
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
677
|
+
// included column aliases
|
678
|
+
token.innerTokens.push(arg.aliasExpression.accept(this));
|
679
|
+
return token;
|
680
|
+
}
|
681
|
+
}
|
682
|
+
visitFromClause(arg) {
|
683
|
+
const token = new SqlPrintToken(SqlPrintTokenType.keyword, 'from', SqlPrintTokenContainerType.FromClause);
|
684
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
685
|
+
token.innerTokens.push(this.visit(arg.source));
|
686
|
+
if (arg.joins) {
|
687
|
+
for (let i = 0; i < arg.joins.length; i++) {
|
688
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
689
|
+
token.innerTokens.push(this.visit(arg.joins[i]));
|
690
|
+
}
|
691
|
+
}
|
692
|
+
return token;
|
693
|
+
}
|
694
|
+
visitJoinClause(arg) {
|
695
|
+
// Print join clause: [joinType] [lateral] [source] [on/using ...]
|
696
|
+
const token = new SqlPrintToken(SqlPrintTokenType.container, '', SqlPrintTokenContainerType.JoinClause);
|
697
|
+
// join type (e.g. inner join, left join, etc)
|
698
|
+
token.innerTokens.push(new SqlPrintToken(SqlPrintTokenType.keyword, arg.joinType.value));
|
699
|
+
if (arg.lateral) {
|
700
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
701
|
+
token.innerTokens.push(new SqlPrintToken(SqlPrintTokenType.keyword, 'lateral'));
|
702
|
+
}
|
703
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
704
|
+
token.innerTokens.push(this.visit(arg.source));
|
705
|
+
if (arg.condition) {
|
706
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
707
|
+
token.innerTokens.push(this.visit(arg.condition));
|
708
|
+
}
|
709
|
+
return token;
|
710
|
+
}
|
711
|
+
visitJoinOnClause(arg) {
|
712
|
+
const token = new SqlPrintToken(SqlPrintTokenType.container, '', SqlPrintTokenContainerType.JoinOnClause);
|
713
|
+
token.innerTokens.push(new SqlPrintToken(SqlPrintTokenType.keyword, 'on'));
|
714
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
715
|
+
token.innerTokens.push(this.visit(arg.condition));
|
716
|
+
return token;
|
717
|
+
}
|
718
|
+
visitJoinUsingClause(arg) {
|
719
|
+
const token = new SqlPrintToken(SqlPrintTokenType.container, '', SqlPrintTokenContainerType.JoinUsingClause);
|
720
|
+
token.innerTokens.push(new SqlPrintToken(SqlPrintTokenType.keyword, 'using'));
|
721
|
+
token.innerTokens.push(SqlPrintTokenParser.PAREN_OPEN_TOKEN);
|
722
|
+
token.innerTokens.push(this.visit(arg.condition));
|
723
|
+
token.innerTokens.push(SqlPrintTokenParser.PAREN_CLOSE_TOKEN);
|
724
|
+
return token;
|
725
|
+
}
|
726
|
+
visitFunctionSource(arg) {
|
727
|
+
// Print function source: [functionName]([args])
|
728
|
+
const token = new SqlPrintToken(SqlPrintTokenType.container, '', SqlPrintTokenContainerType.FunctionSource);
|
729
|
+
token.innerTokens.push(arg.qualifiedName.accept(this));
|
730
|
+
token.innerTokens.push(SqlPrintTokenParser.PAREN_OPEN_TOKEN);
|
731
|
+
if (arg.argument) {
|
732
|
+
token.innerTokens.push(this.visit(arg.argument));
|
733
|
+
}
|
734
|
+
token.innerTokens.push(SqlPrintTokenParser.PAREN_CLOSE_TOKEN);
|
735
|
+
return token;
|
736
|
+
}
|
737
|
+
visitSourceAliasExpression(arg) {
|
738
|
+
// Print source alias expression: [source] as [alias]
|
739
|
+
const token = new SqlPrintToken(SqlPrintTokenType.container, '', SqlPrintTokenContainerType.SourceAliasExpression);
|
740
|
+
token.innerTokens.push(this.visit(arg.table));
|
741
|
+
if (arg.columns) {
|
742
|
+
token.innerTokens.push(SqlPrintTokenParser.PAREN_OPEN_TOKEN);
|
743
|
+
for (let i = 0; i < arg.columns.length; i++) {
|
744
|
+
if (i > 0) {
|
745
|
+
token.innerTokens.push(...SqlPrintTokenParser.argumentCommaSpaceTokens());
|
746
|
+
}
|
747
|
+
token.innerTokens.push(this.visit(arg.columns[i]));
|
748
|
+
}
|
749
|
+
token.innerTokens.push(SqlPrintTokenParser.PAREN_CLOSE_TOKEN);
|
750
|
+
}
|
751
|
+
return token;
|
752
|
+
}
|
753
|
+
visitWhereClause(arg) {
|
754
|
+
const token = new SqlPrintToken(SqlPrintTokenType.keyword, 'where', SqlPrintTokenContainerType.WhereClause);
|
755
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
756
|
+
token.innerTokens.push(this.visit(arg.condition));
|
757
|
+
return token;
|
758
|
+
}
|
759
|
+
visitGroupByClause(arg) {
|
760
|
+
const token = new SqlPrintToken(SqlPrintTokenType.keyword, 'group by', SqlPrintTokenContainerType.GroupByClause);
|
761
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
762
|
+
for (let i = 0; i < arg.grouping.length; i++) {
|
763
|
+
if (i > 0) {
|
764
|
+
token.innerTokens.push(...SqlPrintTokenParser.commaSpaceTokens());
|
765
|
+
}
|
766
|
+
token.innerTokens.push(this.visit(arg.grouping[i]));
|
767
|
+
}
|
768
|
+
return token;
|
769
|
+
}
|
770
|
+
visitHavingClause(arg) {
|
771
|
+
const token = new SqlPrintToken(SqlPrintTokenType.keyword, 'having', SqlPrintTokenContainerType.HavingClause);
|
772
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
773
|
+
token.innerTokens.push(this.visit(arg.condition));
|
774
|
+
return token;
|
775
|
+
}
|
776
|
+
visitWindowClause(arg) {
|
777
|
+
const token = new SqlPrintToken(SqlPrintTokenType.keyword, 'window', SqlPrintTokenContainerType.WindowClause);
|
778
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
779
|
+
for (let i = 0; i < arg.windows.length; i++) {
|
780
|
+
if (i > 0) {
|
781
|
+
token.innerTokens.push(...SqlPrintTokenParser.commaSpaceTokens());
|
782
|
+
}
|
783
|
+
token.innerTokens.push(this.visit(arg.windows[i]));
|
784
|
+
}
|
785
|
+
return token;
|
786
|
+
}
|
787
|
+
visitWindowFrameClause(arg) {
|
788
|
+
const token = new SqlPrintToken(SqlPrintTokenType.container, '', SqlPrintTokenContainerType.WindowFrameClause);
|
789
|
+
token.innerTokens.push(arg.name.accept(this));
|
790
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
791
|
+
token.innerTokens.push(new SqlPrintToken(SqlPrintTokenType.keyword, 'as'));
|
792
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
793
|
+
token.innerTokens.push(SqlPrintTokenParser.PAREN_OPEN_TOKEN);
|
794
|
+
token.innerTokens.push(this.visit(arg.expression));
|
795
|
+
token.innerTokens.push(SqlPrintTokenParser.PAREN_CLOSE_TOKEN);
|
796
|
+
return token;
|
797
|
+
}
|
798
|
+
visitLimitClause(arg) {
|
799
|
+
const token = new SqlPrintToken(SqlPrintTokenType.keyword, 'limit', SqlPrintTokenContainerType.LimitClause);
|
800
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
801
|
+
token.innerTokens.push(this.visit(arg.value));
|
802
|
+
return token;
|
803
|
+
}
|
804
|
+
visitOffsetClause(arg) {
|
805
|
+
const token = new SqlPrintToken(SqlPrintTokenType.keyword, 'offset', SqlPrintTokenContainerType.OffsetClause);
|
806
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
807
|
+
token.innerTokens.push(this.visit(arg.value));
|
808
|
+
return token;
|
809
|
+
}
|
810
|
+
visitFetchClause(arg) {
|
811
|
+
const token = new SqlPrintToken(SqlPrintTokenType.keyword, 'fetch', SqlPrintTokenContainerType.FetchClause);
|
812
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
813
|
+
token.innerTokens.push(this.visit(arg.expression));
|
814
|
+
return token;
|
815
|
+
}
|
816
|
+
visitFetchExpression(arg) {
|
817
|
+
const token = new SqlPrintToken(SqlPrintTokenType.container, '', SqlPrintTokenContainerType.FetchExpression);
|
818
|
+
token.innerTokens.push(new SqlPrintToken(SqlPrintTokenType.keyword, arg.type));
|
819
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
820
|
+
token.innerTokens.push(arg.count.accept(this));
|
821
|
+
if (arg.unit) {
|
822
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
823
|
+
token.innerTokens.push(new SqlPrintToken(SqlPrintTokenType.keyword, arg.unit));
|
824
|
+
}
|
825
|
+
return token;
|
826
|
+
}
|
827
|
+
visitForClause(arg) {
|
828
|
+
const token = new SqlPrintToken(SqlPrintTokenType.keyword, 'for', SqlPrintTokenContainerType.ForClause);
|
829
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
830
|
+
token.innerTokens.push(new SqlPrintToken(SqlPrintTokenType.keyword, arg.lockMode));
|
831
|
+
return token;
|
832
|
+
}
|
833
|
+
visitWithClause(arg) {
|
834
|
+
const token = new SqlPrintToken(SqlPrintTokenType.keyword, 'with', SqlPrintTokenContainerType.WithClause);
|
835
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
836
|
+
if (arg.recursive) {
|
837
|
+
token.innerTokens.push(new SqlPrintToken(SqlPrintTokenType.keyword, 'recursive'));
|
838
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
839
|
+
}
|
840
|
+
for (let i = 0; i < arg.tables.length; i++) {
|
841
|
+
if (i > 0) {
|
842
|
+
token.innerTokens.push(...SqlPrintTokenParser.commaSpaceTokens());
|
843
|
+
}
|
844
|
+
token.innerTokens.push(arg.tables[i].accept(this));
|
845
|
+
}
|
846
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
847
|
+
return token;
|
848
|
+
}
|
849
|
+
visitCommonTable(arg) {
|
850
|
+
const token = new SqlPrintToken(SqlPrintTokenType.container, '', SqlPrintTokenContainerType.CommonTable);
|
851
|
+
token.innerTokens.push(arg.aliasExpression.accept(this));
|
852
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
853
|
+
token.innerTokens.push(new SqlPrintToken(SqlPrintTokenType.keyword, 'as'));
|
854
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
855
|
+
if (arg.materialized !== null) {
|
856
|
+
if (arg.materialized) {
|
857
|
+
token.innerTokens.push(new SqlPrintToken(SqlPrintTokenType.keyword, 'materialized'));
|
858
|
+
}
|
859
|
+
else {
|
860
|
+
token.innerTokens.push(new SqlPrintToken(SqlPrintTokenType.keyword, 'not materialized'));
|
861
|
+
}
|
862
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
863
|
+
}
|
864
|
+
token.innerTokens.push(SqlPrintTokenParser.PAREN_OPEN_TOKEN);
|
865
|
+
const query = new SqlPrintToken(SqlPrintTokenType.container, '', SqlPrintTokenContainerType.SubQuerySource);
|
866
|
+
query.innerTokens.push(arg.query.accept(this));
|
867
|
+
token.innerTokens.push(query);
|
868
|
+
token.innerTokens.push(SqlPrintTokenParser.PAREN_CLOSE_TOKEN);
|
869
|
+
return token;
|
870
|
+
}
|
871
|
+
// query
|
872
|
+
visitSimpleQuery(arg) {
|
873
|
+
const token = new SqlPrintToken(SqlPrintTokenType.container, '', SqlPrintTokenContainerType.SimpleSelectQuery);
|
874
|
+
if (arg.withClause) {
|
875
|
+
token.innerTokens.push(arg.withClause.accept(this));
|
876
|
+
}
|
877
|
+
token.innerTokens.push(arg.selectClause.accept(this));
|
878
|
+
if (!arg.fromClause) {
|
879
|
+
return token;
|
880
|
+
}
|
881
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
882
|
+
token.innerTokens.push(arg.fromClause.accept(this));
|
883
|
+
if (arg.whereClause) {
|
884
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
885
|
+
token.innerTokens.push(arg.whereClause.accept(this));
|
886
|
+
}
|
887
|
+
if (arg.groupByClause) {
|
888
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
889
|
+
token.innerTokens.push(arg.groupByClause.accept(this));
|
890
|
+
}
|
891
|
+
if (arg.havingClause) {
|
892
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
893
|
+
token.innerTokens.push(arg.havingClause.accept(this));
|
894
|
+
}
|
895
|
+
if (arg.orderByClause) {
|
896
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
897
|
+
token.innerTokens.push(arg.orderByClause.accept(this));
|
898
|
+
}
|
899
|
+
if (arg.windowClause) {
|
900
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
901
|
+
token.innerTokens.push(arg.windowClause.accept(this));
|
902
|
+
}
|
903
|
+
if (arg.limitClause) {
|
904
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
905
|
+
token.innerTokens.push(arg.limitClause.accept(this));
|
906
|
+
}
|
907
|
+
if (arg.offsetClause) {
|
908
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
909
|
+
token.innerTokens.push(arg.offsetClause.accept(this));
|
910
|
+
}
|
911
|
+
if (arg.fetchClause) {
|
912
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
913
|
+
token.innerTokens.push(arg.fetchClause.accept(this));
|
914
|
+
}
|
915
|
+
if (arg.forClause) {
|
916
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
917
|
+
token.innerTokens.push(arg.forClause.accept(this));
|
918
|
+
}
|
919
|
+
return token;
|
920
|
+
}
|
921
|
+
visitSubQuerySource(arg) {
|
922
|
+
const token = new SqlPrintToken(SqlPrintTokenType.container, '');
|
923
|
+
token.innerTokens.push(SqlPrintTokenParser.PAREN_OPEN_TOKEN);
|
924
|
+
const subQuery = new SqlPrintToken(SqlPrintTokenType.container, '', SqlPrintTokenContainerType.SubQuerySource);
|
925
|
+
subQuery.innerTokens.push(arg.query.accept(this));
|
926
|
+
token.innerTokens.push(subQuery);
|
927
|
+
token.innerTokens.push(SqlPrintTokenParser.PAREN_CLOSE_TOKEN);
|
928
|
+
return token;
|
929
|
+
}
|
930
|
+
visitValuesQuery(arg) {
|
931
|
+
const token = new SqlPrintToken(SqlPrintTokenType.keyword, 'values', SqlPrintTokenContainerType.ValuesQuery);
|
932
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
933
|
+
const values = new SqlPrintToken(SqlPrintTokenType.container, '', SqlPrintTokenContainerType.Values);
|
934
|
+
for (let i = 0; i < arg.tuples.length; i++) {
|
935
|
+
if (i > 0) {
|
936
|
+
values.innerTokens.push(...SqlPrintTokenParser.commaSpaceTokens());
|
937
|
+
}
|
938
|
+
values.innerTokens.push(arg.tuples[i].accept(this));
|
939
|
+
}
|
940
|
+
token.innerTokens.push(values);
|
941
|
+
return token;
|
942
|
+
}
|
943
|
+
visitInlineQuery(arg) {
|
944
|
+
const token = new SqlPrintToken(SqlPrintTokenType.container, '', SqlPrintTokenContainerType.InlineQuery);
|
945
|
+
token.innerTokens.push(SqlPrintTokenParser.PAREN_OPEN_TOKEN);
|
946
|
+
token.innerTokens.push(arg.selectQuery.accept(this));
|
947
|
+
token.innerTokens.push(SqlPrintTokenParser.PAREN_CLOSE_TOKEN);
|
948
|
+
return token;
|
949
|
+
}
|
950
|
+
visitInsertQuery(arg) {
|
951
|
+
const token = new SqlPrintToken(SqlPrintTokenType.container, '', SqlPrintTokenContainerType.InsertQuery);
|
952
|
+
// Process the insert clause
|
953
|
+
token.innerTokens.push(this.visit(arg.insertClause));
|
954
|
+
// Process the select query if present
|
955
|
+
if (arg.selectQuery) {
|
956
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
957
|
+
token.innerTokens.push(this.visit(arg.selectQuery));
|
958
|
+
}
|
959
|
+
return token;
|
960
|
+
}
|
961
|
+
visitInsertClause(arg) {
|
962
|
+
const token = new SqlPrintToken(SqlPrintTokenType.container, '');
|
963
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
964
|
+
token.innerTokens.push(new SqlPrintToken(SqlPrintTokenType.keyword, 'insert into'));
|
965
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
966
|
+
token.innerTokens.push(arg.source.accept(this));
|
967
|
+
if (arg.columns.length > 0) {
|
968
|
+
token.innerTokens.push(SqlPrintTokenParser.PAREN_OPEN_TOKEN);
|
969
|
+
for (let i = 0; i < arg.columns.length; i++) {
|
970
|
+
if (i > 0) {
|
971
|
+
token.innerTokens.push(...SqlPrintTokenParser.commaSpaceTokens());
|
972
|
+
}
|
973
|
+
token.innerTokens.push(arg.columns[i].accept(this));
|
974
|
+
}
|
975
|
+
token.innerTokens.push(SqlPrintTokenParser.PAREN_CLOSE_TOKEN);
|
976
|
+
}
|
977
|
+
return token;
|
978
|
+
}
|
979
|
+
visitUpdateQuery(arg) {
|
980
|
+
const token = new SqlPrintToken(SqlPrintTokenType.container, '', SqlPrintTokenContainerType.UpdateQuery);
|
981
|
+
if (arg.withClause) {
|
982
|
+
token.innerTokens.push(arg.withClause.accept(this));
|
983
|
+
}
|
984
|
+
token.innerTokens.push(arg.updateClause.accept(this));
|
985
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
986
|
+
token.innerTokens.push(arg.setClause.accept(this));
|
987
|
+
if (arg.fromClause) {
|
988
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
989
|
+
token.innerTokens.push(arg.fromClause.accept(this));
|
990
|
+
}
|
991
|
+
if (arg.whereClause) {
|
992
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
993
|
+
token.innerTokens.push(arg.whereClause.accept(this));
|
994
|
+
}
|
995
|
+
if (arg.returningClause) {
|
996
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
997
|
+
token.innerTokens.push(arg.returningClause.accept(this));
|
998
|
+
}
|
999
|
+
return token;
|
1000
|
+
}
|
1001
|
+
visitUpdateClause(arg) {
|
1002
|
+
const token = new SqlPrintToken(SqlPrintTokenType.keyword, 'update', SqlPrintTokenContainerType.UpdateClause);
|
1003
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
1004
|
+
token.innerTokens.push(arg.source.accept(this));
|
1005
|
+
return token;
|
1006
|
+
}
|
1007
|
+
visitSetClause(arg) {
|
1008
|
+
const token = new SqlPrintToken(SqlPrintTokenType.keyword, 'set', SqlPrintTokenContainerType.SelectClause);
|
1009
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
1010
|
+
for (let i = 0; i < arg.items.length; i++) {
|
1011
|
+
if (i > 0) {
|
1012
|
+
token.innerTokens.push(...SqlPrintTokenParser.commaSpaceTokens());
|
1013
|
+
}
|
1014
|
+
token.innerTokens.push(this.visit(arg.items[i]));
|
1015
|
+
}
|
1016
|
+
return token;
|
1017
|
+
}
|
1018
|
+
visitSetClauseItem(arg) {
|
1019
|
+
const token = new SqlPrintToken(SqlPrintTokenType.container, '', SqlPrintTokenContainerType.SetClauseItem);
|
1020
|
+
token.innerTokens.push(arg.column.accept(this));
|
1021
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
1022
|
+
token.innerTokens.push(new SqlPrintToken(SqlPrintTokenType.operator, '='));
|
1023
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
1024
|
+
token.innerTokens.push(arg.value.accept(this));
|
1025
|
+
return token;
|
1026
|
+
}
|
1027
|
+
visitReturningClause(arg) {
|
1028
|
+
const token = new SqlPrintToken(SqlPrintTokenType.keyword, 'returning', SqlPrintTokenContainerType.ReturningClause);
|
1029
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
1030
|
+
for (let i = 0; i < arg.columns.length; i++) {
|
1031
|
+
if (i > 0) {
|
1032
|
+
token.innerTokens.push(...SqlPrintTokenParser.commaSpaceTokens());
|
1033
|
+
}
|
1034
|
+
token.innerTokens.push(this.visit(arg.columns[i]));
|
1035
|
+
}
|
1036
|
+
return token;
|
1037
|
+
}
|
1038
|
+
visitCreateTableQuery(arg) {
|
1039
|
+
const token = new SqlPrintToken(SqlPrintTokenType.keyword, arg.isTemporary ? 'create temporary table' : 'create table', SqlPrintTokenContainerType.CreateTableQuery);
|
1040
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
1041
|
+
token.innerTokens.push(arg.tableName.accept(this));
|
1042
|
+
if (arg.asSelectQuery) {
|
1043
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
1044
|
+
token.innerTokens.push(new SqlPrintToken(SqlPrintTokenType.keyword, 'as'));
|
1045
|
+
token.innerTokens.push(SqlPrintTokenParser.SPACE_TOKEN);
|
1046
|
+
token.innerTokens.push(arg.asSelectQuery.accept(this));
|
1047
|
+
}
|
1048
|
+
return token;
|
1049
|
+
}
|
1050
|
+
}
|
1051
|
+
// Static tokens for common symbols
|
1052
|
+
SqlPrintTokenParser.SPACE_TOKEN = new SqlPrintToken(SqlPrintTokenType.space, ' ');
|
1053
|
+
SqlPrintTokenParser.COMMA_TOKEN = new SqlPrintToken(SqlPrintTokenType.comma, ',');
|
1054
|
+
SqlPrintTokenParser.ARGUMENT_SPLIT_COMMA_TOKEN = new SqlPrintToken(SqlPrintTokenType.argumentSplitter, ',');
|
1055
|
+
SqlPrintTokenParser.PAREN_OPEN_TOKEN = new SqlPrintToken(SqlPrintTokenType.parenthesis, '(');
|
1056
|
+
SqlPrintTokenParser.PAREN_CLOSE_TOKEN = new SqlPrintToken(SqlPrintTokenType.parenthesis, ')');
|
1057
|
+
SqlPrintTokenParser.DOT_TOKEN = new SqlPrintToken(SqlPrintTokenType.dot, '.');
|
1058
|
+
//# sourceMappingURL=SqlPrintTokenParser.js.map
|