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