prettier-plugin-sql-cst 0.17.4 → 0.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (212) hide show
  1. package/dist/{CstToDocMap.d.ts → src/CstToDocMap.d.ts} +2 -2
  2. package/dist/src/CstToDocMap.js +1 -0
  3. package/dist/src/PrintFn.js +1 -0
  4. package/dist/src/embed.js +6 -0
  5. package/dist/src/embedJs.js +43 -0
  6. package/dist/src/embedJson.js +34 -0
  7. package/dist/src/embedSql.d.ts +3 -0
  8. package/dist/src/embedSql.js +39 -0
  9. package/dist/src/index.js +64 -0
  10. package/dist/{node_utils.d.ts → src/node_utils.d.ts} +1 -0
  11. package/dist/src/node_utils.js +44 -0
  12. package/dist/{options.js → src/options.js} +1 -4
  13. package/dist/{printComment.js → src/printComment.js} +2 -6
  14. package/dist/src/printSql.js +61 -0
  15. package/dist/src/print_utils.js +49 -0
  16. package/dist/src/syntax/alias.js +3 -0
  17. package/dist/src/syntax/alter_action.js +120 -0
  18. package/dist/src/syntax/alter_table.js +19 -0
  19. package/dist/src/syntax/analyze.js +4 -0
  20. package/dist/{syntax → src/syntax}/base.js +6 -9
  21. package/dist/src/syntax/cast.js +4 -0
  22. package/dist/src/syntax/comment.js +54 -0
  23. package/dist/{syntax → src/syntax}/constraint.d.ts +1 -1
  24. package/dist/src/syntax/constraint.js +80 -0
  25. package/dist/src/syntax/create_table.js +69 -0
  26. package/dist/src/syntax/data_type.js +29 -0
  27. package/dist/src/syntax/dcl.js +83 -0
  28. package/dist/src/syntax/delete.js +5 -0
  29. package/dist/src/syntax/dialects/bigquery.js +84 -0
  30. package/dist/src/syntax/dialects/mysql.js +3 -0
  31. package/dist/src/syntax/dialects/postgresql.js +9 -0
  32. package/dist/src/syntax/dialects/sqlite.js +9 -0
  33. package/dist/src/syntax/do.js +4 -0
  34. package/dist/src/syntax/domain.js +11 -0
  35. package/dist/src/syntax/drop_table.js +11 -0
  36. package/dist/src/syntax/explain.js +7 -0
  37. package/dist/src/syntax/expr.js +224 -0
  38. package/dist/src/syntax/extension.js +13 -0
  39. package/dist/src/syntax/frame.js +13 -0
  40. package/dist/src/syntax/function.js +55 -0
  41. package/dist/src/syntax/index.js +60 -0
  42. package/dist/src/syntax/insert.js +33 -0
  43. package/dist/src/syntax/merge.js +30 -0
  44. package/dist/src/syntax/other_clauses.js +9 -0
  45. package/dist/src/syntax/parameter.js +18 -0
  46. package/dist/src/syntax/policy.js +27 -0
  47. package/dist/src/syntax/prepared_statements.js +31 -0
  48. package/dist/src/syntax/proc_clause.js +14 -0
  49. package/dist/src/syntax/procedural_language.js +104 -0
  50. package/dist/src/syntax/procedure.js +38 -0
  51. package/dist/src/syntax/program.js +39 -0
  52. package/dist/src/syntax/publication.js +27 -0
  53. package/dist/src/syntax/rename_table.js +8 -0
  54. package/dist/src/syntax/role.js +31 -0
  55. package/dist/src/syntax/schema.js +18 -0
  56. package/dist/src/syntax/select.js +226 -0
  57. package/dist/src/syntax/sequence.js +36 -0
  58. package/dist/src/syntax/subscription.js +10 -0
  59. package/dist/src/syntax/transaction.js +19 -0
  60. package/dist/src/syntax/transformMap.js +100 -0
  61. package/dist/src/syntax/trigger.js +52 -0
  62. package/dist/src/syntax/truncate.js +10 -0
  63. package/dist/src/syntax/type.js +12 -0
  64. package/dist/src/syntax/unsupported_grammar.js +4 -0
  65. package/dist/src/syntax/update.js +14 -0
  66. package/dist/src/syntax/view.js +48 -0
  67. package/dist/src/transform/addFinalSemicolon.js +9 -0
  68. package/dist/src/transform/aliasAs.js +10 -0
  69. package/dist/{transform → src/transform}/canonicKeywords.js +16 -20
  70. package/dist/{transform → src/transform}/canonicOperators.js +8 -12
  71. package/dist/src/transform/comments.js +22 -0
  72. package/dist/src/transform/stripTrailingCommas.js +15 -0
  73. package/dist/src/transform/transformCst.js +21 -0
  74. package/dist/src/transform/transformUtils.js +3 -0
  75. package/dist/src/utils.js +9 -0
  76. package/dist/src/visitAllNodes.js +16 -0
  77. package/dist/tsconfig.json +14 -0
  78. package/package.json +10 -8
  79. package/dist/CstToDocMap.js +0 -2
  80. package/dist/PrintFn.js +0 -2
  81. package/dist/embed.js +0 -13
  82. package/dist/embedJs.js +0 -99
  83. package/dist/embedJson.js +0 -90
  84. package/dist/index.js +0 -70
  85. package/dist/node_utils.js +0 -54
  86. package/dist/printSql.js +0 -71
  87. package/dist/print_utils.js +0 -68
  88. package/dist/syntax/alias.js +0 -6
  89. package/dist/syntax/alter_action.js +0 -213
  90. package/dist/syntax/alter_table.js +0 -28
  91. package/dist/syntax/analyze.js +0 -9
  92. package/dist/syntax/cast.js +0 -7
  93. package/dist/syntax/comment.js +0 -123
  94. package/dist/syntax/constraint.js +0 -116
  95. package/dist/syntax/create_table.js +0 -107
  96. package/dist/syntax/data_type.js +0 -48
  97. package/dist/syntax/dcl.js +0 -141
  98. package/dist/syntax/delete.js +0 -10
  99. package/dist/syntax/dialects/bigquery.js +0 -130
  100. package/dist/syntax/dialects/mysql.js +0 -6
  101. package/dist/syntax/dialects/postgresql.js +0 -14
  102. package/dist/syntax/dialects/sqlite.js +0 -18
  103. package/dist/syntax/do.js +0 -7
  104. package/dist/syntax/domain.js +0 -20
  105. package/dist/syntax/drop_table.js +0 -16
  106. package/dist/syntax/explain.js +0 -12
  107. package/dist/syntax/expr.js +0 -273
  108. package/dist/syntax/extension.js +0 -22
  109. package/dist/syntax/frame.js +0 -18
  110. package/dist/syntax/function.js +0 -65
  111. package/dist/syntax/index.js +0 -87
  112. package/dist/syntax/insert.js +0 -50
  113. package/dist/syntax/merge.js +0 -35
  114. package/dist/syntax/other_clauses.js +0 -18
  115. package/dist/syntax/parameter.js +0 -31
  116. package/dist/syntax/policy.js +0 -42
  117. package/dist/syntax/prepared_statements.js +0 -51
  118. package/dist/syntax/proc_clause.js +0 -19
  119. package/dist/syntax/procedural_language.js +0 -135
  120. package/dist/syntax/procedure.js +0 -42
  121. package/dist/syntax/program.js +0 -46
  122. package/dist/syntax/publication.js +0 -48
  123. package/dist/syntax/rename_table.js +0 -13
  124. package/dist/syntax/role.js +0 -56
  125. package/dist/syntax/schema.js +0 -36
  126. package/dist/syntax/select.js +0 -295
  127. package/dist/syntax/sequence.js +0 -53
  128. package/dist/syntax/subscription.js +0 -25
  129. package/dist/syntax/transaction.js +0 -34
  130. package/dist/syntax/transformMap.js +0 -64
  131. package/dist/syntax/trigger.js +0 -76
  132. package/dist/syntax/truncate.js +0 -15
  133. package/dist/syntax/type.js +0 -23
  134. package/dist/syntax/unsupported_grammar.js +0 -7
  135. package/dist/syntax/update.js +0 -21
  136. package/dist/syntax/view.js +0 -59
  137. package/dist/transform/addFinalSemicolon.js +0 -13
  138. package/dist/transform/aliasAs.js +0 -14
  139. package/dist/transform/comments.js +0 -43
  140. package/dist/transform/stripTrailingCommas.js +0 -19
  141. package/dist/transform/transformCst.js +0 -25
  142. package/dist/transform/transformUtils.js +0 -7
  143. package/dist/utils.js +0 -30
  144. package/dist/visitAllNodes.js +0 -21
  145. /package/dist/{PrintFn.d.ts → src/PrintFn.d.ts} +0 -0
  146. /package/dist/{embed.d.ts → src/embed.d.ts} +0 -0
  147. /package/dist/{embedJs.d.ts → src/embedJs.d.ts} +0 -0
  148. /package/dist/{embedJson.d.ts → src/embedJson.d.ts} +0 -0
  149. /package/dist/{index.d.ts → src/index.d.ts} +0 -0
  150. /package/dist/{options.d.ts → src/options.d.ts} +0 -0
  151. /package/dist/{printComment.d.ts → src/printComment.d.ts} +0 -0
  152. /package/dist/{printSql.d.ts → src/printSql.d.ts} +0 -0
  153. /package/dist/{print_utils.d.ts → src/print_utils.d.ts} +0 -0
  154. /package/dist/{syntax → src/syntax}/alias.d.ts +0 -0
  155. /package/dist/{syntax → src/syntax}/alter_action.d.ts +0 -0
  156. /package/dist/{syntax → src/syntax}/alter_table.d.ts +0 -0
  157. /package/dist/{syntax → src/syntax}/analyze.d.ts +0 -0
  158. /package/dist/{syntax → src/syntax}/base.d.ts +0 -0
  159. /package/dist/{syntax → src/syntax}/cast.d.ts +0 -0
  160. /package/dist/{syntax → src/syntax}/comment.d.ts +0 -0
  161. /package/dist/{syntax → src/syntax}/create_table.d.ts +0 -0
  162. /package/dist/{syntax → src/syntax}/data_type.d.ts +0 -0
  163. /package/dist/{syntax → src/syntax}/dcl.d.ts +0 -0
  164. /package/dist/{syntax → src/syntax}/delete.d.ts +0 -0
  165. /package/dist/{syntax → src/syntax}/dialects/bigquery.d.ts +0 -0
  166. /package/dist/{syntax → src/syntax}/dialects/mysql.d.ts +0 -0
  167. /package/dist/{syntax → src/syntax}/dialects/postgresql.d.ts +0 -0
  168. /package/dist/{syntax → src/syntax}/dialects/sqlite.d.ts +0 -0
  169. /package/dist/{syntax → src/syntax}/do.d.ts +0 -0
  170. /package/dist/{syntax → src/syntax}/domain.d.ts +0 -0
  171. /package/dist/{syntax → src/syntax}/drop_table.d.ts +0 -0
  172. /package/dist/{syntax → src/syntax}/explain.d.ts +0 -0
  173. /package/dist/{syntax → src/syntax}/expr.d.ts +0 -0
  174. /package/dist/{syntax → src/syntax}/extension.d.ts +0 -0
  175. /package/dist/{syntax → src/syntax}/frame.d.ts +0 -0
  176. /package/dist/{syntax → src/syntax}/function.d.ts +0 -0
  177. /package/dist/{syntax → src/syntax}/index.d.ts +0 -0
  178. /package/dist/{syntax → src/syntax}/insert.d.ts +0 -0
  179. /package/dist/{syntax → src/syntax}/merge.d.ts +0 -0
  180. /package/dist/{syntax → src/syntax}/other_clauses.d.ts +0 -0
  181. /package/dist/{syntax → src/syntax}/parameter.d.ts +0 -0
  182. /package/dist/{syntax → src/syntax}/policy.d.ts +0 -0
  183. /package/dist/{syntax → src/syntax}/prepared_statements.d.ts +0 -0
  184. /package/dist/{syntax → src/syntax}/proc_clause.d.ts +0 -0
  185. /package/dist/{syntax → src/syntax}/procedural_language.d.ts +0 -0
  186. /package/dist/{syntax → src/syntax}/procedure.d.ts +0 -0
  187. /package/dist/{syntax → src/syntax}/program.d.ts +0 -0
  188. /package/dist/{syntax → src/syntax}/publication.d.ts +0 -0
  189. /package/dist/{syntax → src/syntax}/rename_table.d.ts +0 -0
  190. /package/dist/{syntax → src/syntax}/role.d.ts +0 -0
  191. /package/dist/{syntax → src/syntax}/schema.d.ts +0 -0
  192. /package/dist/{syntax → src/syntax}/select.d.ts +0 -0
  193. /package/dist/{syntax → src/syntax}/sequence.d.ts +0 -0
  194. /package/dist/{syntax → src/syntax}/subscription.d.ts +0 -0
  195. /package/dist/{syntax → src/syntax}/transaction.d.ts +0 -0
  196. /package/dist/{syntax → src/syntax}/transformMap.d.ts +0 -0
  197. /package/dist/{syntax → src/syntax}/trigger.d.ts +0 -0
  198. /package/dist/{syntax → src/syntax}/truncate.d.ts +0 -0
  199. /package/dist/{syntax → src/syntax}/type.d.ts +0 -0
  200. /package/dist/{syntax → src/syntax}/unsupported_grammar.d.ts +0 -0
  201. /package/dist/{syntax → src/syntax}/update.d.ts +0 -0
  202. /package/dist/{syntax → src/syntax}/view.d.ts +0 -0
  203. /package/dist/{transform → src/transform}/addFinalSemicolon.d.ts +0 -0
  204. /package/dist/{transform → src/transform}/aliasAs.d.ts +0 -0
  205. /package/dist/{transform → src/transform}/canonicKeywords.d.ts +0 -0
  206. /package/dist/{transform → src/transform}/canonicOperators.d.ts +0 -0
  207. /package/dist/{transform → src/transform}/comments.d.ts +0 -0
  208. /package/dist/{transform → src/transform}/stripTrailingCommas.d.ts +0 -0
  209. /package/dist/{transform → src/transform}/transformCst.d.ts +0 -0
  210. /package/dist/{transform → src/transform}/transformUtils.d.ts +0 -0
  211. /package/dist/{utils.d.ts → src/utils.d.ts} +0 -0
  212. /package/dist/{visitAllNodes.d.ts → src/visitAllNodes.d.ts} +0 -0
@@ -0,0 +1,226 @@
1
+ import { isDefined } from "../utils";
2
+ import { join, line, hardline, indent, group, containsNewline, breakParent, } from "../print_utils";
3
+ export const selectMap = {
4
+ compound_select_stmt: (print) => group(join(hardline, [print("left"), print.spaced("operator"), print("right")])),
5
+ select_stmt: (print) => group(join(print.dynamicLine(), print("clauses"))),
6
+ // WITH clause
7
+ with_clause: (print) => group([
8
+ print.spaced(["withKw", "recursiveKw"]),
9
+ indent([line, print("tables")]),
10
+ ]),
11
+ common_table_expr: (print, node) => [
12
+ print(["table", "columns"]),
13
+ " ",
14
+ print.spaced(["asKw", "materializedKw", "expr"]),
15
+ group([
16
+ node.search || node.cycle
17
+ ? indent([line, print.separated(line, ["search", "cycle"])])
18
+ : [],
19
+ ]),
20
+ ],
21
+ cte_search_clause: (print) => group(join(line, [
22
+ [print.spaced("searchKw"), group(indent([line, print("columns")]))],
23
+ print.spaced(["setKw", "resultColumn"]),
24
+ ])),
25
+ cte_cycle_clause: (print, node) => group(join(line, [
26
+ [print("cycleKw"), group(indent([line, print("columns")]))],
27
+ print.spaced(["setKw", "resultColumn"]),
28
+ node.values ? print("values") : undefined,
29
+ print.spaced(["usingKw", "pathColumn"]),
30
+ ].filter(isDefined))),
31
+ cte_cycle_clause_values: (print) => join(line, [
32
+ print.spaced(["toKw", "markValue"]),
33
+ print.spaced(["defaultKw", "defaultValue"]),
34
+ ]),
35
+ // SELECT clause
36
+ select_clause: (print, node, path, opts) => group([
37
+ print.spaced(["selectKw", "modifiers"]),
38
+ node.columns ? indent([line, print("columns")]) : [],
39
+ containsNewline(node, opts) ? breakParent : [],
40
+ ]),
41
+ select_all: (print) => print.spaced(["allKw"]),
42
+ select_distinct: (print) => print.spaced(["distinctKw"]),
43
+ select_distinct_on: (print) => group([print.spaced(["distinctOnKw", "columns"])]),
44
+ select_as_struct: (print) => print.spaced(["asStructKw"]),
45
+ select_as_value: (print) => print.spaced(["asValueKw"]),
46
+ except_columns: (print) => print.spaced(["expr", "exceptKw", "columns"]),
47
+ replace_columns: (print) => print.spaced(["expr", "replaceKw", "columns"]),
48
+ // FROM clause
49
+ from_clause: (print) => group([print("fromKw"), indent([line, print("expr")])]),
50
+ join_expr: (print, node) => {
51
+ if (node.operator === ",") {
52
+ return join([",", hardline], print(["left", "right"]));
53
+ }
54
+ else {
55
+ return [
56
+ print("left"),
57
+ hardline,
58
+ group(join(" ", [
59
+ print.spaced("operator"),
60
+ [
61
+ print("right"),
62
+ node.specification
63
+ ? indent([line, print(["specification"])])
64
+ : [],
65
+ ],
66
+ ])),
67
+ ];
68
+ }
69
+ },
70
+ join_on_specification: (print) => group(print.spaced(["onKw", "expr"])),
71
+ join_using_specification: (print) => group(print.spaced(["usingKw", "expr"])),
72
+ table_with_inheritance: (print) => [print("table"), " ", "*"],
73
+ table_without_inheritance: (print) => print.spaced(["onlyKw", "table"]),
74
+ indexed_table: (print) => print.spaced(["table", "indexedByKw", "index"]),
75
+ not_indexed_table: (print) => print.spaced(["table", "notIndexedKw"]),
76
+ unnest_expr: (print) => print(["unnestKw", "expr"]),
77
+ unnest_with_offset_expr: (print) => print.spaced(["unnest", "withOffsetKw"]),
78
+ pivot_expr: (print) => [print("left"), hardline, print(["pivotKw", "args"])],
79
+ pivot_for_in: (print) => group(join(line, [
80
+ group(print("aggregations")),
81
+ print.spaced(["forKw", "inputColumn"]),
82
+ print.spaced(["inKw", "pivotColumns"]),
83
+ ])),
84
+ unpivot_expr: (print, node) => [
85
+ print("left"),
86
+ hardline,
87
+ (node.nullHandlingKw ? print.spaced : print)([
88
+ "unpivotKw",
89
+ "nullHandlingKw",
90
+ "args",
91
+ ]),
92
+ ],
93
+ unpivot_for_in: (print) => group(join(line, [
94
+ print("valuesColumn"),
95
+ print.spaced(["forKw", "nameColumn"]),
96
+ print.spaced(["inKw", "unpivotColumns"]),
97
+ ])),
98
+ tablesample_expr: (print) => group([
99
+ print("left"),
100
+ line,
101
+ print.spaced(["tablesampleKw", "method", "args", "repeatable"]),
102
+ ]),
103
+ tablesample_method: (print) => print.spaced(["methodKw"]),
104
+ tablesample_percent: (print) => print.spaced(["percent", "percentKw"]),
105
+ tablesample_repeatable: (print) => print.spaced(["repeatableKw", "seed"]),
106
+ for_system_time_as_of_expr: (print) => group([print("left"), line, print.spaced(["forSystemTimeAsOfKw", "expr"])]),
107
+ partitioned_table: (print) => print.spaced(["table", "partitionKw", "partitions"]),
108
+ dual_table: (print) => print("dualKw"),
109
+ lateral_derived_table: (print) => print.spaced(["lateralKw", "expr"]),
110
+ rows_from_expr: (print) => print.spaced(["rowsFromKw", "expr"]),
111
+ with_ordinality_expr: (print) => print.spaced(["expr", "withOrdinalityKw"]),
112
+ func_call_with_column_definitions: (print) => print.spaced(["funcCall", "asKw", "columns"]),
113
+ // WHERE clause
114
+ where_clause: (print) => group([print("whereKw"), indent([line, print("expr")])]),
115
+ // ORDER BY clause
116
+ order_by_clause: (print, node) => group([
117
+ print.spaced("orderByKw"),
118
+ indent([line, print.separated(line, ["specifications", "withRollupKw"])]),
119
+ ]),
120
+ sort_specification: (print) => print.spaced(["expr", "direction", "nullHandlingKw"]),
121
+ sort_direction_asc: (print) => print("ascKw"),
122
+ sort_direction_desc: (print) => print("descKw"),
123
+ sort_direction_using_operator: (print) => print.spaced(["usingKw", "operator"]),
124
+ // GROUP BY clause
125
+ group_by_clause: (print, node) => group([
126
+ print.spaced(["groupByKw", "distinctKw"]),
127
+ indent([line, print.separated(line, ["columns", "withRollupKw"])]),
128
+ ]),
129
+ group_by_rollup: (print) => print(["rollupKw", "columns"]),
130
+ group_by_cube: (print) => print(["cubeKw", "columns"]),
131
+ group_by_grouping_sets: (print) => print.spaced(["groupingSetsKw", "columns"]),
132
+ group_by_all: (print) => print(["allKw"]),
133
+ // PARTITION BY clause
134
+ partition_by_clause: (print) => group([
135
+ print.spaced("partitionByKw"),
136
+ indent([line, print("specifications")]),
137
+ ]),
138
+ // HAVING clause
139
+ having_clause: (print) => group([print("havingKw"), indent([line, print("expr")])]),
140
+ // QUALIFY clause
141
+ qualify_clause: (print) => group([print("qualifyKw"), indent([line, print("expr")])]),
142
+ // LIMIT clause
143
+ /** cst-ignore: count, offsetKw, offset */
144
+ limit_clause: (print, node) => group([
145
+ print("limitKw"),
146
+ indent([
147
+ line,
148
+ printLimitValues(print, node),
149
+ node.rowsExamined ? [line, print("rowsExamined")] : [],
150
+ ]),
151
+ ]),
152
+ limit_all: (print) => print("allKw"),
153
+ limit_rows_examined: (print) => print.spaced(["rowsExaminedKw", "count"]),
154
+ // OFFSET clause
155
+ offset_clause: (print) => group([
156
+ print("offsetKw"),
157
+ indent([line, print.spaced(["offset", "rowsKw"])]),
158
+ ]),
159
+ // FETCH clause
160
+ fetch_clause: (print) => print.spaced(["fetchKw", "count", "rowsKw", "withTiesKw"]),
161
+ // WINDOW clause
162
+ window_clause: (print, node) => {
163
+ const lineType = node.namedWindows.items.length > 1 ? hardline : line;
164
+ return group([
165
+ print("windowKw"),
166
+ indent([lineType, print("namedWindows")]),
167
+ ]);
168
+ },
169
+ named_window: (print) => print.spaced(["name", "asKw", "window"]),
170
+ window_definition: (print, node) => {
171
+ const itemCount = [
172
+ node.baseWindowName,
173
+ node.partitionBy,
174
+ node.orderBy,
175
+ node.frame,
176
+ ].filter(isDefined).length;
177
+ const lineType = itemCount > 1 ? hardline : line;
178
+ return group(join(lineType, print(["baseWindowName", "partitionBy", "orderBy", "frame"])));
179
+ },
180
+ // INTO clause
181
+ into_table_clause: (print) => print.spaced(["intoKw", "kind", "tableKw", "name"]),
182
+ into_variables_clause: (print) => group([print("intoKw"), indent([line, print("variables")])]),
183
+ into_dumpfile_clause: (print) => print.spaced(["intoDumpfileKw", "filename"]),
184
+ into_outfile_clause: (print, node) => {
185
+ const hasOptions = node.charset || node.fields || node.lines;
186
+ return group([
187
+ print.spaced(["intoOutfileKw", "filename"]),
188
+ hasOptions
189
+ ? indent([
190
+ hardline,
191
+ join(hardline, print(["charset", "fields", "lines"])),
192
+ ])
193
+ : [],
194
+ ]);
195
+ },
196
+ outfile_fields: (print) => print.spaced(["fieldsKw", "options"]),
197
+ outfile_lines: (print) => print.spaced(["linesKw", "options"]),
198
+ outfile_option_character_set: (print) => print.spaced(["characterSetKw", "value"]),
199
+ outfile_option_starting_by: (print) => print.spaced(["startingByKw", "value"]),
200
+ outfile_option_terminated_by: (print) => print.spaced(["terminatedByKw", "value"]),
201
+ outfile_option_enclosed_by: (print) => print.spaced(["optionallyKw", "enclosedByKw", "value"]),
202
+ outfile_option_escaped_by: (print) => print.spaced(["escapedByKw", "value"]),
203
+ // FOR clause (locking)
204
+ for_clause: (print, node) => group([
205
+ print.spaced(["forKw", "lockStrengthKw", "tables"]),
206
+ node.waitingKw ? indent([line, print.spaced("waitingKw")]) : [],
207
+ ]),
208
+ for_clause_tables: (print) => [
209
+ print("ofKw"),
210
+ indent([line, print("tables")]),
211
+ ],
212
+ lock_in_share_mode_clause: (print) => print.spaced("lockInShareModeKw"),
213
+ // TABLE clause
214
+ table_clause: (print) => print.spaced(["tableKw", "table"]),
215
+ };
216
+ const printLimitValues = (print, node) => {
217
+ if (node.offsetKw) {
218
+ return print.spaced(["count", "offsetKw", "offset"]);
219
+ }
220
+ else if (node.offset) {
221
+ return join([",", " "], print(["offset", "count"]));
222
+ }
223
+ else {
224
+ return print("count");
225
+ }
226
+ };
@@ -0,0 +1,36 @@
1
+ import { group, indent, join, line } from "../print_utils";
2
+ export const sequenceMap = {
3
+ create_sequence_stmt: (print, node) => group([
4
+ print.spaced(["createKw", "kind", "sequenceKw", "ifNotExistsKw", "name"]),
5
+ node.options.length > 0
6
+ ? indent([print.dynamicLine(), join(line, print("options"))])
7
+ : [],
8
+ ]),
9
+ alter_sequence_stmt: (print) => group([
10
+ print.spaced(["alterKw", "sequenceKw", "ifExistsKw", "sequence"]),
11
+ indent([print.dynamicLine(), join(line, print("actions"))]),
12
+ ]),
13
+ drop_sequence_stmt: (print) => group(print.spaced([
14
+ "dropKw",
15
+ "sequenceKw",
16
+ "ifExistsKw",
17
+ "sequences",
18
+ "behaviorKw",
19
+ ])),
20
+ sequence_option_sequence_name: (print) => print.spaced(["sequenceNameKw", "name"]),
21
+ sequence_option_logged: (print) => print.spaced("loggedKw"),
22
+ sequence_option_unlogged: (print) => print.spaced("unloggedKw"),
23
+ sequence_option_as_type: (print) => print.spaced(["asKw", "dataType"]),
24
+ sequence_option_increment: (print) => print.spaced(["incrementKw", "byKw", "value"]),
25
+ sequence_option_minvalue: (print) => print.spaced(["minvalueKw", "value"]),
26
+ sequence_option_maxvalue: (print) => print.spaced(["maxvalueKw", "value"]),
27
+ sequence_option_no_minvalue: (print) => print.spaced("noMinvalueKw"),
28
+ sequence_option_no_maxvalue: (print) => print.spaced("noMaxvalueKw"),
29
+ sequence_option_start: (print) => print.spaced(["startKw", "withKw", "value"]),
30
+ sequence_option_restart: (print) => print.spaced(["restartKw", "withKw", "value"]),
31
+ sequence_option_cache: (print) => print.spaced(["cacheKw", "value"]),
32
+ sequence_option_cycle: (print) => print.spaced("cycleKw"),
33
+ sequence_option_no_cycle: (print) => print.spaced("noCycleKw"),
34
+ sequence_option_owned_by: (print) => print.spaced(["ownedByKw", "owner"]),
35
+ sequence_option_list: (print) => join(line, print("options")),
36
+ };
@@ -0,0 +1,10 @@
1
+ import { group, line, join } from "../print_utils";
2
+ export const subscriptionMap = {
3
+ create_subscription_stmt: (print, node) => group(join(line, [
4
+ print.spaced(["createSubscriptionKw", "name"]),
5
+ print.spaced(["connectionKw", "connectionInfo"]),
6
+ print.spaced(["publicationKw", "publications"]),
7
+ ...(node.with ? [print.spaced(["with"])] : []),
8
+ ])),
9
+ drop_subscription_stmt: (print) => group(print.spaced(["dropSubscriptionKw", "ifExistsKw", "name", "behaviorKw"])),
10
+ };
@@ -0,0 +1,19 @@
1
+ import { group, indent, line } from "../print_utils";
2
+ export const transactionMap = {
3
+ start_transaction_stmt: (print, node) => group([
4
+ print.spaced(["startKw", "behaviorKw", "transactionKw"]),
5
+ node.modes ? indent([line, print("modes")]) : [],
6
+ ]),
7
+ commit_transaction_stmt: (print) => group(print.spaced(["commitKw", "transactionKw", "chain"])),
8
+ rollback_transaction_stmt: (print) => group(print.spaced(["rollbackKw", "transactionKw", "savepoint", "chain"])),
9
+ rollback_to_savepoint: (print) => print.spaced(["toKw", "savepointKw", "savepoint"]),
10
+ savepoint_stmt: (print) => group(print.spaced(["savepointKw", "savepoint"])),
11
+ release_savepoint_stmt: (print) => group(print.spaced(["releaseKw", "savepointKw", "savepoint"])),
12
+ transaction_chain_clause: (print) => print.spaced("andChainKw"),
13
+ transaction_no_chain_clause: (print) => print.spaced("andNoChainKw"),
14
+ transaction_mode_isolation_level: (print) => print.spaced(["isolationLevelKw", "levelKw"]),
15
+ transaction_mode_deferrable: (print) => print.spaced("deferrableKw"),
16
+ transaction_mode_not_deferrable: (print) => print.spaced("notDeferrableKw"),
17
+ transaction_mode_read_only: (print) => print.spaced("readOnlyKw"),
18
+ transaction_mode_read_write: (print) => print.spaced("readWriteKw"),
19
+ };
@@ -0,0 +1,100 @@
1
+ import { aliasMap } from "./alias";
2
+ import { alterActionMap } from "./alter_action";
3
+ import { alterTableMap } from "./alter_table";
4
+ import { analyzeMap } from "./analyze";
5
+ import { baseMap } from "./base";
6
+ import { castMap } from "./cast";
7
+ import { commentMap } from "./comment";
8
+ import { constraintMap } from "./constraint";
9
+ import { createTableMap } from "./create_table";
10
+ import { dataTypeMap } from "./data_type";
11
+ import { dclMap } from "./dcl";
12
+ import { deleteMap } from "./delete";
13
+ import { doMap } from "./do";
14
+ import { domainMap } from "./domain";
15
+ import { dropTableMap } from "./drop_table";
16
+ import { explainMap } from "./explain";
17
+ import { exprMap } from "./expr";
18
+ import { extensionMap } from "./extension";
19
+ import { frameMap } from "./frame";
20
+ import { functionMap } from "./function";
21
+ import { indexMap } from "./index";
22
+ import { insertMap } from "./insert";
23
+ import { mergeMap } from "./merge";
24
+ import { otherClausesMap } from "./other_clauses";
25
+ import { renameTableMap } from "./rename_table";
26
+ import { roleMap } from "./role";
27
+ import { parameterMap } from "./parameter";
28
+ import { policyMap } from "./policy";
29
+ import { preparedStatementsMap } from "./prepared_statements";
30
+ import { proceduralLanguageMap } from "./procedural_language";
31
+ import { procedureMap } from "./procedure";
32
+ import { procClauseMap } from "./proc_clause";
33
+ import { programMap } from "./program";
34
+ import { publicationMap } from "./publication";
35
+ import { schemaMap } from "./schema";
36
+ import { selectMap } from "./select";
37
+ import { sequenceMap } from "./sequence";
38
+ import { subscriptionMap } from "./subscription";
39
+ import { transactionMap } from "./transaction";
40
+ import { triggerMap } from "./trigger";
41
+ import { truncateMap } from "./truncate";
42
+ import { typeMap } from "./type";
43
+ import { unsupportedGrammarMap } from "./unsupported_grammar";
44
+ import { updateMap } from "./update";
45
+ import { viewMap } from "./view";
46
+ import { bigqueryMap } from "./dialects/bigquery";
47
+ import { mysqlMap } from "./dialects/mysql";
48
+ import { sqliteMap } from "./dialects/sqlite";
49
+ import { postgresqlMap } from "./dialects/postgresql";
50
+ export const transformMap = {
51
+ ...aliasMap,
52
+ ...alterActionMap,
53
+ ...alterTableMap,
54
+ ...analyzeMap,
55
+ ...baseMap,
56
+ ...castMap,
57
+ ...commentMap,
58
+ ...constraintMap,
59
+ ...createTableMap,
60
+ ...dataTypeMap,
61
+ ...dclMap,
62
+ ...deleteMap,
63
+ ...doMap,
64
+ ...domainMap,
65
+ ...dropTableMap,
66
+ ...explainMap,
67
+ ...exprMap,
68
+ ...extensionMap,
69
+ ...frameMap,
70
+ ...functionMap,
71
+ ...indexMap,
72
+ ...insertMap,
73
+ ...mergeMap,
74
+ ...otherClausesMap,
75
+ ...parameterMap,
76
+ ...policyMap,
77
+ ...preparedStatementsMap,
78
+ ...procClauseMap,
79
+ ...proceduralLanguageMap,
80
+ ...procedureMap,
81
+ ...programMap,
82
+ ...publicationMap,
83
+ ...renameTableMap,
84
+ ...roleMap,
85
+ ...schemaMap,
86
+ ...selectMap,
87
+ ...sequenceMap,
88
+ ...subscriptionMap,
89
+ ...transactionMap,
90
+ ...triggerMap,
91
+ ...truncateMap,
92
+ ...typeMap,
93
+ ...unsupportedGrammarMap,
94
+ ...updateMap,
95
+ ...viewMap,
96
+ ...bigqueryMap,
97
+ ...mysqlMap,
98
+ ...postgresqlMap,
99
+ ...sqliteMap,
100
+ };
@@ -0,0 +1,52 @@
1
+ import { group, hardline, indent, join, line } from "../print_utils";
2
+ export const triggerMap = {
3
+ create_trigger_stmt: (print, node) => group(join(hardline, [
4
+ print.spaced([
5
+ "createKw",
6
+ "orReplaceKw",
7
+ "kind",
8
+ "triggerKw",
9
+ "ifNotExistsKw",
10
+ "name",
11
+ ]),
12
+ group([
13
+ node.timeKw ? [print.spaced("timeKw"), " "] : [],
14
+ print("event"),
15
+ line,
16
+ print("target"),
17
+ ]),
18
+ ...print("clauses"),
19
+ print("body"),
20
+ ])),
21
+ trigger_event: (print, node) => group([
22
+ print.spaced(["eventKw", "ofKw"]),
23
+ node.columns ? indent([line, print("columns")]) : [],
24
+ ]),
25
+ trigger_target: (print) => print.spaced(["onKw", "table"]),
26
+ when_clause: (print) => group([print("whenKw"), indent([line, print("expr")])]),
27
+ for_each_clause: (print) => print.spaced(["forEachKw", "itemKw"]),
28
+ execute_clause: (print) => [
29
+ print.spaced(["executeKw", "functionKw", "name"]),
30
+ print("args"),
31
+ ],
32
+ from_referenced_table_clause: (print) => print.spaced(["fromKw", "table"]),
33
+ trigger_timing_clause: (print) => print.spaced(["timingKw"]),
34
+ trigger_referencing_clause: (print) => group([
35
+ print.spaced(["referencingKw"]),
36
+ indent([line, print("transitions")]),
37
+ ]),
38
+ trigger_transition: (print) => [
39
+ print.spaced(["oldOrNewKw", "rowOrTableKw", "asKw", "name"]),
40
+ ],
41
+ alter_trigger_stmt: (print) => group(join(print.dynamicLine(), [
42
+ print.spaced(["alterTriggerKw", "trigger", "target"]),
43
+ print("action"),
44
+ ])),
45
+ drop_trigger_stmt: (print) => group(print.spaced([
46
+ "dropTriggerKw",
47
+ "ifExistsKw",
48
+ "trigger",
49
+ "target",
50
+ "behaviorKw",
51
+ ])),
52
+ };
@@ -0,0 +1,10 @@
1
+ import { group, indent, line } from "../print_utils";
2
+ export const truncateMap = {
3
+ truncate_stmt: (print) => group([
4
+ print.spaced(["truncateKw", "tableKw"]),
5
+ indent([
6
+ line,
7
+ print.separated(line, ["tables", "restartOrContinueKw", "behaviorKw"]),
8
+ ]),
9
+ ]),
10
+ };
@@ -0,0 +1,12 @@
1
+ import { group } from "../print_utils";
2
+ export const typeMap = {
3
+ create_type_stmt: (print) => group([print.spaced(["createTypeKw", "name", "definition"])]),
4
+ composite_type_definition: (print) => group(print.spaced(["asKw", "columns"])),
5
+ enum_type_definition: (print) => group(print.spaced(["asEnumKw", "values"])),
6
+ alter_type_stmt: (print, node) => group([
7
+ print.spaced(["alterTypeKw", "name"]),
8
+ print.dynamicLine(),
9
+ print("actions"),
10
+ ]),
11
+ drop_type_stmt: (print) => group(print.spaced(["dropTypeKw", "ifExistsKw", "types", "behaviorKw"])),
12
+ };
@@ -0,0 +1,4 @@
1
+ import { group } from "../print_utils";
2
+ export const unsupportedGrammarMap = {
3
+ unsupported_grammar_stmt: (print) => group(print("text")),
4
+ };
@@ -0,0 +1,14 @@
1
+ import { join, hardline, indent, group } from "../print_utils";
2
+ export const updateMap = {
3
+ update_stmt: (print) => group(join(print.dynamicLine(), print("clauses"))),
4
+ update_clause: (print) => print.spaced(["updateKw", "modifiers", "orAction", "tables"]),
5
+ set_clause: (print, node) => {
6
+ if (node.assignments.items.length > 1) {
7
+ return [print("setKw"), indent([hardline, print("assignments")])];
8
+ }
9
+ else {
10
+ return print.spaced(["setKw", "assignments"]);
11
+ }
12
+ },
13
+ column_assignment: (print) => join([" ", "=", " "], print(["column", "expr"])),
14
+ };
@@ -0,0 +1,48 @@
1
+ import { group, hardline, join, line } from "../print_utils";
2
+ export const viewMap = {
3
+ create_view_stmt: (print, node) => {
4
+ const hasOnlyAsClause = node.clauses.length === 1;
5
+ const hasManyClauses = node.clauses.length > 1;
6
+ return group([
7
+ print.spaced([
8
+ "createKw",
9
+ "orReplaceKw",
10
+ "kinds",
11
+ "viewKw",
12
+ "ifNotExistsKw",
13
+ "name",
14
+ "columns",
15
+ ]),
16
+ hasOnlyAsClause ? [" ", print("clauses")] : [],
17
+ hasManyClauses ? [hardline, join(hardline, print("clauses"))] : [],
18
+ ]);
19
+ },
20
+ with_check_option_clause: (print) => print.spaced(["withKw", "levelKw", "checkOptionKw"]),
21
+ as_replica_of_clause: (print) => print.spaced(["asReplicaOfKw", "view"]),
22
+ drop_view_stmt: (print) => group(print.spaced([
23
+ "dropKw",
24
+ "kind",
25
+ "viewKw",
26
+ "ifExistsKw",
27
+ "views",
28
+ "behaviorKw",
29
+ ])),
30
+ alter_view_stmt: (print) => group([
31
+ print.spaced([
32
+ "alterKw",
33
+ "kind",
34
+ "viewKw",
35
+ "ifExistsKw",
36
+ "name",
37
+ "columns",
38
+ ]),
39
+ hardline,
40
+ print("actions"),
41
+ ]),
42
+ refresh_materialized_view_stmt: (print, node) => group([
43
+ print.spaced(["refreshMaterializedViewKw", "concurrentlyKw", "name"]),
44
+ node.clauses.length > 0
45
+ ? [print.dynamicLine(), join(line, print("clauses"))]
46
+ : [],
47
+ ]),
48
+ };
@@ -0,0 +1,9 @@
1
+ import { isEmpty } from "../node_utils";
2
+ import { last } from "../utils";
3
+ export const addFinalSemicolon = (program, originalText) => {
4
+ if (!isEmpty(last(program.statements))) {
5
+ const end = originalText.length;
6
+ program.statements.push({ type: "empty", range: [end, end] });
7
+ }
8
+ return program;
9
+ };
@@ -0,0 +1,10 @@
1
+ import { cstVisitor } from "sql-parser-cst";
2
+ // Adds AS keyword to aliases if none exists
3
+ export const processAliasAs = (cst) => {
4
+ cstVisitor({
5
+ alias: (node) => {
6
+ node.asKw = node.asKw || { type: "keyword", name: "AS", text: "AS" };
7
+ },
8
+ })(cst);
9
+ return cst;
10
+ };
@@ -1,12 +1,9 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.canonicKeywords = void 0;
4
- var sql_parser_cst_1 = require("sql-parser-cst");
5
- var transformUtils_1 = require("./transformUtils");
6
- var canonicKeywords = function (cst) {
7
- (0, sql_parser_cst_1.cstVisitor)({
1
+ import { cstVisitor } from "sql-parser-cst";
2
+ import { keyword } from "./transformUtils";
3
+ export const canonicKeywords = (cst) => {
4
+ cstVisitor({
8
5
  // Replaces TEMP with TEMPORARY
9
- relation_kind: function (node) {
6
+ relation_kind: (node) => {
10
7
  if (Array.isArray(node.kindKw)) {
11
8
  // TODO...
12
9
  }
@@ -18,14 +15,14 @@ var canonicKeywords = function (cst) {
18
15
  }
19
16
  },
20
17
  // Replaces MySQL SELECT DISTINCTROW with SELECT DISTINCT
21
- select_distinct: function (node) {
18
+ select_distinct: (node) => {
22
19
  if (node.distinctKw.name === "DISTINCTROW") {
23
20
  node.distinctKw.name = "DISTINCT";
24
21
  node.distinctKw.text = "DISTINCT";
25
22
  }
26
23
  },
27
24
  // Replaces RENAME & RENAME AS with RENAME TO
28
- alter_action_rename: function (node) {
25
+ alter_action_rename: (node) => {
29
26
  if (Array.isArray(node.renameKw)) {
30
27
  if (node.renameKw[1].name === "AS") {
31
28
  node.renameKw[1].name = "TO";
@@ -33,34 +30,33 @@ var canonicKeywords = function (cst) {
33
30
  }
34
31
  }
35
32
  else {
36
- node.renameKw = [node.renameKw, (0, transformUtils_1.keyword)("TO")];
33
+ node.renameKw = [node.renameKw, keyword("TO")];
37
34
  }
38
35
  },
39
36
  // Replaces INSERT with INSERT INTO
40
- insert_clause: function (node) {
37
+ insert_clause: (node) => {
41
38
  if (!node.intoKw) {
42
- node.intoKw = (0, transformUtils_1.keyword)("INTO");
39
+ node.intoKw = keyword("INTO");
43
40
  }
44
41
  },
45
42
  // Replaces MERGE with MERGE INTO
46
- merge_clause: function (node) {
43
+ merge_clause: (node) => {
47
44
  if (!node.intoKw) {
48
- node.intoKw = (0, transformUtils_1.keyword)("INTO");
45
+ node.intoKw = keyword("INTO");
49
46
  }
50
47
  },
51
48
  // Replaces DELETE with DELETE FROM
52
- delete_clause: function (node) {
49
+ delete_clause: (node) => {
53
50
  if (!node.fromKw) {
54
- node.fromKw = (0, transformUtils_1.keyword)("FROM");
51
+ node.fromKw = keyword("FROM");
55
52
  }
56
53
  },
57
54
  // Replaces TRUNCATE with TRUNCATE TABLE
58
- truncate_stmt: function (node) {
55
+ truncate_stmt: (node) => {
59
56
  if (!node.tableKw) {
60
- node.tableKw = (0, transformUtils_1.keyword)("TABLE");
57
+ node.tableKw = keyword("TABLE");
61
58
  }
62
59
  },
63
60
  })(cst);
64
61
  return cst;
65
62
  };
66
- exports.canonicKeywords = canonicKeywords;