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,13 @@
1
+ import { group, indent, line } from "../print_utils";
2
+ export const extensionMap = {
3
+ create_extension_stmt: (print, node) => group([
4
+ print.spaced(["createExtensionKw", "ifNotExistsKw", "name"]),
5
+ node.clauses.length > 0
6
+ ? indent([line, print.spaced(["withKw", "clauses"])])
7
+ : [],
8
+ ]),
9
+ extension_cascade_clause: (print) => group(print.spaced(["cascadeKw"])),
10
+ extension_schema_clause: (print) => group(print.spaced(["schemaKw", "name"])),
11
+ extension_version_clause: (print) => group(print.spaced(["versionKw", "name"])),
12
+ drop_extension_stmt: (print) => group(print.spaced(["dropExtensionKw", "ifExistsKw", "names", "behaviorKw"])),
13
+ };
@@ -0,0 +1,13 @@
1
+ import { hardline } from "../print_utils";
2
+ export const frameMap = {
3
+ frame_clause: (print, node) => [
4
+ print.spaced(["unitKw", "extent"]),
5
+ node.exclusion ? [hardline, print("exclusion")] : [],
6
+ ],
7
+ frame_bound_current_row: (print) => print.spaced("currentRowKw"),
8
+ frame_bound_preceding: (print) => print.spaced(["expr", "precedingKw"]),
9
+ frame_bound_following: (print) => print.spaced(["expr", "followingKw"]),
10
+ frame_unbounded: (print) => print.spaced("unboundedKw"),
11
+ frame_between: (print) => print.spaced(["betweenKw", "begin", "andKw", "end"]),
12
+ frame_exclusion: (print) => print.spaced(["excludeKw", "kindKw"]),
13
+ };
@@ -0,0 +1,55 @@
1
+ import { group, hardline, join } from "../print_utils";
2
+ import { isAsClause } from "../node_utils";
3
+ export const functionMap = {
4
+ create_function_stmt: (print, node) => group([
5
+ print.spaced([
6
+ "createKw",
7
+ "orReplaceKw",
8
+ "temporaryKw",
9
+ "tableKw",
10
+ "functionKw",
11
+ "ifNotExistsKw",
12
+ "name",
13
+ ]),
14
+ print("params"),
15
+ hasOnlyAsClause(node)
16
+ ? [" ", group(print("clauses"))]
17
+ : [
18
+ hardline,
19
+ join(hardline, print("clauses").map((cls) => group(cls))),
20
+ ],
21
+ ]),
22
+ function_signature: (print) => print(["name", "params"]),
23
+ function_param: (print) => print.spaced(["mode", "name", "dataType", "default"]),
24
+ function_param_default: (print) => print.spaced(["operator", "expr"]),
25
+ return_clause: (print) => print.spaced(["returnKw", "expr"]),
26
+ function_behavior_clause: (print) => print.spaced(["behaviorKw"]),
27
+ function_security_clause: (print) => print.spaced(["externalKw", "securityKw"]),
28
+ function_cost_clause: (print) => print.spaced(["costKw", "cost"]),
29
+ function_rows_clause: (print) => print.spaced(["rowsKw", "rows"]),
30
+ function_support_clause: (print) => print.spaced(["supportKw", "name"]),
31
+ function_window_clause: (print) => print.spaced("windowKw"),
32
+ function_transform_clause: (print) => print.spaced(["transformKw", "types"]),
33
+ transform_type: (print) => print.spaced(["forTypeKw", "dataType"]),
34
+ dynamically_loaded_function: (print) => join(", ", print(["objectFile", "symbol"])),
35
+ drop_function_stmt: (print) => group([
36
+ print.spaced([
37
+ "dropKw",
38
+ "tableKw",
39
+ "functionKw",
40
+ "ifExistsKw",
41
+ "signatures",
42
+ "behaviorKw",
43
+ ]),
44
+ ]),
45
+ // almost exact copy of alter_procedure_stmt
46
+ alter_function_stmt: (print, node) => group([
47
+ print.spaced(["alterKw", "functionKw"]),
48
+ " ",
49
+ print(["signature"]),
50
+ print.dynamicLine(),
51
+ join(print.dynamicLine(), print("actions")),
52
+ node.behaviorKw ? [print.dynamicLine(), print("behaviorKw")] : [],
53
+ ]),
54
+ };
55
+ export const hasOnlyAsClause = (node) => node.clauses.length === 1 && isAsClause(node.clauses[0]);
@@ -0,0 +1,60 @@
1
+ import { group, join } from "../print_utils";
2
+ export const indexMap = {
3
+ create_index_stmt: (print) => group(join(print.dynamicLine(), [
4
+ print.spaced([
5
+ "createKw",
6
+ "orReplaceKw",
7
+ "indexTypeKw",
8
+ "indexKw",
9
+ "concurrentlyKw",
10
+ "ifNotExistsKw",
11
+ "name",
12
+ "onKw",
13
+ "table",
14
+ "using",
15
+ "columns",
16
+ ]),
17
+ ...print("clauses"),
18
+ ])),
19
+ index_specification: (print) => print.spaced(["expr", "opclass", "direction", "nullHandlingKw"]),
20
+ index_include_clause: (print) => print.spaced(["includeKw", "columns"]),
21
+ index_nulls_distinct_clause: (print) => print.spaced(["nullsDistinctKw"]),
22
+ index_nulls_not_distinct_clause: (print) => print.spaced(["nullsNotDistinctKw"]),
23
+ drop_index_stmt: (print) => group(print.spaced([
24
+ "dropKw",
25
+ "indexTypeKw",
26
+ "indexKw",
27
+ "concurrentlyKw",
28
+ "ifExistsKw",
29
+ "indexes",
30
+ "onKw",
31
+ "table",
32
+ "behaviorKw",
33
+ ])),
34
+ verbose_all_columns: (print) => print.spaced("allColumnsKw"),
35
+ alter_index_stmt: (print) => group([
36
+ print.spaced(["alterKw", "indexKw", "ifExistsKw", "index"]),
37
+ print.dynamicLine(),
38
+ print("action"),
39
+ ]),
40
+ alter_index_all_in_tablespace_stmt: (print) => group([
41
+ print.spaced([
42
+ "alterIndexKw",
43
+ "allInTablespaceKw",
44
+ "tablespace",
45
+ "ownedBy",
46
+ ]),
47
+ print.dynamicLine(),
48
+ print("action"),
49
+ ]),
50
+ reindex_stmt: (print) => group(print.spaced([
51
+ "reindexKw",
52
+ "options",
53
+ "targetKw",
54
+ "concurrentlyKw",
55
+ "name",
56
+ ])),
57
+ reindex_option_concurrently: (print) => print.spaced(["concurrentlyKw", "value"]),
58
+ reindex_option_tablespace: (print) => print.spaced(["tablespaceKw", "name"]),
59
+ reindex_option_verbose: (print) => print.spaced(["verboseKw", "value"]),
60
+ };
@@ -0,0 +1,33 @@
1
+ import { join, group, indent } from "../print_utils";
2
+ export const insertMap = {
3
+ insert_stmt: (print) => group(join(print.dynamicLine(), print("clauses"))),
4
+ insert_clause: (print, node) => group([
5
+ print.spaced(["insertKw", "modifiers", "orAction", "intoKw", "table"]),
6
+ node.columns ? indent([print.dynamicLine(), print("columns")]) : [],
7
+ ]),
8
+ values_clause: (print) => group([print("valuesKw"), indent([print.dynamicLine(), print("values")])]),
9
+ or_alternate_action: (print) => print.spaced(["orKw", "actionKw"]),
10
+ default: (print) => print("defaultKw"),
11
+ default_values: (print) => print.spaced("defaultValuesKw"),
12
+ upsert_clause: (print) => print.spaced(["onConflictKw", "conflictTarget", "where", "doKw", "action"]),
13
+ conflict_target_on_constraint: (print) => print.spaced(["onConstraintKw", "constraint"]),
14
+ upsert_action_nothing: (print) => print("nothingKw"),
15
+ upsert_action_update: (print) => group([
16
+ print("updateKw"),
17
+ indent([
18
+ print.dynamicLine(),
19
+ join(print.dynamicLine(), print(["set", "where"])),
20
+ ]),
21
+ ]),
22
+ row_alias_clause: (print, node) => group([
23
+ print.spaced(["asKw", "rowAlias"]),
24
+ node.columnAliases
25
+ ? indent([print.dynamicLine(), print("columnAliases")])
26
+ : [],
27
+ ]),
28
+ on_duplicate_key_update_clause: (print) => group([
29
+ print.spaced("onDuplicateKeyUpdateKw"),
30
+ indent([print.dynamicLine(), print("assignments")]),
31
+ ]),
32
+ overriding_clause: (print) => print.spaced("overridingKw"),
33
+ };
@@ -0,0 +1,30 @@
1
+ import { group, hardline, indent, join, line } from "../print_utils";
2
+ export const mergeMap = {
3
+ merge_stmt: (print) => group(join(hardline, print("clauses"))),
4
+ merge_clause: (print) => join(line, [
5
+ print.spaced(["mergeKw", "intoKw", "target"]),
6
+ print.spaced(["usingKw", "source"]),
7
+ group([print("onKw"), indent([line, print("condition")])]),
8
+ ]),
9
+ merge_when_clause: (print, node) => [
10
+ group([
11
+ print.spaced(["whenKw", "matchedKw", "byKw"]),
12
+ node.condition ? indent([line, print("condition")]) : [],
13
+ [line, print("thenKw")],
14
+ ]),
15
+ indent([hardline, group(print("action"))]),
16
+ ],
17
+ merge_when_condition: (print) => print.spaced(["andKw", "expr"]),
18
+ merge_action_delete: (print) => print("deleteKw"),
19
+ merge_action_insert: (print, node) => [
20
+ group([
21
+ print("insertKw"),
22
+ node.columns ? indent([hardline, print("columns")]) : [],
23
+ ]),
24
+ line,
25
+ join(hardline, print("clauses")),
26
+ ],
27
+ merge_action_insert_row_clause: (print) => print("rowKw"),
28
+ merge_action_update: (print) => print.spaced(["updateKw", "set"]),
29
+ merge_action_do_nothing: (print) => print.spaced(["doNothingKw"]),
30
+ };
@@ -0,0 +1,9 @@
1
+ import { line, indent, group } from "../print_utils";
2
+ export const otherClausesMap = {
3
+ // CLUSTER BY clause
4
+ cluster_by_clause: (print) => group([print.spaced("clusterByKw"), indent([line, print("columns")])]),
5
+ // RETURNING clause
6
+ returning_clause: (print) => group([print("returningKw"), indent([line, print("columns")])]),
7
+ // WHERE CURRENT OF clause
8
+ where_current_of_clause: (print) => print.spaced(["whereCurrentOfKw", "cursor"]),
9
+ };
@@ -0,0 +1,18 @@
1
+ import { printLiteral } from "./expr";
2
+ import { group } from "../print_utils";
3
+ export const parameterMap = {
4
+ // SET
5
+ set_parameter_stmt: (print) => group(print.spaced(["setKw", "modifierKw", "name", "operator", "value"])),
6
+ set_time_zone_parameter_stmt: (print) => group(print.spaced(["setKw", "modifierKw", "timeZoneKw", "value"])),
7
+ set_parameter_clause: (print) => print.spaced(["setKw", "name", "operator", "value"]),
8
+ local_parameter_value: (print) => print("localKw"),
9
+ set_parameter_from_current_clause: (print) => print.spaced(["setKw", "name", "fromCurrentKw"]),
10
+ // RESET
11
+ reset_parameter_stmt: (print) => group(print.spaced(["resetKw", "name"])),
12
+ reset_parameter_clause: (print) => print.spaced(["resetKw", "name"]),
13
+ all_parameters: (print) => print("allKw"),
14
+ // SHOW
15
+ show_parameter_stmt: (print) => group(print.spaced(["showKw", "name"])),
16
+ /** cst-ignore: value */
17
+ boolean_on_off_literal: (print, node, path, options) => printLiteral(node.valueKw, options),
18
+ };
@@ -0,0 +1,27 @@
1
+ import { group, join } from "../print_utils";
2
+ export const policyMap = {
3
+ create_policy_stmt: (print, node) => group([
4
+ print.spaced(["createPolicyKw", "name", "onKw", "table"]),
5
+ node.clauses.length > 0 ? print.dynamicLine() : [],
6
+ join(print.dynamicLine(), print("clauses")),
7
+ ]),
8
+ policy_permissive_clause: (print) => group(print.spaced(["asKw", "permissiveKw"])),
9
+ policy_restrictive_clause: (print) => group(print.spaced(["asKw", "restrictiveKw"])),
10
+ policy_command_clause: (print) => group(print.spaced(["forKw", "commandKw"])),
11
+ policy_roles_clause: (print) => group(print.spaced(["toKw", "roles"])),
12
+ policy_using_clause: (print) => group(print.spaced(["usingKw", "expr"])),
13
+ policy_check_clause: (print) => group(print.spaced(["withKw", "checkKw", "expr"])),
14
+ alter_policy_stmt: (print) => group([
15
+ print.spaced(["alterPolicyKw", "name", "onKw", "table"]),
16
+ print.dynamicLine(),
17
+ join(print.dynamicLine(), print("actions")),
18
+ ]),
19
+ drop_policy_stmt: (print) => group(print.spaced([
20
+ "dropPolicyKw",
21
+ "ifExistsKw",
22
+ "name",
23
+ "onKw",
24
+ "table",
25
+ "behaviorKw",
26
+ ])),
27
+ };
@@ -0,0 +1,31 @@
1
+ import { group, hardline, indent, join, line } from "../print_utils";
2
+ export const preparedStatementsMap = {
3
+ // EXECUTE
4
+ execute_stmt: (print, node) => {
5
+ if (node.args?.type === "execute_using_clause") {
6
+ return group(print.spaced(["executeKw", "name", "args"]));
7
+ }
8
+ else {
9
+ return group([print.spaced(["executeKw", "name"]), print("args")]);
10
+ }
11
+ },
12
+ execute_immediate_stmt: (print) => group(join(hardline, [
13
+ group([
14
+ print.spaced(["executeKw", "immediateKw"]),
15
+ indent([line, print("expr")]),
16
+ ]),
17
+ ...print(["into", "using"]).map((clause) => group(clause)),
18
+ ])),
19
+ execute_into_clause: (print) => print.spaced(["intoKw", "variables"]),
20
+ execute_using_clause: (print) => group([print("usingKw"), indent([line, print("values")])]),
21
+ // PREPARE
22
+ prepare_stmt: (print) => group(join(" ", [
23
+ print("prepareKw"),
24
+ print(["name", "params"]),
25
+ print("source"),
26
+ ])),
27
+ prepare_from_clause: (print) => group([print("fromKw"), indent([line, print("expr")])]),
28
+ // DEALLOCATE
29
+ deallocate_stmt: (print) => group(print.spaced(["deallocateKw", "name"])),
30
+ deallocate_all: (print) => print("allKw"),
31
+ };
@@ -0,0 +1,14 @@
1
+ import { isDynamicallyLoadedFunction, isStringLiteral } from "../node_utils";
2
+ import { hardline, indent } from "../print_utils";
3
+ export const procClauseMap = {
4
+ returns_clause: (print) => print.spaced(["returnsKw", "dataType"]),
5
+ determinism_clause: (print) => print.spaced("deterministicKw"),
6
+ language_clause: (print) => print.spaced(["languageKw", "name"]),
7
+ as_clause: (print, node) => {
8
+ if (isStringLiteral(node.expr) || isDynamicallyLoadedFunction(node.expr)) {
9
+ return print.spaced(["asKw", "expr"]);
10
+ }
11
+ return [print("asKw"), indent([hardline, print("expr")])];
12
+ },
13
+ with_connection_clause: (print) => print.spaced(["withConnectionKw", "connection"]),
14
+ };
@@ -0,0 +1,104 @@
1
+ import { group, hardline, indent, join, line, stripTrailingHardline, } from "../print_utils";
2
+ export const proceduralLanguageMap = {
3
+ // BEGIN .. END
4
+ block_stmt: (print, node) => group([
5
+ print.spaced(["beginKw", "atomicKw"]),
6
+ indent([hardline, stripTrailingHardline(print("program"))]),
7
+ node.exception ? [hardline, print("exception")] : [],
8
+ hardline,
9
+ print("endKw"),
10
+ ]),
11
+ exception_clause: (print) => group([
12
+ print.spaced(["exceptionKw", "whenKw", "condition", "thenKw"]),
13
+ indent([hardline, stripTrailingHardline(print("program"))]),
14
+ ]),
15
+ error_category: (print) => print("errorKw"),
16
+ // DECLARE
17
+ declare_stmt: (print) => group(join(" ", [
18
+ print("declareKw"),
19
+ group(print("names")),
20
+ ...print.spaced(["dataType", "default"]),
21
+ ])),
22
+ declare_default: (print) => print.spaced(["defaultKw", "expr"]),
23
+ // SET
24
+ set_stmt: (print) => group(print.spaced(["setKw", "assignments"])),
25
+ // IF
26
+ if_stmt: (print) => group(join(hardline, [...print("clauses"), print.spaced("endIfKw")])),
27
+ if_clause: (print) => [
28
+ group([
29
+ print("ifKw"),
30
+ indent([line, print("condition")]),
31
+ line,
32
+ print("thenKw"),
33
+ ]),
34
+ indent([hardline, stripTrailingHardline(print("consequent"))]),
35
+ ],
36
+ elseif_clause: (print) => [
37
+ group([
38
+ print("elseifKw"),
39
+ indent([line, print("condition")]),
40
+ line,
41
+ print("thenKw"),
42
+ ]),
43
+ indent([hardline, stripTrailingHardline(print("consequent"))]),
44
+ ],
45
+ else_clause: (print) => [
46
+ print("elseKw"),
47
+ indent([hardline, stripTrailingHardline(print("consequent"))]),
48
+ ],
49
+ // CASE
50
+ case_stmt: (print) => group([
51
+ print.spaced(["caseKw", "expr"]),
52
+ indent([hardline, join(hardline, print("clauses"))]),
53
+ hardline,
54
+ print.spaced("endCaseKw"),
55
+ ]),
56
+ // LOOP
57
+ loop_stmt: (print) => group([
58
+ print("loopKw"),
59
+ indent([hardline, stripTrailingHardline(print("body"))]),
60
+ hardline,
61
+ print.spaced("endLoopKw"),
62
+ ]),
63
+ // REPEAT
64
+ repeat_stmt: (print) => group([
65
+ print("repeatKw"),
66
+ indent([hardline, stripTrailingHardline(print("body"))]),
67
+ hardline,
68
+ print.spaced(["untilKw", "condition", "endRepeatKw"]),
69
+ ]),
70
+ // WHILE
71
+ while_stmt: (print) => group([
72
+ print.spaced(["whileKw", "condition", "doKw"]),
73
+ indent([hardline, stripTrailingHardline(print("body"))]),
74
+ hardline,
75
+ print.spaced("endWhileKw"),
76
+ ]),
77
+ // FOR .. IN
78
+ for_stmt: (print) => group([
79
+ print.spaced(["forKw", "left", "inKw", "right", "doKw"]),
80
+ indent([hardline, stripTrailingHardline(print("body"))]),
81
+ hardline,
82
+ print.spaced("endForKw"),
83
+ ]),
84
+ // BREAK/CONTINUE
85
+ break_stmt: (print) => group(print.spaced(["breakKw", "label"])),
86
+ continue_stmt: (print) => group(print.spaced(["continueKw", "label"])),
87
+ labeled_stmt: (print, node) => group([
88
+ print("beginLabel"),
89
+ ": ",
90
+ print("statement"),
91
+ node.endLabel ? [" ", print(["endLabel"])] : [],
92
+ ]),
93
+ // CALL
94
+ call_stmt: (print) => group(print.spaced(["callKw", "func"])),
95
+ // RETURN
96
+ return_stmt: (print) => group(print.spaced(["returnKw", "expr"])),
97
+ // RAISE
98
+ raise_stmt: (print) => group(print.spaced(["raiseKw", "message"])),
99
+ raise_message: (print) => [
100
+ print.spaced("usingMessageKw"),
101
+ " = ",
102
+ print("string"),
103
+ ],
104
+ };
@@ -0,0 +1,38 @@
1
+ import { group, hardline, join } from "../print_utils";
2
+ import { hasOnlyAsClause } from "./function";
3
+ export const procedureMap = {
4
+ create_procedure_stmt: (print, node) => group([
5
+ print.spaced([
6
+ "createKw",
7
+ "orReplaceKw",
8
+ "procedureKw",
9
+ "ifNotExistsKw",
10
+ "name",
11
+ ]),
12
+ print("params"),
13
+ hasOnlyAsClause(node)
14
+ ? [" ", group(print("clauses"))]
15
+ : [
16
+ hardline,
17
+ join(hardline, print("clauses").map((clause) => group(clause))),
18
+ ],
19
+ ]),
20
+ drop_procedure_stmt: (print) => group([
21
+ print.spaced([
22
+ "dropKw",
23
+ "procedureKw",
24
+ "ifExistsKw",
25
+ "signatures",
26
+ "behaviorKw",
27
+ ]),
28
+ ]),
29
+ // almost exact copy of alter_function_stmt
30
+ alter_procedure_stmt: (print, node) => group([
31
+ print.spaced(["alterKw", "procedureKw"]),
32
+ " ",
33
+ print(["signature"]),
34
+ print.dynamicLine(),
35
+ join(print.dynamicLine(), print("actions")),
36
+ node.behaviorKw ? [print.dynamicLine(), print("behaviorKw")] : [],
37
+ ]),
38
+ };
@@ -0,0 +1,39 @@
1
+ import { hardline, hasEmptyLineBetweenNodes } from "../print_utils";
2
+ export const programMap = {
3
+ program: (print, node, path, options) => print("statements").map((doc, i) => i === node.statements.length - 1
4
+ ? printFinalStatement(doc, i, node.statements, options)
5
+ : printStatement(doc, i, node.statements, options)),
6
+ };
7
+ const printStatement = (doc, i, statements, options) => {
8
+ const prevNode = statements[i - 1];
9
+ const node = statements[i];
10
+ if (i === 0) {
11
+ return doc;
12
+ }
13
+ else if (node.type !== "empty") {
14
+ if (hasEmptyLineBetweenNodes(prevNode, node, options)) {
15
+ return [";", hardline, hardline, doc];
16
+ }
17
+ else {
18
+ return [";", hardline, doc];
19
+ }
20
+ }
21
+ else {
22
+ return [";", hardline, doc];
23
+ }
24
+ };
25
+ const printFinalStatement = (doc, i, statements, options) => {
26
+ const stmtDoc = printStatement(doc, i, statements, options);
27
+ if (statements[i].type === "empty") {
28
+ // When the final statement is an empty statement,
29
+ // this means we have inserted a semicolon and newline before it.
30
+ // So nothing else is needed.
31
+ return stmtDoc;
32
+ }
33
+ else {
34
+ // If the last statement is not empty,
35
+ // this means sqlFinalSemicolon option is false,
36
+ // so we need to add an empty line after it.
37
+ return [stmtDoc, hardline];
38
+ }
39
+ };
@@ -0,0 +1,27 @@
1
+ import { group, indent, line } from "../print_utils";
2
+ export const publicationMap = {
3
+ create_publication_stmt: (print, node) => group([
4
+ print.spaced(["createPublicationKw", "name"]),
5
+ print("clauses").map((printedClause, i) => {
6
+ if (node.clauses[i].type === "for_publication_objects_clause") {
7
+ return [" ", printedClause];
8
+ }
9
+ else {
10
+ return [line, printedClause];
11
+ }
12
+ }),
13
+ ]),
14
+ for_publication_objects_clause: (print) => group([print("forKw"), indent([line, print("publicationObjects")])]),
15
+ all_publication_object: (print) => group(print.spaced(["allKw", "typesKw"])),
16
+ publication_object_table: (print) => group(print.spaced(["tableKw", "table", "columns", "where"])),
17
+ publication_object_tables_in_schema: (print) => group(print.spaced(["tablesInSchemaKw", "schema"])),
18
+ alter_publication_stmt: (print) => group([
19
+ print.spaced(["alterPublicationKw", "name"]),
20
+ print.dynamicLine(),
21
+ print("action"),
22
+ ]),
23
+ alter_action_add_publication_objects: (print) => group([print("addKw"), indent([line, print("publicationObjects")])]),
24
+ alter_action_set_publication_objects: (print) => group([print("setKw"), indent([line, print("publicationObjects")])]),
25
+ alter_action_drop_publication_objects: (print) => group([print("dropKw"), indent([line, print("publicationObjects")])]),
26
+ drop_publication_stmt: (print) => group(print.spaced(["dropPublicationKw", "ifExistsKw", "names", "behaviorKw"])),
27
+ };
@@ -0,0 +1,8 @@
1
+ import { group, indent, line } from "../print_utils";
2
+ export const renameTableMap = {
3
+ rename_table_stmt: (print) => group([
4
+ print.spaced(["renameKw", "tableKw"]),
5
+ indent([line, print("actions")]),
6
+ ]),
7
+ rename_action: (print) => print.spaced(["from", "toKw", "to"]),
8
+ };
@@ -0,0 +1,31 @@
1
+ import { group, indent, join, line } from "../print_utils";
2
+ export const roleMap = {
3
+ create_role_stmt: (print, node) => group([
4
+ print.spaced(["createRoleKw", "name", "withKw"]),
5
+ ...(node.options?.length
6
+ ? [indent([line, join(print.dynamicLine(), print("options"))])]
7
+ : []),
8
+ ]),
9
+ alter_role_stmt: (print, node) => group([
10
+ join(print.dynamicLine(), [
11
+ group([print.spaced("alterRoleKw"), indent([line, print("name")])]),
12
+ ...(node.database ? print(["database"]) : []),
13
+ ]),
14
+ node.action.type === "alter_action_with_role_options" &&
15
+ !node.action.withKw
16
+ ? indent([print.dynamicLine(), print("action")])
17
+ : [print.dynamicLine(), print("action")],
18
+ ]),
19
+ drop_role_stmt: (print) => group(print.spaced(["dropRoleKw", "ifExistsKw", "names"])),
20
+ set_role_stmt: (print) => group(print.spaced(["setKw", "scopeKw", "roleKw", "name"])),
21
+ reset_role_stmt: (print) => group(print.spaced("resetRoleKw")),
22
+ role_option_keyword: (print) => print("kw"),
23
+ role_option_connection_limit: (print) => group(print.spaced(["connectionLimitKw", "limit"])),
24
+ role_option_password: (print) => group(print.spaced(["encryptedKw", "passwordKw", "password"])),
25
+ role_option_valid_until: (print) => group(print.spaced(["validUntilKw", "timestamp"])),
26
+ role_option_in_role: (print) => group(print.spaced(["inRoleKw", "names"])),
27
+ role_option_role: (print) => group(print.spaced(["roleKw", "names"])),
28
+ role_option_admin: (print) => group(print.spaced(["adminKw", "names"])),
29
+ role_option_sysid: (print) => group(print.spaced(["sysIdKw", "sysId"])),
30
+ in_database_clause: (print) => group(print.spaced(["inDatabaseKw", "name"])),
31
+ };
@@ -0,0 +1,18 @@
1
+ import { group, hardline, indent, join } from "../print_utils";
2
+ export const schemaMap = {
3
+ create_schema_stmt: (print, node) => group([
4
+ group(join(print.dynamicLine(), [
5
+ print.spaced(["createSchemaKw", "ifNotExistsKw", "name"]),
6
+ ...print("clauses"),
7
+ ])),
8
+ node.statements.length > 0
9
+ ? indent([hardline, join(hardline, print("statements"))])
10
+ : [],
11
+ ]),
12
+ create_schema_authorization_clause: (print) => print.spaced(["authorizationKw", "role"]),
13
+ drop_schema_stmt: (print) => group(print.spaced(["dropSchemaKw", "ifExistsKw", "schemas", "behaviorKw"])),
14
+ alter_schema_stmt: (print) => group(join(print.dynamicLine(), [
15
+ print.spaced(["alterSchemaKw", "ifExistsKw", "name"]),
16
+ ...print("actions"),
17
+ ])),
18
+ };