prettier-plugin-sql-cst 0.10.1 → 0.11.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 (46) hide show
  1. package/README.md +22 -6
  2. package/dist/PrintFn.d.ts +3 -0
  3. package/dist/embedJs.js +1 -1
  4. package/dist/embedJson.js +1 -1
  5. package/dist/index.js +1 -1
  6. package/dist/options.d.ts +1 -0
  7. package/dist/options.js +7 -0
  8. package/dist/printComment.js +1 -1
  9. package/dist/printSql.js +12 -7
  10. package/dist/syntax/alter_table.js +39 -11
  11. package/dist/syntax/base.js +4 -3
  12. package/dist/syntax/constraint.js +44 -13
  13. package/dist/syntax/create_table.js +47 -6
  14. package/dist/syntax/dcl.js +4 -4
  15. package/dist/syntax/delete.js +1 -1
  16. package/dist/syntax/dialects/postgresql.d.ts +1 -1
  17. package/dist/syntax/dialects/postgresql.js +1 -0
  18. package/dist/syntax/drop_table.js +2 -2
  19. package/dist/syntax/explain.js +1 -1
  20. package/dist/syntax/expr.js +13 -1
  21. package/dist/syntax/index.js +3 -3
  22. package/dist/syntax/insert.js +31 -16
  23. package/dist/syntax/merge.js +7 -14
  24. package/dist/syntax/other_clauses.d.ts +3 -0
  25. package/dist/syntax/other_clauses.js +18 -0
  26. package/dist/syntax/procedural_language.js +1 -1
  27. package/dist/syntax/rename_table.d.ts +3 -0
  28. package/dist/syntax/rename_table.js +13 -0
  29. package/dist/syntax/select.js +6 -35
  30. package/dist/syntax/transformMap.d.ts +1 -1
  31. package/dist/syntax/transformMap.js +3 -1
  32. package/dist/syntax/trigger.js +1 -1
  33. package/dist/syntax/truncate.js +14 -1
  34. package/dist/syntax/update.js +1 -1
  35. package/dist/syntax/view.js +16 -2
  36. package/dist/transform/aliasAs.js +2 -3
  37. package/dist/transform/canonicKeywords.d.ts +2 -0
  38. package/dist/transform/canonicKeywords.js +66 -0
  39. package/dist/transform/canonicOperators.d.ts +3 -0
  40. package/dist/transform/canonicOperators.js +32 -0
  41. package/dist/transform/stripTrailingCommas.js +2 -3
  42. package/dist/transform/transformCst.d.ts +4 -1
  43. package/dist/transform/transformCst.js +14 -4
  44. package/dist/transform/transformUtils.d.ts +2 -0
  45. package/dist/transform/transformUtils.js +7 -0
  46. package/package.json +6 -4
package/README.md CHANGED
@@ -98,10 +98,25 @@ The plugin provides the following parsers:
98
98
  The standard Prettier options [printWidth][], [tabWidth][], [useTabs][] apply.
99
99
  There are also some SQL-specific options:
100
100
 
101
- | API Option | Default | Description |
102
- | ---------------- | :-----: | ------------------------------------------------------------------------- |
103
- | `sqlKeywordCase` | `upper` | Converts SQL keywords to `upper` or `lower` case, or `preserve` existing. |
104
- | `sqlParamTypes` | `[]` | Array of bound parameter types: `?`, `?nr`, `:name`, `@name`, `$name`. |
101
+ | API Option | Default | Description |
102
+ | -------------------- | :-----: | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
103
+ | `sqlKeywordCase` | `upper` | Converts SQL keywords to `upper` or `lower` case, or `preserve` existing. Note that for now `preserve` is somewhat incompatible with `sqlCanonicalSyntax: true` (e.g. the added `AS` keywords will always be in uppercase). |
104
+ | `sqlParamTypes` | `[]` | Array of bound parameter types: `?`, `?nr`, `:name`, `@name`, `$name`. |
105
+ | `sqlCanonicalSyntax` | `true` | When enabled, performs some opinionated changes of keywords and operators, like enforcing the use of `AS` in aliases and replacing `<>` comparisons with `!=`. See [STYLE_GUIDE][] for more details. (Since 0.11.0) |
106
+
107
+ ## FAQ
108
+
109
+ ### The SQL dialect I'm using is not supported. Can you add support for it?
110
+
111
+ Support for new SQL dialects depends on these dialects being supported by [sql-parser-cst][].
112
+ If you really want to, you can open a new issue for that in the parser repo.
113
+ But be aware that implementing parser support for new dialects takes a lot of work.
114
+ As long as the ongoing implementation of PostgreSQL, MySQL and MariaDB is not finished,
115
+ it's unlikely that work on any other dialect will start.
116
+
117
+ ### How can I format SQL strings inside JavaScript files?
118
+
119
+ Use [prettier-plugin-embed][] together with `prettier-plugin-sql-cst`.
105
120
 
106
121
  ## Limitations and development status
107
122
 
@@ -119,8 +134,8 @@ It also has experimental support for the following dialects:
119
134
  The main limitation is that [the parser][sql-parser-cst] does not support full syntax of
120
135
  these dialects. One should expect the parser to crash for syntax that's more specific to
121
136
  these dialects. But as long as the parsing succeeds, the formatting should also succeed.
122
- Mainly one can expect the formatting of SELECT statements to work. But beyond that you should
123
- keep your expectations low. You have been warned.
137
+ Mainly one can expect the formatting of SELECT, INSERT, UPDATE, DELETE statements to work.
138
+ But beyond that you should keep your expectations low. You have been warned.
124
139
 
125
140
  The specifics of the [SQL formatting style][STYLE_GUIDE] are still very much subject to change.
126
141
  Though the general principles should be mostly in place by now.
@@ -132,4 +147,5 @@ Though the general principles should be mostly in place by now.
132
147
  [useTabs]: https://prettier.io/docs/en/options.html#tabs
133
148
  [sql-parser-cst]: https://github.com/nene/sql-parser-cst
134
149
  [wadler-prettier]: http://homepages.inf.ed.ac.uk/wadler/papers/prettier/prettier.pdf
150
+ [prettier-plugin-embed]: https://github.com/Sec-ant/prettier-plugin-embed
135
151
  [STYLE_GUIDE]: ./STYLE_GUIDE.md
package/dist/PrintFn.d.ts CHANGED
@@ -8,6 +8,9 @@ export type PrintFn<T, K = PrintableKey<T>> = {
8
8
  (path: K[]): Doc[];
9
9
  spaced(path: K): Doc[];
10
10
  spaced(path: K[]): Doc[];
11
+ separated(separator: Doc, path: K): Doc[];
12
+ separated(separator: Doc, path: K[]): Doc[];
13
+ dynamicLine(): Doc;
11
14
  };
12
15
  export type PrintableKey<T> = Exclude<keyof T, ReservedKey>;
13
16
  type ReservedKey = "type" | "range" | "leading" | "trailing";
package/dist/embedJs.js CHANGED
@@ -51,7 +51,7 @@ exports.embedJs = void 0;
51
51
  var node_utils_1 = require("./node_utils");
52
52
  var print_utils_1 = require("./print_utils");
53
53
  var embedJs = function (path, options) {
54
- var node = path.getValue(); // TODO: Don't use deprecated method
54
+ var node = path.node;
55
55
  var parent = path.getParentNode(0);
56
56
  var grandParent = path.getParentNode(1);
57
57
  if ((0, node_utils_1.isStringLiteral)(node) &&
package/dist/embedJson.js CHANGED
@@ -51,7 +51,7 @@ exports.embedJson = void 0;
51
51
  var node_utils_1 = require("./node_utils");
52
52
  var print_utils_1 = require("./print_utils");
53
53
  var embedJson = function (path, options) {
54
- var node = path.getValue(); // TODO: Don't use deprecated method
54
+ var node = path.node;
55
55
  var parent = path.getParentNode();
56
56
  if ((0, node_utils_1.isStringLiteral)(node) &&
57
57
  ((0, node_utils_1.isJsonLiteral)(parent) || (0, node_utils_1.isJsonbLiteral)(parent))) {
package/dist/index.js CHANGED
@@ -44,7 +44,7 @@ var createParser = function (dialect) { return ({
44
44
  includeComments: true,
45
45
  filename: options.filepath,
46
46
  paramTypes: options.sqlParamTypes,
47
- }), text);
47
+ }), text, options);
48
48
  },
49
49
  astFormat: "sql-cst",
50
50
  locStart: function (node) { var _a; return (_a = node.range) === null || _a === void 0 ? void 0 : _a[0]; },
package/dist/options.d.ts CHANGED
@@ -3,6 +3,7 @@ import { Node, ParserOptions as CstParserOptions } from "sql-parser-cst";
3
3
  export interface SqlPluginOptions {
4
4
  sqlKeywordCase: "preserve" | "upper" | "lower";
5
5
  sqlParamTypes: NonNullable<CstParserOptions["paramTypes"]>;
6
+ sqlCanonicalSyntax: boolean;
6
7
  }
7
8
  export type AllPrettierOptions<T = Node> = ParserOptions<T> & SqlPluginOptions;
8
9
  export declare const options: SupportOptions;
package/dist/options.js CHANGED
@@ -34,4 +34,11 @@ exports.options = {
34
34
  // Since 0.7.0
35
35
  // Possible values in array: "?" | "?nr" | ":name" | "$name" | "@name"
36
36
  },
37
+ sqlCanonicalSyntax: {
38
+ type: "boolean",
39
+ category: "SQL",
40
+ default: true,
41
+ description: "Enforces one true style of SQL syntax (adds and removes keywords)",
42
+ // Since 0.11.0
43
+ },
37
44
  };
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.printComment = void 0;
4
4
  var printComment = function (path) {
5
- var node = path.getValue();
5
+ var node = path.node;
6
6
  if (node.type === "line_comment") {
7
7
  if (/^--[^ \t]/.test(node.text)) {
8
8
  return node.text.replace(/^--/, "-- ");
package/dist/printSql.js CHANGED
@@ -5,12 +5,12 @@ var utils_1 = require("./utils");
5
5
  var transformMap_1 = require("./syntax/transformMap");
6
6
  var print_utils_1 = require("./print_utils");
7
7
  function printSql(path, options, oldPrint) {
8
- return printNode(path, options, createPrintFn(path, oldPrint));
8
+ return printNode(path, options, createPrintFn(path, oldPrint, options));
9
9
  }
10
10
  exports.printSql = printSql;
11
11
  var cachedPrintFn;
12
12
  var cachedPath;
13
- function createPrintFn(path, oldPrint) {
13
+ function createPrintFn(path, oldPrint, opts) {
14
14
  // The path parameter will reference the same AstPath instance
15
15
  // during the whole printing cycle.
16
16
  // So we can keep using the same print function as long as
@@ -21,15 +21,15 @@ function createPrintFn(path, oldPrint) {
21
21
  cachedPath = path;
22
22
  cachedPrintFn = (function (selector) {
23
23
  if ((0, utils_1.isArray)(selector)) {
24
- var node_1 = path.getValue();
24
+ var node_1 = path.node;
25
25
  return selector.filter(function (sel) { return (0, utils_1.isDefined)(node_1[sel]); }).map(oldPrint);
26
26
  }
27
27
  else {
28
28
  return oldPrint(selector);
29
29
  }
30
30
  });
31
- cachedPrintFn.spaced = function (selector) {
32
- var node = path.getValue();
31
+ cachedPrintFn.separated = function (separator, selector) {
32
+ var node = path.node;
33
33
  var docs = (0, utils_1.arrayWrap)(selector)
34
34
  .filter(function (sel) { return (0, utils_1.isDefined)(node[sel]); })
35
35
  .map(function (sel) { return [sel, oldPrint(sel)]; })
@@ -43,12 +43,17 @@ function createPrintFn(path, oldPrint) {
43
43
  var sel = _a[0], doc = _a[1];
44
44
  return ((0, utils_1.isArray)(node[sel]) ? (0, print_utils_1.join)(" ", doc) : doc);
45
45
  });
46
- return docs.length > 0 ? [(0, print_utils_1.join)(" ", docs)] : [];
46
+ return docs.length > 0 ? [(0, print_utils_1.join)(separator, docs)] : [];
47
+ };
48
+ cachedPrintFn.spaced = function (selector) { return cachedPrintFn.separated(" ", selector); };
49
+ cachedPrintFn.dynamicLine = function () {
50
+ var node = path.node;
51
+ return (0, print_utils_1.containsNewline)(node, opts) ? print_utils_1.hardline : print_utils_1.line;
47
52
  };
48
53
  return cachedPrintFn;
49
54
  }
50
55
  function printNode(path, options, print) {
51
- var node = path.getValue();
56
+ var node = path.node;
52
57
  if ((0, utils_1.isArray)(node)) {
53
58
  return path.map(print);
54
59
  }
@@ -3,11 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.alterTableMap = void 0;
4
4
  var print_utils_1 = require("../print_utils");
5
5
  exports.alterTableMap = {
6
- alter_table_stmt: function (print) { return [
7
- print.spaced(["alterTableKw", "ifExistsKw", "table"]),
8
- print_utils_1.hardline,
9
- print("actions"),
10
- ]; },
6
+ alter_table_stmt: function (print) {
7
+ return (0, print_utils_1.group)([
8
+ print.spaced(["alterTableKw", "ifExistsKw", "table"]),
9
+ print.dynamicLine(),
10
+ print("actions"),
11
+ ]);
12
+ },
11
13
  alter_action_rename_table: function (print) { return print.spaced(["renameKw", "newName"]); },
12
14
  alter_action_rename_column: function (print) {
13
15
  return print.spaced(["renameKw", "ifExistsKw", "oldName", "toKw", "newName"]);
@@ -16,19 +18,45 @@ exports.alterTableMap = {
16
18
  return print.spaced(["addKw", "ifNotExistsKw", "column"]);
17
19
  },
18
20
  alter_action_drop_column: function (print) {
19
- return print.spaced(["dropKw", "ifExistsKw", "column"]);
21
+ return print.spaced(["dropKw", "ifExistsKw", "column", "behaviorKw"]);
20
22
  },
21
23
  alter_action_set_options: function (print) { return print.spaced(["setKw", "options"]); },
22
24
  alter_action_set_default_collate: function (print) {
23
25
  return print.spaced(["setDefaultCollateKw", "collation"]);
24
26
  },
25
- alter_action_alter_column: function (print) { return [
26
- print.spaced(["alterKw", "ifExistsKw", "column"]),
27
- print_utils_1.hardline,
28
- print("action"),
29
- ]; },
27
+ alter_action_add_constraint: function (print) {
28
+ return print.spaced(["addKw", "constraint"]);
29
+ },
30
+ alter_action_drop_constraint: function (print) {
31
+ return print.spaced([
32
+ "dropConstraintKw",
33
+ "ifExistsKw",
34
+ "constraint",
35
+ "behaviorKw",
36
+ ]);
37
+ },
38
+ alter_action_alter_constraint: function (print) {
39
+ return print.spaced(["alterConstraintKw", "constraint", "modifiers"]);
40
+ },
41
+ alter_action_rename_constraint: function (print) {
42
+ return print.spaced(["renameConstraintKw", "oldName", "toKw", "newName"]);
43
+ },
44
+ alter_action_validate_constraint: function (print) {
45
+ return print.spaced(["validateConstraintKw", "constraint"]);
46
+ },
47
+ alter_action_set_visible: function (print) { return print.spaced("setVisibleKw"); },
48
+ alter_action_set_invisible: function (print) { return print.spaced("setInvisibleKw"); },
49
+ // ALTER COLUMN
50
+ alter_action_alter_column: function (print) {
51
+ return (0, print_utils_1.group)([
52
+ print.spaced(["alterKw", "ifExistsKw", "column"]),
53
+ print.dynamicLine(),
54
+ print("action"),
55
+ ]);
56
+ },
30
57
  alter_action_set_default: function (print) { return print.spaced(["setDefaultKw", "expr"]); },
31
58
  alter_action_drop_default: function (print) { return print.spaced("dropDefaultKw"); },
59
+ alter_action_set_not_null: function (print) { return print.spaced("setNotNullKw"); },
32
60
  alter_action_drop_not_null: function (print) { return print.spaced("dropNotNullKw"); },
33
61
  alter_action_set_data_type: function (print) {
34
62
  return print.spaced(["setDataTypeKw", "dataType"]);
@@ -2,14 +2,15 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.baseMap = void 0;
4
4
  exports.baseMap = {
5
+ /** cst-ignore: name */
5
6
  keyword: function (print, node, path, options) {
6
7
  switch (options.sqlKeywordCase) {
7
8
  case "preserve":
8
- return path.getValue().text;
9
+ return path.node.text;
9
10
  case "upper":
10
- return path.getValue().text.toUpperCase();
11
+ return path.node.text.toUpperCase();
11
12
  case "lower":
12
- return path.getValue().text.toLowerCase();
13
+ return path.node.text.toLowerCase();
13
14
  }
14
15
  },
15
16
  all_columns: function () { return "*"; },
@@ -1,8 +1,18 @@
1
1
  "use strict";
2
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
3
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
4
+ if (ar || !(i in from)) {
5
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
6
+ ar[i] = from[i];
7
+ }
8
+ }
9
+ return to.concat(ar || Array.prototype.slice.call(from));
10
+ };
2
11
  Object.defineProperty(exports, "__esModule", { value: true });
3
12
  exports.constraintMap = void 0;
4
13
  var print_utils_1 = require("../print_utils");
5
14
  exports.constraintMap = {
15
+ /** cst-ignore: constraint, modifiers */
6
16
  constraint: function (print, node) {
7
17
  if (node.name) {
8
18
  return (0, print_utils_1.group)([
@@ -15,26 +25,24 @@ exports.constraintMap = {
15
25
  }
16
26
  },
17
27
  constraint_name: function (print) { return print.spaced(["constraintKw", "name"]); },
18
- constraint_deferrable: function (print) {
19
- return print.spaced(["deferrableKw", "initiallyKw"]);
20
- },
28
+ constraint_modifier: function (print) { return print.spaced("kw"); },
21
29
  constraint_null: function (print) { return print("nullKw"); },
22
- constraint_not_null: function (print) {
23
- return (0, print_utils_1.group)(print.spaced(["notNullKw", "onConflict"]));
24
- },
30
+ constraint_not_null: function (print) { return (0, print_utils_1.group)(print.spaced(["notNullKw", "clauses"])); },
25
31
  constraint_default: function (print) { return (0, print_utils_1.group)(print.spaced(["defaultKw", "expr"])); },
26
32
  constraint_primary_key: function (print) {
27
- return (0, print_utils_1.group)(print.spaced(["primaryKeyKw", "direction", "columns", "onConflict"]));
33
+ return (0, print_utils_1.group)(print.spaced(["primaryKeyKw", "direction", "columns", "clauses"]));
28
34
  },
29
35
  constraint_unique: function (print) {
30
- return (0, print_utils_1.group)(print.spaced(["uniqueKw", "columns", "onConflict"]));
36
+ return (0, print_utils_1.group)(print.spaced(["uniqueKw", "columns", "nullsKw", "clauses"]));
37
+ },
38
+ constraint_check: function (print) {
39
+ return (0, print_utils_1.group)(print.spaced(["checkKw", "expr", "clauses"]));
31
40
  },
32
- constraint_check: function (print) { return (0, print_utils_1.group)(print.spaced(["checkKw", "expr"])); },
33
41
  constraint_collate: function (print) {
34
42
  return (0, print_utils_1.group)(print.spaced(["collateKw", "collation"]));
35
43
  },
36
44
  constraint_foreign_key: function (print) {
37
- return (0, print_utils_1.group)(print.spaced(["foreignKeyKw", "columns", "references"]));
45
+ return (0, print_utils_1.group)(print.spaced(["foreignKeyKw", "indexName", "columns", "references"]));
38
46
  },
39
47
  references_specification: function (print, node) {
40
48
  var baseDoc = print.spaced(["referencesKw", "table", "columns"]);
@@ -48,11 +56,17 @@ exports.constraintMap = {
48
56
  return baseDoc;
49
57
  }
50
58
  },
51
- referential_action: function (print) { return print.spaced(["onKw", "eventKw", "actionKw"]); },
59
+ index_specification: function (print) {
60
+ return print.spaced(["expr", "opclass", "direction", "nullHandlingKw"]);
61
+ },
62
+ referential_action: function (print) {
63
+ return print.spaced(["onKw", "eventKw", "actionKw", "columns"]);
64
+ },
52
65
  referential_match: function (print) { return print.spaced(["matchKw", "typeKw"]); },
53
66
  constraint_generated: function (print) {
54
67
  return print.spaced(["generatedKw", "asKw", "expr", "storageKw"]);
55
68
  },
69
+ identity_column: function (print) { return print("identityKw"); },
56
70
  constraint_auto_increment: function (print) { return print("autoIncrementKw"); },
57
71
  on_conflict_clause: function (print) { return print.spaced(["onConflictKw", "resolutionKw"]); },
58
72
  constraint_comment: function (print) { return print.spaced(["commentKw", "value"]); },
@@ -67,12 +81,29 @@ exports.constraintMap = {
67
81
  constraint_engine_attribute: function (print, node) {
68
82
  return (0, print_utils_1.join)(node.hasEq ? " = " : " ", print(["engineAttributeKw", "value"]));
69
83
  },
84
+ constraint_compression: function (print) { return print.spaced(["compressionKw", "method"]); },
85
+ constraint_exclude: function (print, node) {
86
+ return (0, print_utils_1.group)([
87
+ print("excludeKw"),
88
+ (0, print_utils_1.indent)([
89
+ print_utils_1.line,
90
+ (0, print_utils_1.join)(print_utils_1.line, __spreadArray([
91
+ print.separated(print_utils_1.line, ["using", "params"])
92
+ ], print("clauses"), true)),
93
+ ]),
94
+ ]);
95
+ },
96
+ exclusion_param: function (print) { return print.spaced(["index", "withKw", "operator"]); },
97
+ index_include_clause: function (print) { return print.spaced(["includeKw", "columns"]); },
98
+ index_tablespace_clause: function (print) {
99
+ return print.spaced(["usingIndexTablespaceKw", "name"]);
100
+ },
70
101
  };
71
102
  var printUnnamedConstraint = function (print, node) {
72
- if (node.deferrable) {
103
+ if (node.modifiers.length > 0) {
73
104
  return (0, print_utils_1.group)([
74
105
  print("constraint"),
75
- (0, print_utils_1.indent)([print_utils_1.hardline, print("deferrable")]),
106
+ (0, print_utils_1.indent)([print_utils_1.line, print.spaced("modifiers")]),
76
107
  ]);
77
108
  }
78
109
  else {
@@ -13,6 +13,7 @@ exports.createTableMap = void 0;
13
13
  var node_utils_1 = require("../node_utils");
14
14
  var print_utils_1 = require("../print_utils");
15
15
  exports.createTableMap = {
16
+ /** cst-ignore: clauses */
16
17
  create_table_stmt: function (print, node) {
17
18
  var rest = [];
18
19
  for (var _i = 2; _i < arguments.length; _i++) {
@@ -22,21 +23,21 @@ exports.createTableMap = {
22
23
  print.spaced([
23
24
  "createKw",
24
25
  "orReplaceKw",
25
- "temporaryKw",
26
- "externalKw",
27
- "snapshotKw",
28
- "virtualKw",
26
+ "kind",
29
27
  "tableKw",
30
28
  "ifNotExistsKw",
31
29
  "name",
30
+ "partitionOf",
31
+ "ofType",
32
32
  "columns",
33
33
  ]),
34
34
  printClauses.apply(void 0, __spreadArray([print, node], rest, false)),
35
35
  node.options ? [print_utils_1.line, (0, print_utils_1.group)(print("options"))] : [],
36
36
  ];
37
37
  },
38
+ table_kind: function (print) { return print.spaced("kindKw"); },
38
39
  column_definition: function (print) {
39
- return print.spaced(["name", "dataType", "constraints"]);
40
+ return print.spaced(["name", "dataType", "withOptionsKw", "constraints"]);
40
41
  },
41
42
  table_option: function (print, node) {
42
43
  if (node.value && node.hasEq) {
@@ -49,13 +50,53 @@ exports.createTableMap = {
49
50
  return print.spaced("name");
50
51
  }
51
52
  },
52
- create_table_like_clause: function (print) { return print.spaced(["likeKw", "name"]); },
53
+ create_table_like_clause: function (print) {
54
+ return print.spaced(["likeKw", "name", "options"]);
55
+ },
56
+ table_like_option: function (print) {
57
+ return print.spaced(["includingOrExcludingKw", "optionKw"]);
58
+ },
53
59
  create_table_copy_clause: function (print) { return print.spaced(["copyKw", "name"]); },
54
60
  create_table_clone_clause: function (print) { return print.spaced(["cloneKw", "table"]); },
55
61
  with_partition_columns_clause: function (print) {
56
62
  return print.spaced(["withPartitionColumnsKw", "columns"]);
57
63
  },
58
64
  create_table_using_clause: function (print) { return print.spaced(["usingKw", "module"]); },
65
+ create_table_inherits_clause: function (print) {
66
+ return print.spaced(["inheritsKw", "tables"]);
67
+ },
68
+ create_table_partition_by_clause: function (print) {
69
+ return print.spaced(["partitionByKw", "strategyKw", "columns"]);
70
+ },
71
+ create_table_partition_of_clause: function (print) {
72
+ return print.spaced(["partitionOfKw", "table"]);
73
+ },
74
+ create_table_partition_bound_clause: function (print) {
75
+ return print.spaced(["forValuesKw", "bound"]);
76
+ },
77
+ partition_bound_in: function (print) { return print.spaced(["inKw", "values"]); },
78
+ partition_bound_from_to: function (print) {
79
+ return print.spaced(["fromKw", "from", "toKw", "to"]);
80
+ },
81
+ partition_bound_minvalue: function (print) { return print.spaced("minvalueKw"); },
82
+ partition_bound_maxvalue: function (print) { return print.spaced("maxvalueKw"); },
83
+ partition_bound_with: function (print) { return print.spaced(["withKw", "values"]); },
84
+ partition_bound_modulus: function (print) { return print.spaced(["modulusKw", "value"]); },
85
+ partition_bound_remainder: function (print) { return print.spaced(["remainderKw", "value"]); },
86
+ create_table_default_partition_clause: function (print) { return print.spaced("defaultKw"); },
87
+ create_table_of_type_clause: function (print) { return print.spaced(["ofKw", "typeName"]); },
88
+ using_access_method_clause: function (print) { return print.spaced(["usingKw", "method"]); },
89
+ create_table_tablespace_clause: function (print) {
90
+ return print.spaced(["tablespaceKw", "name"]);
91
+ },
92
+ with_storage_parameters_clause: function (print) {
93
+ return print.spaced(["withKw", "options"]);
94
+ },
95
+ create_table_without_oids_clause: function (print) { return print.spaced("withoutOidsKw"); },
96
+ create_table_on_commit_clause: function (print) {
97
+ return print.spaced(["onCommitKw", "actionKw"]);
98
+ },
99
+ create_table_with_data_clause: function (print) { return print.spaced("withDataKw"); },
59
100
  };
60
101
  var printClauses = function (print, node) {
61
102
  if (node.clauses.length === 1 && (0, node_utils_1.isAsClause)(node.clauses[0])) {
@@ -4,17 +4,17 @@ exports.dclMap = void 0;
4
4
  var print_utils_1 = require("../print_utils");
5
5
  exports.dclMap = {
6
6
  grant_stmt: function (print) {
7
- return (0, print_utils_1.join)(print_utils_1.hardline, [
7
+ return (0, print_utils_1.group)((0, print_utils_1.join)(print.dynamicLine(), [
8
8
  (0, print_utils_1.group)([print("grantKw"), (0, print_utils_1.indent)([print_utils_1.line, print("roles")])]),
9
9
  (0, print_utils_1.group)(print.spaced(["onKw", "resourceType", "resourceName"])),
10
10
  (0, print_utils_1.group)([print("toKw"), (0, print_utils_1.indent)([print_utils_1.line, print("users")])]),
11
- ]);
11
+ ]));
12
12
  },
13
13
  revoke_stmt: function (print) {
14
- return (0, print_utils_1.join)(print_utils_1.hardline, [
14
+ return (0, print_utils_1.group)((0, print_utils_1.join)(print.dynamicLine(), [
15
15
  (0, print_utils_1.group)([print("revokeKw"), (0, print_utils_1.indent)([print_utils_1.line, print("roles")])]),
16
16
  (0, print_utils_1.group)(print.spaced(["onKw", "resourceType", "resourceName"])),
17
17
  (0, print_utils_1.group)([print("fromKw"), (0, print_utils_1.indent)([print_utils_1.line, print("users")])]),
18
- ]);
18
+ ]));
19
19
  },
20
20
  };
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.deleteMap = void 0;
4
4
  var print_utils_1 = require("../print_utils");
5
5
  exports.deleteMap = {
6
- delete_stmt: function (print) { return (0, print_utils_1.join)(print_utils_1.hardline, print("clauses")); },
6
+ delete_stmt: function (print) { return (0, print_utils_1.group)((0, print_utils_1.join)(print.dynamicLine(), print("clauses"))); },
7
7
  delete_clause: function (print) {
8
8
  return print.spaced(["deleteKw", "modifiers", "fromKw", "tables"]);
9
9
  },
@@ -1,3 +1,3 @@
1
1
  import { AllPostgresqlNodes } from "sql-parser-cst";
2
2
  import { CstToDocMap } from "../../CstToDocMap";
3
- export declare const postgresqlMap: Partial<CstToDocMap<AllPostgresqlNodes>>;
3
+ export declare const postgresqlMap: CstToDocMap<AllPostgresqlNodes>;
@@ -4,4 +4,5 @@ exports.postgresqlMap = void 0;
4
4
  exports.postgresqlMap = {
5
5
  postgresql_operator_expr: function (print) { return print(["operatorKw", "expr"]); },
6
6
  postgresql_operator: function (print) { return print("operator"); },
7
+ postgresql_operator_class: function (print) { return print("name"); },
7
8
  };
@@ -5,11 +5,11 @@ exports.dropTableMap = {
5
5
  drop_table_stmt: function (print) {
6
6
  return print.spaced([
7
7
  "dropKw",
8
- "externalKw",
9
- "snapshotKw",
8
+ "kind",
10
9
  "tableKw",
11
10
  "ifExistsKw",
12
11
  "tables",
12
+ "behaviorKw",
13
13
  ]);
14
14
  },
15
15
  };
@@ -5,7 +5,7 @@ var print_utils_1 = require("../print_utils");
5
5
  exports.explainMap = {
6
6
  explain_stmt: function (print) {
7
7
  return (0, print_utils_1.group)([
8
- print.spaced(["explainKw", "queryPlanKw"]),
8
+ print.spaced(["explainKw", "analyzeKw", "queryPlanKw"]),
9
9
  (0, print_utils_1.indent)([print_utils_1.line, print("statement")]),
10
10
  ]);
11
11
  },
@@ -115,7 +115,12 @@ exports.exprMap = {
115
115
  over_arg: function (print) { return print.spaced(["overKw", "window"]); },
116
116
  having_arg: function (print) { return print.spaced(["havingKw", "minMaxKw", "expr"]); },
117
117
  named_arg: function (print) {
118
- return (0, print_utils_1.group)([print("name"), " ", "=>", (0, print_utils_1.indent)([print_utils_1.line, print("value")])]);
118
+ return (0, print_utils_1.group)([
119
+ print("name"),
120
+ " ",
121
+ print("operator"),
122
+ (0, print_utils_1.indent)([print_utils_1.line, print("value")]),
123
+ ]);
119
124
  },
120
125
  cast_expr: function (print) { return print(["castKw", "args"]); },
121
126
  cast_arg: function (print) { return print.spaced(["expr", "asKw", "dataType", "format"]); },
@@ -145,10 +150,15 @@ exports.exprMap = {
145
150
  return print.spaced(["matchKw", "columns", "againstKw", "args"]);
146
151
  },
147
152
  full_text_match_args: function (print) { return print.spaced(["expr", "modifier"]); },
153
+ /** cst-ignore: value */
148
154
  number_literal: function (print) { return print("text"); },
155
+ /** cst-ignore: value */
149
156
  boolean_literal: function (print) { return print("valueKw"); },
157
+ /** cst-ignore: value */
150
158
  string_literal: function (print) { return print("text"); },
159
+ /** cst-ignore: value */
151
160
  blob_literal: function (print) { return print("text"); },
161
+ /** cst-ignore: value */
152
162
  null_literal: function (print) { return print("nullKw"); },
153
163
  numeric_literal: function (print) { return print.spaced(["numericKw", "string"]); },
154
164
  bignumeric_literal: function (print) { return print.spaced(["bignumericKw", "string"]); },
@@ -158,7 +168,9 @@ exports.exprMap = {
158
168
  timestamp_literal: function (print) { return print.spaced(["timestampKw", "string"]); },
159
169
  json_literal: function (print) { return print.spaced(["jsonKw", "string"]); },
160
170
  jsonb_literal: function (print) { return print.spaced(["jsonbKw", "string"]); },
171
+ /** cst-ignore: name */
161
172
  identifier: function (print) { return print("text"); },
173
+ /** cst-ignore: name */
162
174
  variable: function (print) { return print("text"); },
163
175
  parameter: function (print) { return print("text"); },
164
176
  };
@@ -12,8 +12,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.indexMap = void 0;
13
13
  var print_utils_1 = require("../print_utils");
14
14
  exports.indexMap = {
15
- create_index_stmt: function (print, node) {
16
- return (0, print_utils_1.join)(print_utils_1.hardline, __spreadArray([
15
+ create_index_stmt: function (print) {
16
+ return (0, print_utils_1.group)((0, print_utils_1.join)(print.dynamicLine(), __spreadArray([
17
17
  print.spaced([
18
18
  "createKw",
19
19
  "indexTypeKw",
@@ -24,7 +24,7 @@ exports.indexMap = {
24
24
  "table",
25
25
  "columns",
26
26
  ])
27
- ], (node.clauses.length > 0 ? [(0, print_utils_1.join)(print_utils_1.hardline, print("clauses"))] : []), true));
27
+ ], print("clauses"), true)));
28
28
  },
29
29
  drop_index_stmt: function (print) {
30
30
  return print.spaced([
@@ -3,33 +3,48 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.insertMap = void 0;
4
4
  var print_utils_1 = require("../print_utils");
5
5
  exports.insertMap = {
6
- insert_stmt: function (print) { return (0, print_utils_1.join)(print_utils_1.hardline, print("clauses")); },
6
+ insert_stmt: function (print) { return (0, print_utils_1.group)((0, print_utils_1.join)(print.dynamicLine(), print("clauses"))); },
7
7
  insert_clause: function (print, node) {
8
8
  return (0, print_utils_1.group)([
9
9
  print.spaced(["insertKw", "modifiers", "orAction", "intoKw", "table"]),
10
- node.columns ? (0, print_utils_1.indent)([print_utils_1.hardline, print("columns")]) : [],
10
+ node.columns ? (0, print_utils_1.indent)([print.dynamicLine(), print("columns")]) : [],
11
11
  ]);
12
12
  },
13
13
  values_clause: function (print) {
14
- return (0, print_utils_1.group)([print("valuesKw"), (0, print_utils_1.indent)([print_utils_1.hardline, print("values")])]);
14
+ return (0, print_utils_1.group)([print("valuesKw"), (0, print_utils_1.indent)([print.dynamicLine(), print("values")])]);
15
15
  },
16
16
  or_alternate_action: function (print) { return print.spaced(["orKw", "actionKw"]); },
17
17
  default: function (print) { return print("defaultKw"); },
18
18
  default_values: function (print) { return print.spaced("defaultValuesKw"); },
19
19
  upsert_clause: function (print) {
20
- return print.spaced(["onConflictKw", "columns", "where", "doKw", "action"]);
20
+ return print.spaced(["onConflictKw", "conflictTarget", "where", "doKw", "action"]);
21
+ },
22
+ conflict_target_on_constraint: function (print) {
23
+ return print.spaced(["onConstraintKw", "constraint"]);
21
24
  },
22
25
  upsert_action_nothing: function (print) { return print("nothingKw"); },
23
- upsert_action_update: function (print) { return [
24
- print("updateKw"),
25
- (0, print_utils_1.indent)([print_utils_1.hardline, (0, print_utils_1.join)(print_utils_1.hardline, print(["set", "where"]))]),
26
- ]; },
27
- row_alias_clause: function (print, node) { return [
28
- print.spaced(["asKw", "rowAlias"]),
29
- node.columnAliases ? (0, print_utils_1.indent)([print_utils_1.hardline, print("columnAliases")]) : [],
30
- ]; },
31
- on_duplicate_key_update_clause: function (print) { return [
32
- print.spaced("onDuplicateKeyUpdateKw"),
33
- (0, print_utils_1.indent)([print_utils_1.hardline, print("assignments")]),
34
- ]; },
26
+ upsert_action_update: function (print) {
27
+ return (0, print_utils_1.group)([
28
+ print("updateKw"),
29
+ (0, print_utils_1.indent)([
30
+ print.dynamicLine(),
31
+ (0, print_utils_1.join)(print.dynamicLine(), print(["set", "where"])),
32
+ ]),
33
+ ]);
34
+ },
35
+ row_alias_clause: function (print, node) {
36
+ return (0, print_utils_1.group)([
37
+ print.spaced(["asKw", "rowAlias"]),
38
+ node.columnAliases
39
+ ? (0, print_utils_1.indent)([print.dynamicLine(), print("columnAliases")])
40
+ : [],
41
+ ]);
42
+ },
43
+ on_duplicate_key_update_clause: function (print) {
44
+ return (0, print_utils_1.group)([
45
+ print.spaced("onDuplicateKeyUpdateKw"),
46
+ (0, print_utils_1.indent)([print.dynamicLine(), print("assignments")]),
47
+ ]);
48
+ },
49
+ overriding_clause: function (print) { return print.spaced("overridingKw"); },
35
50
  };
@@ -1,23 +1,15 @@
1
1
  "use strict";
2
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
3
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
4
- if (ar || !(i in from)) {
5
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
6
- ar[i] = from[i];
7
- }
8
- }
9
- return to.concat(ar || Array.prototype.slice.call(from));
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.mergeMap = void 0;
13
4
  var print_utils_1 = require("../print_utils");
14
5
  exports.mergeMap = {
15
- merge_stmt: function (print) {
16
- return (0, print_utils_1.join)(print_utils_1.line, __spreadArray([
6
+ merge_stmt: function (print) { return (0, print_utils_1.join)(print_utils_1.line, print("clauses")); },
7
+ merge_clause: function (print) {
8
+ return (0, print_utils_1.join)(print_utils_1.line, [
17
9
  print.spaced(["mergeKw", "intoKw", "target"]),
18
10
  print.spaced(["usingKw", "source"]),
19
- (0, print_utils_1.group)([print("onKw"), (0, print_utils_1.indent)([print_utils_1.line, print("condition")])])
20
- ], print("clauses").map(function (clause) { return (0, print_utils_1.group)(clause); }), true));
11
+ (0, print_utils_1.group)([print("onKw"), (0, print_utils_1.indent)([print_utils_1.line, print("condition")])]),
12
+ ]);
21
13
  },
22
14
  merge_when_clause: function (print, node) { return [
23
15
  (0, print_utils_1.group)([
@@ -35,8 +27,9 @@ exports.mergeMap = {
35
27
  node.columns ? (0, print_utils_1.indent)([print_utils_1.hardline, print("columns")]) : [],
36
28
  ]),
37
29
  print_utils_1.line,
38
- (0, print_utils_1.group)(print("values")),
30
+ (0, print_utils_1.join)(print_utils_1.hardline, print("clauses")),
39
31
  ]; },
40
32
  merge_action_insert_row_clause: function (print) { return print("rowKw"); },
41
33
  merge_action_update: function (print) { return print.spaced(["updateKw", "set"]); },
34
+ merge_action_do_nothing: function (print) { return print.spaced(["doNothingKw"]); },
42
35
  };
@@ -0,0 +1,3 @@
1
+ import { AllOtherClauses } from "sql-parser-cst";
2
+ import { CstToDocMap } from "../CstToDocMap";
3
+ export declare const otherClausesMap: CstToDocMap<AllOtherClauses>;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.otherClausesMap = void 0;
4
+ var print_utils_1 = require("../print_utils");
5
+ exports.otherClausesMap = {
6
+ // CLUSTER BY clause
7
+ cluster_by_clause: function (print) {
8
+ return (0, print_utils_1.group)([print.spaced("clusterByKw"), (0, print_utils_1.indent)([print_utils_1.line, print("columns")])]);
9
+ },
10
+ // RETURNING clause
11
+ returning_clause: function (print) {
12
+ return (0, print_utils_1.group)([print("returningKw"), (0, print_utils_1.indent)([print_utils_1.line, print("columns")])]);
13
+ },
14
+ // WHERE CURRENT OF clause
15
+ where_current_of_clause: function (print) {
16
+ return print.spaced(["whereCurrentOfKw", "cursor"]);
17
+ },
18
+ };
@@ -108,7 +108,7 @@ exports.proceduralLanguageMap = {
108
108
  // CALL
109
109
  call_stmt: function (print) { return print.spaced(["callKw", "func"]); },
110
110
  // RETURN
111
- return_stmt: function (print) { return print("returnKw"); },
111
+ return_stmt: function (print) { return print.spaced(["returnKw", "expr"]); },
112
112
  // RAISE
113
113
  raise_stmt: function (print) { return print.spaced(["raiseKw", "message"]); },
114
114
  raise_message: function (print) { return [
@@ -0,0 +1,3 @@
1
+ import { AllRenameTableNodes } from "sql-parser-cst";
2
+ import { CstToDocMap } from "../CstToDocMap";
3
+ export declare const renameTableMap: CstToDocMap<AllRenameTableNodes>;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.renameTableMap = void 0;
4
+ var print_utils_1 = require("../print_utils");
5
+ exports.renameTableMap = {
6
+ rename_table_stmt: function (print) {
7
+ return (0, print_utils_1.group)([
8
+ print.spaced(["renameKw", "tableKw"]),
9
+ (0, print_utils_1.indent)([print_utils_1.line, print("actions")]),
10
+ ]);
11
+ },
12
+ rename_action: function (print) { return print.spaced(["from", "toKw", "to"]); },
13
+ };
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
3
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
4
- if (ar || !(i in from)) {
5
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
6
- ar[i] = from[i];
7
- }
8
- }
9
- return to.concat(ar || Array.prototype.slice.call(from));
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.selectMap = void 0;
13
4
  var utils_1 = require("../utils");
@@ -16,10 +7,7 @@ exports.selectMap = {
16
7
  compound_select_stmt: function (print) {
17
8
  return (0, print_utils_1.join)(print_utils_1.hardline, [print("left"), print.spaced("operator"), print("right")]);
18
9
  },
19
- select_stmt: function (print, node, path, opts) {
20
- var lineType = (0, print_utils_1.containsNewline)(node, opts) ? print_utils_1.hardline : print_utils_1.line;
21
- return (0, print_utils_1.group)((0, print_utils_1.join)(lineType, print("clauses")));
22
- },
10
+ select_stmt: function (print) { return (0, print_utils_1.group)((0, print_utils_1.join)(print.dynamicLine(), print("clauses"))); },
23
11
  // WITH clause
24
12
  with_clause: function (print) {
25
13
  return (0, print_utils_1.group)([
@@ -33,7 +21,7 @@ exports.selectMap = {
33
21
  print.spaced(["asKw", "materializedKw", "expr"]),
34
22
  (0, print_utils_1.group)([
35
23
  node.search || node.cycle
36
- ? (0, print_utils_1.indent)([print_utils_1.line, (0, print_utils_1.join)(print_utils_1.line, print(["search", "cycle"]))])
24
+ ? (0, print_utils_1.indent)([print_utils_1.line, print.separated(print_utils_1.line, ["search", "cycle"])])
37
25
  : [],
38
26
  ]),
39
27
  ]; },
@@ -161,12 +149,7 @@ exports.selectMap = {
161
149
  order_by_clause: function (print, node) {
162
150
  return (0, print_utils_1.group)([
163
151
  print.spaced("orderByKw"),
164
- (0, print_utils_1.indent)([
165
- print_utils_1.line,
166
- (0, print_utils_1.join)(print_utils_1.line, __spreadArray([
167
- print("specifications")
168
- ], (node.withRollupKw ? print.spaced("withRollupKw") : []), true)),
169
- ]),
152
+ (0, print_utils_1.indent)([print_utils_1.line, print.separated(print_utils_1.line, ["specifications", "withRollupKw"])]),
170
153
  ]);
171
154
  },
172
155
  sort_specification: function (print) {
@@ -181,12 +164,7 @@ exports.selectMap = {
181
164
  group_by_clause: function (print, node) {
182
165
  return (0, print_utils_1.group)([
183
166
  print.spaced(["groupByKw", "distinctKw"]),
184
- (0, print_utils_1.indent)([
185
- print_utils_1.line,
186
- (0, print_utils_1.join)(print_utils_1.line, __spreadArray([
187
- print("columns")
188
- ], (node.withRollupKw ? print.spaced("withRollupKw") : []), true)),
189
- ]),
167
+ (0, print_utils_1.indent)([print_utils_1.line, print.separated(print_utils_1.line, ["columns", "withRollupKw"])]),
190
168
  ]);
191
169
  },
192
170
  group_by_rollup: function (print) { return print(["rollupKw", "columns"]); },
@@ -201,10 +179,6 @@ exports.selectMap = {
201
179
  (0, print_utils_1.indent)([print_utils_1.line, print("specifications")]),
202
180
  ]);
203
181
  },
204
- // CLUSTER BY clause
205
- cluster_by_clause: function (print) {
206
- return (0, print_utils_1.group)([print.spaced("clusterByKw"), (0, print_utils_1.indent)([print_utils_1.line, print("columns")])]);
207
- },
208
182
  // HAVING clause
209
183
  having_clause: function (print) {
210
184
  return (0, print_utils_1.group)([print("havingKw"), (0, print_utils_1.indent)([print_utils_1.line, print("expr")])]);
@@ -213,11 +187,8 @@ exports.selectMap = {
213
187
  qualify_clause: function (print) {
214
188
  return (0, print_utils_1.group)([print("qualifyKw"), (0, print_utils_1.indent)([print_utils_1.line, print("expr")])]);
215
189
  },
216
- // RETURNING clause
217
- returning_clause: function (print) {
218
- return (0, print_utils_1.group)([print("returningKw"), (0, print_utils_1.indent)([print_utils_1.line, print("columns")])]);
219
- },
220
190
  // LIMIT clause
191
+ /** cst-ignore: count, offsetKw, offset */
221
192
  limit_clause: function (print, node) {
222
193
  return (0, print_utils_1.group)([
223
194
  print("limitKw"),
@@ -262,7 +233,7 @@ exports.selectMap = {
262
233
  },
263
234
  // INTO clause
264
235
  into_table_clause: function (print) {
265
- return print.spaced(["intoKw", "temporaryKw", "unloggedKw", "tableKw", "name"]);
236
+ return print.spaced(["intoKw", "kind", "tableKw", "name"]);
266
237
  },
267
238
  into_variables_clause: function (print) {
268
239
  return (0, print_utils_1.group)([print("intoKw"), (0, print_utils_1.indent)([print_utils_1.line, print("variables")])]);
@@ -1,3 +1,3 @@
1
1
  import { Node } from "sql-parser-cst";
2
2
  import { CstToDocMap } from "../CstToDocMap";
3
- export declare const transformMap: Partial<CstToDocMap<Node>>;
3
+ export declare const transformMap: CstToDocMap<Node>;
@@ -29,6 +29,8 @@ var function_1 = require("./function");
29
29
  var index_1 = require("./index");
30
30
  var insert_1 = require("./insert");
31
31
  var merge_1 = require("./merge");
32
+ var other_clauses_1 = require("./other_clauses");
33
+ var rename_table_1 = require("./rename_table");
32
34
  var prepared_statements_1 = require("./prepared_statements");
33
35
  var procedural_language_1 = require("./procedural_language");
34
36
  var procedure_1 = require("./procedure");
@@ -45,4 +47,4 @@ var bigquery_1 = require("./dialects/bigquery");
45
47
  var mysql_1 = require("./dialects/mysql");
46
48
  var sqlite_1 = require("./dialects/sqlite");
47
49
  var postgresql_1 = require("./dialects/postgresql");
48
- exports.transformMap = __assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign({}, alias_1.aliasMap), alter_table_1.alterTableMap), analyze_1.analyzeMap), base_1.baseMap), constraint_1.constraintMap), create_table_1.createTableMap), data_type_1.dataTypeMap), dcl_1.dclMap), delete_1.deleteMap), drop_table_1.dropTableMap), explain_1.explainMap), expr_1.exprMap), frame_1.frameMap), function_1.functionMap), index_1.indexMap), insert_1.insertMap), merge_1.mergeMap), prepared_statements_1.preparedStatementsMap), proc_clause_1.procClauseMap), procedural_language_1.proceduralLanguageMap), procedure_1.procedureMap), program_1.programMap), schema_1.schemaMap), select_1.selectMap), transaction_1.transactionMap), trigger_1.triggerMap), truncate_1.truncateMap), update_1.updateMap), view_1.viewMap), bigquery_1.bigqueryMap), mysql_1.mysqlMap), postgresql_1.postgresqlMap), sqlite_1.sqliteMap);
50
+ exports.transformMap = __assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign({}, alias_1.aliasMap), alter_table_1.alterTableMap), analyze_1.analyzeMap), base_1.baseMap), constraint_1.constraintMap), create_table_1.createTableMap), data_type_1.dataTypeMap), dcl_1.dclMap), delete_1.deleteMap), drop_table_1.dropTableMap), explain_1.explainMap), expr_1.exprMap), frame_1.frameMap), function_1.functionMap), index_1.indexMap), insert_1.insertMap), merge_1.mergeMap), other_clauses_1.otherClausesMap), prepared_statements_1.preparedStatementsMap), proc_clause_1.procClauseMap), procedural_language_1.proceduralLanguageMap), procedure_1.procedureMap), program_1.programMap), rename_table_1.renameTableMap), schema_1.schemaMap), select_1.selectMap), transaction_1.transactionMap), trigger_1.triggerMap), truncate_1.truncateMap), update_1.updateMap), view_1.viewMap), bigquery_1.bigqueryMap), mysql_1.mysqlMap), postgresql_1.postgresqlMap), sqlite_1.sqliteMap);
@@ -22,7 +22,7 @@ exports.triggerMap = {
22
22
  "name",
23
23
  ]),
24
24
  print("event")
25
- ], (node.forEachRowKw ? [print.spaced(["forEachRowKw"])] : []), true), (node.condition ? [print(["condition"])] : []), true), [
25
+ ], print.spaced(["forEachRowKw"]), true), print(["condition"]), true), [
26
26
  print("body"),
27
27
  ], false));
28
28
  },
@@ -1,6 +1,19 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.truncateMap = void 0;
4
+ var print_utils_1 = require("../print_utils");
4
5
  exports.truncateMap = {
5
- truncate_stmt: function (print) { return print.spaced(["truncateKw", "tableKw", "table"]); },
6
+ truncate_stmt: function (print) {
7
+ return (0, print_utils_1.group)([
8
+ print.spaced(["truncateKw", "tableKw"]),
9
+ (0, print_utils_1.indent)([
10
+ print_utils_1.line,
11
+ print.separated(print_utils_1.line, [
12
+ "tables",
13
+ "restartOrContinueKw",
14
+ "cascadeOrRestrictKw",
15
+ ]),
16
+ ]),
17
+ ]);
18
+ },
6
19
  };
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.updateMap = void 0;
4
4
  var print_utils_1 = require("../print_utils");
5
5
  exports.updateMap = {
6
- update_stmt: function (print) { return (0, print_utils_1.join)(print_utils_1.hardline, print("clauses")); },
6
+ update_stmt: function (print) { return (0, print_utils_1.group)((0, print_utils_1.join)(print.dynamicLine(), print("clauses"))); },
7
7
  update_clause: function (print) {
8
8
  return print.spaced(["updateKw", "modifiers", "orAction", "tables"]);
9
9
  },
@@ -22,10 +22,24 @@ exports.viewMap = {
22
22
  ];
23
23
  },
24
24
  drop_view_stmt: function (print) {
25
- return print.spaced(["dropKw", "materializedKw", "viewKw", "ifExistsKw", "views"]);
25
+ return print.spaced([
26
+ "dropKw",
27
+ "materializedKw",
28
+ "viewKw",
29
+ "ifExistsKw",
30
+ "views",
31
+ "behaviorKw",
32
+ ]);
26
33
  },
27
34
  alter_view_stmt: function (print) { return [
28
- print.spaced(["alterKw", "materializedKw", "viewKw", "ifExistsKw", "name"]),
35
+ print.spaced([
36
+ "alterKw",
37
+ "materializedKw",
38
+ "viewKw",
39
+ "ifExistsKw",
40
+ "name",
41
+ "columns",
42
+ ]),
29
43
  print_utils_1.hardline,
30
44
  (0, print_utils_1.join)(print_utils_1.hardline, print("actions")),
31
45
  ]; },
@@ -4,12 +4,11 @@ exports.processAliasAs = void 0;
4
4
  var sql_parser_cst_1 = require("sql-parser-cst");
5
5
  // Adds AS keyword to aliases if none exists
6
6
  var processAliasAs = function (cst) {
7
- var mutateAliases = (0, sql_parser_cst_1.cstVisitor)({
7
+ (0, sql_parser_cst_1.cstVisitor)({
8
8
  alias: function (node) {
9
9
  node.asKw = node.asKw || { type: "keyword", name: "AS", text: "AS" };
10
10
  },
11
- });
12
- mutateAliases(cst);
11
+ })(cst);
13
12
  return cst;
14
13
  };
15
14
  exports.processAliasAs = processAliasAs;
@@ -0,0 +1,2 @@
1
+ import { Program } from "sql-parser-cst";
2
+ export declare const canonicKeywords: (cst: Program) => Program;
@@ -0,0 +1,66 @@
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)({
8
+ // Replaces TEMP with TEMPORARY
9
+ table_kind: function (node) {
10
+ if (Array.isArray(node.kindKw)) {
11
+ // TODO...
12
+ }
13
+ else {
14
+ if (node.kindKw.name === "TEMP") {
15
+ node.kindKw.name = "TEMPORARY";
16
+ node.kindKw.text = "TEMPORARY";
17
+ }
18
+ }
19
+ },
20
+ // Replaces MySQL SELECT DISTINCTROW with SELECT DISTINCT
21
+ select_distinct: function (node) {
22
+ if (node.distinctKw.name === "DISTINCTROW") {
23
+ node.distinctKw.name = "DISTINCT";
24
+ node.distinctKw.text = "DISTINCT";
25
+ }
26
+ },
27
+ // Replaces RENAME & RENAME AS with RENAME TO
28
+ alter_action_rename_table: function (node) {
29
+ if (Array.isArray(node.renameKw)) {
30
+ if (node.renameKw[1].name === "AS") {
31
+ node.renameKw[1].name = "TO";
32
+ node.renameKw[1].text = "TO";
33
+ }
34
+ }
35
+ else {
36
+ node.renameKw = [node.renameKw, (0, transformUtils_1.keyword)("TO")];
37
+ }
38
+ },
39
+ // Replaces INSERT with INSERT INTO
40
+ insert_clause: function (node) {
41
+ if (!node.intoKw) {
42
+ node.intoKw = (0, transformUtils_1.keyword)("INTO");
43
+ }
44
+ },
45
+ // Replaces MERGE with MERGE INTO
46
+ merge_clause: function (node) {
47
+ if (!node.intoKw) {
48
+ node.intoKw = (0, transformUtils_1.keyword)("INTO");
49
+ }
50
+ },
51
+ // Replaces DELETE with DELETE FROM
52
+ delete_clause: function (node) {
53
+ if (!node.fromKw) {
54
+ node.fromKw = (0, transformUtils_1.keyword)("FROM");
55
+ }
56
+ },
57
+ // Replaces TRUNCATE with TRUNCATE TABLE
58
+ truncate_stmt: function (node) {
59
+ if (!node.tableKw) {
60
+ node.tableKw = (0, transformUtils_1.keyword)("TABLE");
61
+ }
62
+ },
63
+ })(cst);
64
+ return cst;
65
+ };
66
+ exports.canonicKeywords = canonicKeywords;
@@ -0,0 +1,3 @@
1
+ import { Program } from "sql-parser-cst";
2
+ import { AllPrettierOptions } from "src/options";
3
+ export declare const canonicOperators: (cst: Program, originalText: string, options: AllPrettierOptions) => Program;
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.canonicOperators = void 0;
4
+ var sql_parser_cst_1 = require("sql-parser-cst");
5
+ var transformUtils_1 = require("./transformUtils");
6
+ var canonicOperators = function (cst, originalText, options) {
7
+ (0, sql_parser_cst_1.cstVisitor)({
8
+ binary_expr: function (node) {
9
+ // Replaces <> operator with !=
10
+ if (node.operator === "<>") {
11
+ node.operator = "!=";
12
+ }
13
+ // Replace MySQL && and || operators with AND and OR
14
+ if (options.parser === "mysql" || options.parser === "mariadb") {
15
+ if (node.operator === "&&") {
16
+ node.operator = (0, transformUtils_1.keyword)("AND");
17
+ }
18
+ if (node.operator === "||") {
19
+ node.operator = (0, transformUtils_1.keyword)("OR");
20
+ }
21
+ }
22
+ },
23
+ // Replaces PostgreSQL deprecated := operator with =>
24
+ named_arg: function (node) {
25
+ if (node.operator === ":=") {
26
+ node.operator = "=>";
27
+ }
28
+ },
29
+ })(cst);
30
+ return cst;
31
+ };
32
+ exports.canonicOperators = canonicOperators;
@@ -7,14 +7,13 @@ var utils_1 = require("../utils");
7
7
  // Removes trailing comma from SELECT clauses
8
8
  var stripTrailingCommas = function (cst) {
9
9
  // Trailing comma is represented as an empty element at the end of column list
10
- var removeLastEmptyColumn = (0, sql_parser_cst_1.cstVisitor)({
10
+ (0, sql_parser_cst_1.cstVisitor)({
11
11
  select_clause: function (node) {
12
12
  if (node.columns && (0, node_utils_1.isEmpty)((0, utils_1.last)(node.columns.items))) {
13
13
  node.columns.items = node.columns.items.slice(0, -1);
14
14
  }
15
15
  },
16
- });
17
- removeLastEmptyColumn(cst);
16
+ })(cst);
18
17
  return cst;
19
18
  };
20
19
  exports.stripTrailingCommas = stripTrailingCommas;
@@ -1,2 +1,5 @@
1
1
  import { Program } from "sql-parser-cst";
2
- export declare const transformCst: (cst: Program, originalText: string) => Program;
2
+ import { AllPrettierOptions } from "src/options";
3
+ export declare const transformCst: TransformFn;
4
+ type TransformFn = (cst: Program, originalText: string, options: AllPrettierOptions) => Program;
5
+ export {};
@@ -5,9 +5,19 @@ var comments_1 = require("./comments");
5
5
  var aliasAs_1 = require("./aliasAs");
6
6
  var stripTrailingCommas_1 = require("./stripTrailingCommas");
7
7
  var addFinalSemicolon_1 = require("./addFinalSemicolon");
8
- // Note that we first perform moveCommentsToRoot transform,
9
- // so we don't need to worry about comments interfering with other transforms
10
- var transformCst = function (cst, originalText) {
11
- return (0, addFinalSemicolon_1.addFinalSemicolon)((0, stripTrailingCommas_1.stripTrailingCommas)((0, aliasAs_1.processAliasAs)((0, comments_1.moveCommentsToRoot)(cst))), originalText);
8
+ var canonicKeywords_1 = require("./canonicKeywords");
9
+ var canonicOperators_1 = require("./canonicOperators");
10
+ var transformCst = function (cst, originalText, options) {
11
+ var transforms = [
12
+ // Note that we first perform moveCommentsToRoot transform,
13
+ // so we don't need to worry about comments interfering with other transforms
14
+ comments_1.moveCommentsToRoot,
15
+ stripTrailingCommas_1.stripTrailingCommas,
16
+ addFinalSemicolon_1.addFinalSemicolon,
17
+ ];
18
+ if (options.sqlCanonicalSyntax) {
19
+ transforms.push(aliasAs_1.processAliasAs, canonicOperators_1.canonicOperators, canonicKeywords_1.canonicKeywords);
20
+ }
21
+ return transforms.reduce(function (cst, transform) { return transform(cst, originalText, options); }, cst);
12
22
  };
13
23
  exports.transformCst = transformCst;
@@ -0,0 +1,2 @@
1
+ import { Keyword } from "sql-parser-cst";
2
+ export declare function keyword<T extends string>(name: T): Keyword<T>;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.keyword = void 0;
4
+ function keyword(name) {
5
+ return { type: "keyword", name: name, text: name };
6
+ }
7
+ exports.keyword = keyword;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prettier-plugin-sql-cst",
3
- "version": "0.10.1",
3
+ "version": "0.11.0",
4
4
  "description": "Prettier plugin for SQL",
5
5
  "author": "Rene Saarsoo <nene@triin.net>",
6
6
  "license": "GPL-3.0-or-later",
@@ -18,12 +18,13 @@
18
18
  "dist/"
19
19
  ],
20
20
  "scripts": {
21
- "prepublishOnly": "yarn test && yarn build",
21
+ "prepublishOnly": "yarn analyze-field-access && yarn test && yarn build",
22
22
  "clean": "rm -rf dist",
23
23
  "build": "yarn clean && tsc",
24
24
  "test": "yarn node --experimental-vm-modules $(yarn bin jest)",
25
25
  "pretty": "prettier -w src/ test/",
26
- "ts:check": "tsc --noEmit"
26
+ "ts:check": "tsc --noEmit",
27
+ "analyze-field-access": "ts-node scripts/analyze-field-access.ts src/index.ts"
27
28
  },
28
29
  "keywords": [
29
30
  "prettier",
@@ -32,13 +33,14 @@
32
33
  ],
33
34
  "dependencies": {
34
35
  "prettier": "^3.0.3",
35
- "sql-parser-cst": "^0.21.1"
36
+ "sql-parser-cst": "^0.23.0"
36
37
  },
37
38
  "devDependencies": {
38
39
  "@types/jest": "^29.2.5",
39
40
  "dedent-js": "^1.0.1",
40
41
  "jest": "^29.7.0",
41
42
  "ts-jest": "^29.1.1",
43
+ "ts-node": "^10.9.2",
42
44
  "typescript": "^4.9.4"
43
45
  }
44
46
  }