prettier-plugin-sql-cst 0.8.1 → 0.8.3

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.
package/README.md CHANGED
@@ -3,6 +3,10 @@
3
3
  A [Prettier][] plugin for SQL that uses [sql-parser-cst][] and the
4
4
  actual [Prettier formatting algorithm][wadler-prettier].
5
5
 
6
+ **Note:** This plugin only works with Prettier 2.x. It doesn't yet support the latest Prettier 3.x.
7
+
8
+ **[Try it live!][live]**
9
+
6
10
  Like Prettier for JavaScript,
7
11
  this plugin formats SQL expressions differently depending on their length.
8
12
  A short SQL query will be formatted on a single line:
@@ -26,15 +30,15 @@ SELECT
26
30
  client.id,
27
31
  client.name AS client_name,
28
32
  organization.name AS org_name,
29
- count(order.id) AS nr_of_orders
33
+ count(orders.id) AS nr_of_orders
30
34
  FROM
31
35
  client
32
36
  LEFT JOIN organization ON client.organization_id = organization.id
33
- LEFT JOIN order ON order.client_id = client.id
37
+ LEFT JOIN orders ON orders.client_id = client.id
34
38
  WHERE
35
39
  client.status = 'active'
36
40
  AND client.id IN (28, 214, 457)
37
- AND order.status IN ('active', 'pending', 'processing')
41
+ AND orders.status IN ('active', 'pending', 'processing')
38
42
  GROUP BY client.id
39
43
  ORDER BY client.name
40
44
  LIMIT 100;
@@ -109,6 +113,7 @@ The specifics of the [SQL formatting style][STYLE_GUIDE] are still very much sub
109
113
  Though the general principles should be mostly in place by now.
110
114
 
111
115
  [prettier]: https://prettier.io/
116
+ [live]: https://nene.github.io/prettier-sql-playground/
112
117
  [printWidth]: https://prettier.io/docs/en/options.html#print-width
113
118
  [tabWidth]: https://prettier.io/docs/en/options.html#tab-width
114
119
  [useTabs]: https://prettier.io/docs/en/options.html#tabs
@@ -2,12 +2,15 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.dataTypeMap = void 0;
4
4
  var utils_1 = require("../utils");
5
+ var print_utils_1 = require("../print_utils");
5
6
  exports.dataTypeMap = {
6
7
  // print single-word types as `TYPE(10)` and multi-word types as `MY TYPE (10)`
7
8
  data_type: function (print, node) {
8
9
  return ((0, utils_1.isArray)(node.nameKw) ? print.spaced : print)(["nameKw", "params"]);
9
10
  },
10
- generic_type_params: function (print) { return ["<", print("params"), ">"]; },
11
+ generic_type_params: function (print) {
12
+ return (0, print_utils_1.group)(["<", (0, print_utils_1.indent)([print_utils_1.softline, print("params")]), print_utils_1.softline, ">"]);
13
+ },
11
14
  array_type_param: function (print) { return print.spaced(["dataType", "constraints"]); },
12
15
  struct_type_param: function (print) {
13
16
  return print.spaced(["name", "dataType", "constraints"]);
@@ -4,5 +4,5 @@ exports.deleteMap = void 0;
4
4
  var print_utils_1 = require("../print_utils");
5
5
  exports.deleteMap = {
6
6
  delete_stmt: function (print) { return (0, print_utils_1.join)(print_utils_1.hardline, print("clauses")); },
7
- delete_clause: function (print) { return print.spaced(["deleteKw", "fromKw", "table"]); },
7
+ delete_clause: function (print) { return print.spaced(["deleteKw", "fromKw", "tables"]); },
8
8
  };
@@ -103,19 +103,22 @@ exports.exprMap = {
103
103
  return (0, print_utils_1.group)((0, print_utils_1.join)(" ", __spreadArray([fnCall], extras, true)));
104
104
  }
105
105
  },
106
- func_args: function (print) { return print.spaced(["distinctKw", "args"]); },
106
+ func_args: function (print) { return print.spaced(["distinctKw", "args", "having"]); },
107
107
  filter_arg: function (print) { return print.spaced(["filterKw", "where"]); },
108
108
  over_arg: function (print) { return print.spaced(["overKw", "window"]); },
109
+ having_arg: function (print) { return print.spaced(["havingKw", "minMaxKw", "expr"]); },
109
110
  cast_expr: function (print) { return print(["castKw", "args"]); },
110
111
  cast_arg: function (print) { return print.spaced(["expr", "asKw", "dataType", "format"]); },
111
112
  cast_format: function (print) { return print.spaced(["formatKw", "string", "timezone"]); },
112
113
  cast_format_timezone: function (print) { return print.spaced(["atTimeZoneKw", "timezone"]); },
113
114
  raise_expr: function (print) { return print(["raiseKw", "args"]); },
114
115
  raise_expr_type: function (print) { return print("typeKw"); },
116
+ extract_expr: function (print) { return print(["extractKw", "args"]); },
117
+ extract_from: function (print) { return print.spaced(["unit", "fromKw", "expr"]); },
118
+ week_expr: function (print) { return print(["weekKw", "args"]); },
115
119
  interval_expr: function (print) { return print.spaced(["intervalKw", "expr", "unit"]); },
116
- interval_unit_range: function (print) {
117
- return print.spaced(["fromUnitKw", "toKw", "toUnitKw"]);
118
- },
120
+ interval_unit_range: function (print) { return print.spaced(["fromUnit", "toKw", "toUnit"]); },
121
+ interval_unit: function (print) { return print("unitKw"); },
119
122
  array_expr: function (print) {
120
123
  return (0, print_utils_1.group)(["[", (0, print_utils_1.indent)([print_utils_1.softline, print("expr")]), print_utils_1.softline, "]"]);
121
124
  },
@@ -17,7 +17,7 @@ exports.selectMap = {
17
17
  (0, print_utils_1.indent)([print_utils_1.line, print("tables")]),
18
18
  ]);
19
19
  },
20
- common_table_expression: function (print) { return [
20
+ common_table_expr: function (print) { return [
21
21
  print(["table", "columns"]),
22
22
  " ",
23
23
  print.spaced(["asKw", "materializedKw", "expr"]),
@@ -5,7 +5,7 @@ var print_utils_1 = require("../print_utils");
5
5
  exports.updateMap = {
6
6
  update_stmt: function (print) { return (0, print_utils_1.join)(print_utils_1.hardline, print("clauses")); },
7
7
  update_clause: function (print) {
8
- return print.spaced(["updateKw", "options", "orAction", "tables"]);
8
+ return print.spaced(["updateKw", "hints", "orAction", "tables"]);
9
9
  },
10
10
  set_clause: function (print, node) {
11
11
  if (node.assignments.items.length > 1) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prettier-plugin-sql-cst",
3
- "version": "0.8.1",
3
+ "version": "0.8.3",
4
4
  "description": "Prettier plugin for SQL",
5
5
  "author": "Rene Saarsoo <nene@triin.net>",
6
6
  "license": "GPL-3.0-or-later",
@@ -30,7 +30,7 @@
30
30
  ],
31
31
  "dependencies": {
32
32
  "prettier": "^2.8.2",
33
- "sql-parser-cst": "^0.14.1"
33
+ "sql-parser-cst": "^0.17.1"
34
34
  },
35
35
  "devDependencies": {
36
36
  "@types/jest": "^29.2.5",