rawsql-ts 0.11.43-beta → 0.11.44-beta

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