prettier-plugin-sql-cst 0.9.1 → 0.10.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.
package/README.md CHANGED
@@ -89,6 +89,9 @@ The plugin provides the following parsers:
89
89
 
90
90
  - `sqlite`
91
91
  - `bigquery`
92
+ - `postgresql` (**experimental! expect crashes**)
93
+ - `mysql` (**experimental! expect crashes**)
94
+ - `mariadb` (**experimental! expect crashes**)
92
95
 
93
96
  ## Configuration
94
97
 
@@ -107,6 +110,18 @@ Currently this plugin supports two SQL dialects:
107
110
  - **SQLite** - full support.
108
111
  - **BigQuery** - full support.
109
112
 
113
+ It also has experimental support for the following dialects:
114
+
115
+ - PostgreSQL
116
+ - MySQL
117
+ - MariaDB
118
+
119
+ The main limitation is that [the parser][sql-parser-cst] does not support full syntax of
120
+ these dialects. One should expect the parser to crash for syntax that's more specific to
121
+ 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.
124
+
110
125
  The specifics of the [SQL formatting style][STYLE_GUIDE] are still very much subject to change.
111
126
  Though the general principles should be mostly in place by now.
112
127
 
package/dist/embedJson.js CHANGED
@@ -53,7 +53,8 @@ var print_utils_1 = require("./print_utils");
53
53
  var embedJson = function (path, options) {
54
54
  var node = path.getValue(); // TODO: Don't use deprecated method
55
55
  var parent = path.getParentNode();
56
- if ((0, node_utils_1.isStringLiteral)(node) && (0, node_utils_1.isJsonLiteral)(parent)) {
56
+ if ((0, node_utils_1.isStringLiteral)(node) &&
57
+ ((0, node_utils_1.isJsonLiteral)(parent) || (0, node_utils_1.isJsonbLiteral)(parent))) {
57
58
  return function (textToDoc) { return __awaiter(void 0, void 0, void 0, function () {
58
59
  var json, inlineQuote;
59
60
  return __generator(this, function (_a) {
package/dist/index.js CHANGED
@@ -20,6 +20,21 @@ exports.languages = [
20
20
  name: "BigQuery SQL",
21
21
  parsers: ["bigquery"],
22
22
  },
23
+ {
24
+ extensions: [],
25
+ name: "Experimental MySQL SQL",
26
+ parsers: ["mysql"],
27
+ },
28
+ {
29
+ extensions: [],
30
+ name: "Experimental MariaDB SQL",
31
+ parsers: ["mariadb"],
32
+ },
33
+ {
34
+ extensions: [],
35
+ name: "Experimental PostgreSQL SQL",
36
+ parsers: ["postgresql"],
37
+ },
23
38
  ];
24
39
  var createParser = function (dialect) { return ({
25
40
  parse: function (text, options) {
@@ -38,6 +53,9 @@ var createParser = function (dialect) { return ({
38
53
  exports.parsers = {
39
54
  sqlite: createParser("sqlite"),
40
55
  bigquery: createParser("bigquery"),
56
+ mysql: createParser("mysql"),
57
+ mariadb: createParser("mariadb"),
58
+ postgresql: createParser("postgresql"),
41
59
  };
42
60
  exports.printers = {
43
61
  "sql-cst": {
@@ -7,6 +7,7 @@ export declare const isCreateTableStmt: (node: any) => node is import("sql-parse
7
7
  export declare const isKeyword: (node: any) => node is import("sql-parser-cst").Keyword<string>;
8
8
  export declare const isEmpty: (node: any) => node is import("sql-parser-cst").Empty;
9
9
  export declare const isJsonLiteral: (node: any) => node is import("sql-parser-cst").JsonLiteral;
10
+ export declare const isJsonbLiteral: (node: any) => node is import("sql-parser-cst").JsonbLiteral;
10
11
  export declare const isStringLiteral: (node: any) => node is import("sql-parser-cst").StringLiteral;
11
12
  export declare const isArraySubscript: (node: any) => node is import("sql-parser-cst").ArraySubscript;
12
13
  export declare const isAsClause: (node: any) => node is import("sql-parser-cst").AsClause<Node>;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isLanguageClause = exports.isCreateFunctionStmt = exports.isListExpr = exports.isParenExpr = exports.isAsClause = exports.isArraySubscript = exports.isStringLiteral = exports.isJsonLiteral = exports.isEmpty = exports.isKeyword = exports.isCreateTableStmt = exports.isFuncArgs = exports.isFuncCall = exports.isValuesClause = exports.isProgram = void 0;
3
+ exports.isLanguageClause = exports.isCreateFunctionStmt = exports.isListExpr = exports.isParenExpr = exports.isAsClause = exports.isArraySubscript = exports.isStringLiteral = exports.isJsonbLiteral = exports.isJsonLiteral = exports.isEmpty = exports.isKeyword = exports.isCreateTableStmt = exports.isFuncArgs = exports.isFuncCall = exports.isValuesClause = exports.isProgram = void 0;
4
4
  var utils_1 = require("./utils");
5
5
  var is = function (type) {
6
6
  return function (node) {
@@ -15,6 +15,7 @@ exports.isCreateTableStmt = is("create_table_stmt");
15
15
  exports.isKeyword = is("keyword");
16
16
  exports.isEmpty = is("empty");
17
17
  exports.isJsonLiteral = is("json_literal");
18
+ exports.isJsonbLiteral = is("jsonb_literal");
18
19
  exports.isStringLiteral = is("string_literal");
19
20
  exports.isArraySubscript = is("array_subscript");
20
21
  exports.isAsClause = is("as_clause");
@@ -1,3 +1,3 @@
1
1
  import { AlterTableStmt, AllAlterActionNodes } from "sql-parser-cst";
2
2
  import { CstToDocMap } from "../CstToDocMap";
3
- export declare const alterTableMap: Partial<CstToDocMap<AlterTableStmt | AllAlterActionNodes>>;
3
+ export declare const alterTableMap: CstToDocMap<AlterTableStmt | AllAlterActionNodes>;
@@ -1,3 +1,3 @@
1
1
  import { AllColumns, Empty, Keyword } from "sql-parser-cst";
2
2
  import { CstToDocMap } from "../CstToDocMap";
3
- export declare const baseMap: Partial<CstToDocMap<Keyword | Empty | AllColumns>>;
3
+ export declare const baseMap: CstToDocMap<Keyword | Empty | AllColumns>;
@@ -1,3 +1,3 @@
1
1
  import { AllBigqueryNodes } from "sql-parser-cst";
2
2
  import { CstToDocMap } from "../CstToDocMap";
3
- export declare const bigqueryMap: Partial<CstToDocMap<AllBigqueryNodes>>;
3
+ export declare const bigqueryMap: CstToDocMap<AllBigqueryNodes>;
@@ -1,3 +1,3 @@
1
1
  import { AllConstraintNodes } from "sql-parser-cst";
2
2
  import { CstToDocMap } from "../CstToDocMap";
3
- export declare const constraintMap: Partial<CstToDocMap<AllConstraintNodes>>;
3
+ export declare const constraintMap: CstToDocMap<AllConstraintNodes>;
@@ -18,6 +18,7 @@ exports.constraintMap = {
18
18
  constraint_deferrable: function (print) {
19
19
  return print.spaced(["deferrableKw", "initiallyKw"]);
20
20
  },
21
+ constraint_null: function (print) { return print("nullKw"); },
21
22
  constraint_not_null: function (print) {
22
23
  return (0, print_utils_1.group)(print.spaced(["notNullKw", "onConflict"]));
23
24
  },
@@ -54,6 +55,18 @@ exports.constraintMap = {
54
55
  },
55
56
  constraint_auto_increment: function (print) { return print("autoIncrementKw"); },
56
57
  on_conflict_clause: function (print) { return print.spaced(["onConflictKw", "resolutionKw"]); },
58
+ constraint_comment: function (print) { return print.spaced(["commentKw", "value"]); },
59
+ constraint_index: function (print) {
60
+ return print.spaced(["indexTypeKw", "indexKw", "columns"]);
61
+ },
62
+ constraint_visible: function (print) { return print.spaced(["visibleKw"]); },
63
+ constraint_column_format: function (print) {
64
+ return print.spaced(["columnFormatKw", "formatKw"]);
65
+ },
66
+ constraint_storage: function (print) { return print.spaced(["storageKw", "typeKw"]); },
67
+ constraint_engine_attribute: function (print, node) {
68
+ return (0, print_utils_1.join)(node.hasEq ? " = " : " ", print(["engineAttributeKw", "value"]));
69
+ },
57
70
  };
58
71
  var printUnnamedConstraint = function (print, node) {
59
72
  if (node.deferrable) {
@@ -1,3 +1,3 @@
1
1
  import { AllCreateTableNodes } from "sql-parser-cst";
2
2
  import { CstToDocMap } from "../CstToDocMap";
3
- export declare const createTableMap: Partial<CstToDocMap<AllCreateTableNodes>>;
3
+ export declare const createTableMap: CstToDocMap<AllCreateTableNodes>;
@@ -38,7 +38,17 @@ exports.createTableMap = {
38
38
  column_definition: function (print) {
39
39
  return print.spaced(["name", "dataType", "constraints"]);
40
40
  },
41
- table_option: function (print) { return print.spaced(["name"]); },
41
+ table_option: function (print, node) {
42
+ if (node.value && node.hasEq) {
43
+ return [print.spaced("name"), " = ", print.spaced("value")];
44
+ }
45
+ else if (node.value) {
46
+ return [print.spaced("name"), " ", print.spaced("value")];
47
+ }
48
+ else {
49
+ return print.spaced("name");
50
+ }
51
+ },
42
52
  create_table_like_clause: function (print) { return print.spaced(["likeKw", "name"]); },
43
53
  create_table_copy_clause: function (print) { return print.spaced(["copyKw", "name"]); },
44
54
  create_table_clone_clause: function (print) { return print.spaced(["cloneKw", "table"]); },
@@ -1,3 +1,3 @@
1
1
  import { AllDataTypeNodes } from "sql-parser-cst";
2
2
  import { CstToDocMap } from "../CstToDocMap";
3
- export declare const dataTypeMap: Partial<CstToDocMap<AllDataTypeNodes>>;
3
+ export declare const dataTypeMap: CstToDocMap<AllDataTypeNodes>;
@@ -5,9 +5,14 @@ var utils_1 = require("../utils");
5
5
  var print_utils_1 = require("../print_utils");
6
6
  exports.dataTypeMap = {
7
7
  // print single-word types as `TYPE(10)` and multi-word types as `MY TYPE (10)`
8
- data_type: function (print, node) {
8
+ named_data_type: function (print, node) {
9
9
  return ((0, utils_1.isArray)(node.nameKw) ? print.spaced : print)(["nameKw", "params"]);
10
10
  },
11
+ array_data_type: function (print) { return print(["dataType", "bounds"]); },
12
+ array_bounds: function (print) { return ["[", print("bounds"), "]"]; },
13
+ with_time_zone_data_type: function (print) {
14
+ return print.spaced(["dataType", "withTimeZoneKw"]);
15
+ },
11
16
  generic_type_params: function (print) {
12
17
  return (0, print_utils_1.group)(["<", (0, print_utils_1.indent)([print_utils_1.softline, print("params")]), print_utils_1.softline, ">"]);
13
18
  },
@@ -1,3 +1,3 @@
1
1
  import { AllDclStatements } from "sql-parser-cst";
2
2
  import { CstToDocMap } from "../CstToDocMap";
3
- export declare const dclMap: Partial<CstToDocMap<AllDclStatements>>;
3
+ export declare const dclMap: CstToDocMap<AllDclStatements>;
@@ -4,5 +4,7 @@ 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", "tables"]); },
7
+ delete_clause: function (print) {
8
+ return print.spaced(["deleteKw", "hints", "fromKw", "tables"]);
9
+ },
8
10
  };
@@ -50,6 +50,10 @@ exports.exprMap = {
50
50
  if ((0, node_utils_1.isKeyword)(node.operator) && isBooleanOp(node.operator)) {
51
51
  return (0, print_utils_1.join)(print_utils_1.line, [print("left"), print.spaced(["operator", "right"])]);
52
52
  }
53
+ if (node.operator === "") {
54
+ // String concatenation with whitespace (MySQL / MariaDB)
55
+ return print.spaced(["left", "right"]);
56
+ }
53
57
  return print.spaced(["left", "operator", "right"]);
54
58
  },
55
59
  prefix_op_expr: function (print, node) {
@@ -93,6 +97,7 @@ exports.exprMap = {
93
97
  return (0, print_utils_1.group)(["[", (0, print_utils_1.indent)([print_utils_1.softline, print("expr")]), print_utils_1.softline, "]"]);
94
98
  },
95
99
  array_subscript_specifier: function (print) { return print(["specifierKw", "args"]); },
100
+ array_slice_specifier: function (print) { return [print("from"), ":", print("to")]; },
96
101
  func_call: function (print) {
97
102
  var fnCall = print(["name", "args"]);
98
103
  var extras = print(["filter", "over"]);
@@ -103,19 +108,27 @@ exports.exprMap = {
103
108
  return (0, print_utils_1.group)((0, print_utils_1.join)(" ", __spreadArray([fnCall], extras, true)));
104
109
  }
105
110
  },
106
- func_args: function (print) { return print.spaced(["distinctKw", "args", "having"]); },
111
+ func_args: function (print, node) {
112
+ return (0, print_utils_1.join)(print_utils_1.line, __spreadArray(__spreadArray(__spreadArray([], print(["distinctKw", "args"]), true), (node.nullHandlingKw ? print.spaced("nullHandlingKw") : []), true), print(["orderBy", "limit", "having"]), true));
113
+ },
107
114
  filter_arg: function (print) { return print.spaced(["filterKw", "where"]); },
108
115
  over_arg: function (print) { return print.spaced(["overKw", "window"]); },
109
116
  having_arg: function (print) { return print.spaced(["havingKw", "minMaxKw", "expr"]); },
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")])]);
119
+ },
110
120
  cast_expr: function (print) { return print(["castKw", "args"]); },
111
121
  cast_arg: function (print) { return print.spaced(["expr", "asKw", "dataType", "format"]); },
112
122
  cast_format: function (print) { return print.spaced(["formatKw", "string", "timezone"]); },
113
123
  cast_format_timezone: function (print) { return print.spaced(["atTimeZoneKw", "timezone"]); },
124
+ cast_operator_expr: function (print) { return [print("expr"), "::", print("dataType")]; },
125
+ string_with_charset: function (print) { return ["_", print(["charset", "string"])]; },
114
126
  raise_expr: function (print) { return print(["raiseKw", "args"]); },
115
127
  raise_expr_type: function (print) { return print("typeKw"); },
116
128
  extract_expr: function (print) { return print(["extractKw", "args"]); },
117
129
  extract_from: function (print) { return print.spaced(["unit", "fromKw", "expr"]); },
118
130
  week_expr: function (print) { return print(["weekKw", "args"]); },
131
+ interval_literal: function (print) { return print.spaced(["intervalKw", "string"]); },
119
132
  interval_expr: function (print) { return print.spaced(["intervalKw", "expr", "unit"]); },
120
133
  interval_unit_range: function (print) { return print.spaced(["fromUnit", "toKw", "toUnit"]); },
121
134
  interval_unit: function (print) { return print("unitKw"); },
@@ -126,9 +139,16 @@ exports.exprMap = {
126
139
  return (0, print_utils_1.group)(["(", (0, print_utils_1.indent)([print_utils_1.softline, print("expr")]), print_utils_1.softline, ")"]);
127
140
  },
128
141
  typed_expr: function (print) { return print(["dataType", "expr"]); },
142
+ row_constructor: function (print) { return print(["rowKw", "row"]); },
143
+ quantifier_expr: function (print) { return print.spaced(["quantifierKw", "expr"]); },
144
+ full_text_match_expr: function (print) {
145
+ return print.spaced(["matchKw", "columns", "againstKw", "args"]);
146
+ },
147
+ full_text_match_args: function (print) { return print.spaced(["expr", "modifier"]); },
129
148
  number_literal: function (print) { return print("text"); },
130
149
  boolean_literal: function (print) { return print("valueKw"); },
131
150
  string_literal: function (print) { return print("text"); },
151
+ blob_literal: function (print) { return print("text"); },
132
152
  null_literal: function (print) { return print("nullKw"); },
133
153
  numeric_literal: function (print) { return print.spaced(["numericKw", "string"]); },
134
154
  bignumeric_literal: function (print) { return print.spaced(["bignumericKw", "string"]); },
@@ -137,6 +157,7 @@ exports.exprMap = {
137
157
  datetime_literal: function (print) { return print.spaced(["datetimeKw", "string"]); },
138
158
  timestamp_literal: function (print) { return print.spaced(["timestampKw", "string"]); },
139
159
  json_literal: function (print) { return print.spaced(["jsonKw", "string"]); },
160
+ jsonb_literal: function (print) { return print.spaced(["jsonbKw", "string"]); },
140
161
  identifier: function (print) { return print("text"); },
141
162
  variable: function (print) { return print("text"); },
142
163
  parameter: function (print) { return print("text"); },
@@ -1,3 +1,3 @@
1
1
  import { AllFunctionNodes } from "sql-parser-cst";
2
2
  import { CstToDocMap } from "../CstToDocMap";
3
- export declare const functionMap: Partial<CstToDocMap<AllFunctionNodes>>;
3
+ export declare const functionMap: CstToDocMap<AllFunctionNodes>;
@@ -1,3 +1,3 @@
1
1
  import { AllIndexNodes } from "sql-parser-cst";
2
2
  import { CstToDocMap } from "../CstToDocMap";
3
- export declare const indexMap: Partial<CstToDocMap<AllIndexNodes>>;
3
+ export declare const indexMap: CstToDocMap<AllIndexNodes>;
@@ -1,3 +1,3 @@
1
1
  import { AllInsertNodes } from "sql-parser-cst";
2
2
  import { CstToDocMap } from "../CstToDocMap";
3
- export declare const insertMap: Partial<CstToDocMap<AllInsertNodes>>;
3
+ export declare const insertMap: CstToDocMap<AllInsertNodes>;
@@ -6,7 +6,7 @@ exports.insertMap = {
6
6
  insert_stmt: function (print) { return (0, print_utils_1.join)(print_utils_1.hardline, print("clauses")); },
7
7
  insert_clause: function (print, node) {
8
8
  return (0, print_utils_1.group)([
9
- print.spaced(["insertKw", "orAction", "intoKw", "table"]),
9
+ print.spaced(["insertKw", "hints", "orAction", "intoKw", "table"]),
10
10
  node.columns ? (0, print_utils_1.indent)([print_utils_1.hardline, print("columns")]) : [],
11
11
  ]);
12
12
  },
@@ -24,4 +24,12 @@ exports.insertMap = {
24
24
  print("updateKw"),
25
25
  (0, print_utils_1.indent)([print_utils_1.hardline, (0, print_utils_1.join)(print_utils_1.hardline, print(["set", "where"]))]),
26
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
+ ]; },
27
35
  };
@@ -1,3 +1,3 @@
1
1
  import { AllMergeNodes } from "sql-parser-cst";
2
2
  import { CstToDocMap } from "../CstToDocMap";
3
- export declare const mergeMap: Partial<CstToDocMap<AllMergeNodes>>;
3
+ export declare const mergeMap: CstToDocMap<AllMergeNodes>;
@@ -0,0 +1,3 @@
1
+ import { AllMysqlNodes } from "sql-parser-cst";
2
+ import { CstToDocMap } from "../CstToDocMap";
3
+ export declare const mysqlMap: CstToDocMap<AllMysqlNodes>;
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.mysqlMap = void 0;
4
+ exports.mysqlMap = {
5
+ mysql_hint: function (print) { return print.spaced("hintKw"); },
6
+ };
@@ -1,3 +1,3 @@
1
1
  import { AllPreparedStatementNodes } from "sql-parser-cst";
2
2
  import { CstToDocMap } from "../CstToDocMap";
3
- export declare const preparedStatementsMap: Partial<CstToDocMap<AllPreparedStatementNodes>>;
3
+ export declare const preparedStatementsMap: CstToDocMap<AllPreparedStatementNodes>;
@@ -1,3 +1,3 @@
1
1
  import { AllProcClauseNodes } from "sql-parser-cst";
2
2
  import { CstToDocMap } from "../CstToDocMap";
3
- export declare const procClauseMap: Partial<CstToDocMap<AllProcClauseNodes>>;
3
+ export declare const procClauseMap: CstToDocMap<AllProcClauseNodes>;
@@ -1,3 +1,3 @@
1
1
  import { AllProceduralNodes } from "sql-parser-cst";
2
2
  import { CstToDocMap } from "../CstToDocMap";
3
- export declare const proceduralLanguageMap: Partial<CstToDocMap<AllProceduralNodes>>;
3
+ export declare const proceduralLanguageMap: CstToDocMap<AllProceduralNodes>;
@@ -1,3 +1,3 @@
1
1
  import { AllProcedureNodes } from "sql-parser-cst";
2
2
  import { CstToDocMap } from "../CstToDocMap";
3
- export declare const procedureMap: Partial<CstToDocMap<AllProcedureNodes>>;
3
+ export declare const procedureMap: CstToDocMap<AllProcedureNodes>;
@@ -1,3 +1,3 @@
1
1
  import { AllSchemaStatements } from "sql-parser-cst";
2
2
  import { CstToDocMap } from "../CstToDocMap";
3
- export declare const schemaMap: Partial<CstToDocMap<AllSchemaStatements>>;
3
+ export declare const schemaMap: CstToDocMap<AllSchemaStatements>;
@@ -1,3 +1,3 @@
1
1
  import { AllSelectNodes } from "sql-parser-cst";
2
2
  import { CstToDocMap } from "../CstToDocMap";
3
- export declare const selectMap: Partial<CstToDocMap<AllSelectNodes>>;
3
+ export declare const selectMap: CstToDocMap<AllSelectNodes>;
@@ -1,4 +1,13 @@
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.selectMap = void 0;
4
13
  var utils_1 = require("../utils");
@@ -11,6 +20,7 @@ exports.selectMap = {
11
20
  var lineType = (0, print_utils_1.containsNewline)(node, opts) ? print_utils_1.hardline : print_utils_1.line;
12
21
  return (0, print_utils_1.group)((0, print_utils_1.join)(lineType, print("clauses")));
13
22
  },
23
+ // WITH clause
14
24
  with_clause: function (print) {
15
25
  return (0, print_utils_1.group)([
16
26
  print.spaced(["withKw", "recursiveKw"]),
@@ -22,15 +32,17 @@ exports.selectMap = {
22
32
  " ",
23
33
  print.spaced(["asKw", "materializedKw", "expr"]),
24
34
  ]; },
35
+ // SELECT clause
25
36
  select_clause: function (print, node, path, opts) {
26
37
  return (0, print_utils_1.group)([
27
- print.spaced(["selectKw", "distinctKw", "asStructOrValueKw"]),
28
- (0, print_utils_1.indent)([print_utils_1.line, print("columns")]),
38
+ print.spaced(["selectKw", "distinctKw", "hints", "asStructOrValueKw"]),
39
+ node.columns ? (0, print_utils_1.indent)([print_utils_1.line, print("columns")]) : [],
29
40
  (0, print_utils_1.containsNewline)(node, opts) ? print_utils_1.breakParent : [],
30
41
  ]);
31
42
  },
32
43
  except_columns: function (print) { return print.spaced(["expr", "exceptKw", "columns"]); },
33
44
  replace_columns: function (print) { return print.spaced(["expr", "replaceKw", "columns"]); },
45
+ // FROM clause
34
46
  from_clause: function (print) {
35
47
  return (0, print_utils_1.group)([print("fromKw"), (0, print_utils_1.indent)([print_utils_1.line, print("expr")])]);
36
48
  },
@@ -91,40 +103,91 @@ exports.selectMap = {
91
103
  for_system_time_as_of_expr: function (print) {
92
104
  return (0, print_utils_1.group)([print("left"), print_utils_1.line, print.spaced(["forSystemTimeAsOfKw", "expr"])]);
93
105
  },
106
+ partitioned_table: function (print) {
107
+ return print.spaced(["table", "partitionKw", "partitions"]);
108
+ },
109
+ dual_table: function (print) { return print("dualKw"); },
110
+ lateral_derived_table: function (print) { return print.spaced(["lateralKw", "expr"]); },
111
+ // WHERE clause
94
112
  where_clause: function (print) {
95
113
  return (0, print_utils_1.group)([print("whereKw"), (0, print_utils_1.indent)([print_utils_1.line, print("expr")])]);
96
114
  },
97
- order_by_clause: function (print) {
98
- return (0, print_utils_1.group)([print.spaced("orderByKw"), (0, print_utils_1.indent)([print_utils_1.line, print("specifications")])]);
115
+ // ORDER BY clause
116
+ order_by_clause: function (print, node) {
117
+ return (0, print_utils_1.group)([
118
+ print.spaced("orderByKw"),
119
+ (0, print_utils_1.indent)([
120
+ print_utils_1.line,
121
+ (0, print_utils_1.join)(print_utils_1.line, __spreadArray([
122
+ print("specifications")
123
+ ], (node.withRollupKw ? print.spaced("withRollupKw") : []), true)),
124
+ ]),
125
+ ]);
126
+ },
127
+ sort_specification: function (print) {
128
+ return print.spaced(["expr", "orderKw", "nullHandlingKw"]);
99
129
  },
100
- group_by_clause: function (print) {
101
- return (0, print_utils_1.group)([print.spaced("groupByKw"), (0, print_utils_1.indent)([print_utils_1.line, print("columns")])]);
130
+ // GROUP BY clause
131
+ group_by_clause: function (print, node) {
132
+ return (0, print_utils_1.group)([
133
+ print.spaced(["groupByKw", "distinctKw"]),
134
+ (0, print_utils_1.indent)([
135
+ print_utils_1.line,
136
+ (0, print_utils_1.join)(print_utils_1.line, __spreadArray([
137
+ print("columns")
138
+ ], (node.withRollupKw ? print.spaced("withRollupKw") : []), true)),
139
+ ]),
140
+ ]);
102
141
  },
103
142
  group_by_rollup: function (print) { return print(["rollupKw", "columns"]); },
143
+ // PARTITION BY clause
104
144
  partition_by_clause: function (print) {
105
145
  return (0, print_utils_1.group)([
106
146
  print.spaced("partitionByKw"),
107
147
  (0, print_utils_1.indent)([print_utils_1.line, print("specifications")]),
108
148
  ]);
109
149
  },
150
+ // CLUSTER BY clause
110
151
  cluster_by_clause: function (print) {
111
152
  return (0, print_utils_1.group)([print.spaced("clusterByKw"), (0, print_utils_1.indent)([print_utils_1.line, print("columns")])]);
112
153
  },
154
+ // HAVING clause
113
155
  having_clause: function (print) {
114
156
  return (0, print_utils_1.group)([print("havingKw"), (0, print_utils_1.indent)([print_utils_1.line, print("expr")])]);
115
157
  },
158
+ // QUALIFY clause
116
159
  qualify_clause: function (print) {
117
160
  return (0, print_utils_1.group)([print("qualifyKw"), (0, print_utils_1.indent)([print_utils_1.line, print("expr")])]);
118
161
  },
162
+ // RETURNING clause
119
163
  returning_clause: function (print) {
120
164
  return (0, print_utils_1.group)([print("returningKw"), (0, print_utils_1.indent)([print_utils_1.line, print("columns")])]);
121
165
  },
166
+ // LIMIT clause
122
167
  limit_clause: function (print, node) {
123
- return (0, print_utils_1.group)([print("limitKw"), (0, print_utils_1.indent)([print_utils_1.line, printLimitValues(print, node)])]);
168
+ return (0, print_utils_1.group)([
169
+ print("limitKw"),
170
+ (0, print_utils_1.indent)([
171
+ print_utils_1.line,
172
+ printLimitValues(print, node),
173
+ node.rowsExamined ? [print_utils_1.line, print("rowsExamined")] : [],
174
+ ]),
175
+ ]);
124
176
  },
125
- sort_specification: function (print) {
126
- return print.spaced(["expr", "orderKw", "nullHandlingKw"]);
177
+ limit_all: function (print) { return print("allKw"); },
178
+ limit_rows_examined: function (print) { return print.spaced(["rowsExaminedKw", "count"]); },
179
+ // OFFSET clause
180
+ offset_clause: function (print) {
181
+ return (0, print_utils_1.group)([
182
+ print("offsetKw"),
183
+ (0, print_utils_1.indent)([print_utils_1.line, print.spaced(["offset", "rowsKw"])]),
184
+ ]);
185
+ },
186
+ // FETCH clause
187
+ fetch_clause: function (print) {
188
+ return print.spaced(["fetchKw", "count", "rowsKw", "withTiesKw"]);
127
189
  },
190
+ // WINDOW clause
128
191
  window_clause: function (print, node) {
129
192
  var lineType = node.namedWindows.items.length > 1 ? print_utils_1.hardline : print_utils_1.line;
130
193
  return (0, print_utils_1.group)([
@@ -143,6 +206,55 @@ exports.selectMap = {
143
206
  var lineType = itemCount > 1 ? print_utils_1.hardline : print_utils_1.line;
144
207
  return (0, print_utils_1.group)((0, print_utils_1.join)(lineType, print(["baseWindowName", "partitionBy", "orderBy", "frame"])));
145
208
  },
209
+ // INTO clause
210
+ into_table_clause: function (print) {
211
+ return print.spaced(["intoKw", "temporaryKw", "unloggedKw", "tableKw", "name"]);
212
+ },
213
+ into_variables_clause: function (print) {
214
+ return (0, print_utils_1.group)([print("intoKw"), (0, print_utils_1.indent)([print_utils_1.line, print("variables")])]);
215
+ },
216
+ into_dumpfile_clause: function (print) { return print.spaced(["intoDumpfileKw", "filename"]); },
217
+ into_outfile_clause: function (print, node) {
218
+ var hasOptions = node.charset || node.fields || node.lines;
219
+ return (0, print_utils_1.group)([
220
+ print.spaced(["intoOutfileKw", "filename"]),
221
+ hasOptions
222
+ ? (0, print_utils_1.indent)([
223
+ print_utils_1.hardline,
224
+ (0, print_utils_1.join)(print_utils_1.hardline, print(["charset", "fields", "lines"])),
225
+ ])
226
+ : [],
227
+ ]);
228
+ },
229
+ outfile_fields: function (print) { return print.spaced(["fieldsKw", "options"]); },
230
+ outfile_lines: function (print) { return print.spaced(["linesKw", "options"]); },
231
+ outfile_option_character_set: function (print) {
232
+ return print.spaced(["characterSetKw", "value"]);
233
+ },
234
+ outfile_option_starting_by: function (print) {
235
+ return print.spaced(["startingByKw", "value"]);
236
+ },
237
+ outfile_option_terminated_by: function (print) {
238
+ return print.spaced(["terminatedByKw", "value"]);
239
+ },
240
+ outfile_option_enclosed_by: function (print) {
241
+ return print.spaced(["optionallyKw", "enclosedByKw", "value"]);
242
+ },
243
+ outfile_option_escaped_by: function (print) { return print.spaced(["escapedByKw", "value"]); },
244
+ // FOR clause (locking)
245
+ for_clause: function (print, node) {
246
+ return (0, print_utils_1.group)([
247
+ print.spaced(["forKw", "lockStrengthKw", "tables"]),
248
+ node.waitingKw ? (0, print_utils_1.indent)([print_utils_1.line, print.spaced("waitingKw")]) : [],
249
+ ]);
250
+ },
251
+ for_clause_tables: function (print) { return [
252
+ print("ofKw"),
253
+ (0, print_utils_1.indent)([print_utils_1.line, print("tables")]),
254
+ ]; },
255
+ lock_in_share_mode_clause: function (print) { return print.spaced("lockInShareModeKw"); },
256
+ // TABLE clause
257
+ table_clause: function (print) { return print.spaced(["tableKw", "table"]); },
146
258
  };
147
259
  var printLimitValues = function (print, node) {
148
260
  if (node.offsetKw) {
@@ -30,6 +30,7 @@ var function_1 = require("./function");
30
30
  var index_1 = require("./index");
31
31
  var insert_1 = require("./insert");
32
32
  var merge_1 = require("./merge");
33
+ var mysql_1 = require("./mysql");
33
34
  var prepared_statements_1 = require("./prepared_statements");
34
35
  var procedural_language_1 = require("./procedural_language");
35
36
  var procedure_1 = require("./procedure");
@@ -43,4 +44,4 @@ var trigger_1 = require("./trigger");
43
44
  var truncate_1 = require("./truncate");
44
45
  var update_1 = require("./update");
45
46
  var view_1 = require("./view");
46
- 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({}, alias_1.aliasMap), alter_table_1.alterTableMap), analyze_1.analyzeMap), base_1.baseMap), bigquery_1.bigqueryMap), 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), sqlite_1.sqliteMap), transaction_1.transactionMap), trigger_1.triggerMap), truncate_1.truncateMap), update_1.updateMap), view_1.viewMap);
47
+ 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({}, alias_1.aliasMap), alter_table_1.alterTableMap), analyze_1.analyzeMap), base_1.baseMap), bigquery_1.bigqueryMap), 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), mysql_1.mysqlMap), prepared_statements_1.preparedStatementsMap), proc_clause_1.procClauseMap), procedural_language_1.proceduralLanguageMap), procedure_1.procedureMap), program_1.programMap), schema_1.schemaMap), select_1.selectMap), sqlite_1.sqliteMap), transaction_1.transactionMap), trigger_1.triggerMap), truncate_1.truncateMap), update_1.updateMap), view_1.viewMap);
@@ -1,3 +1,3 @@
1
1
  import { AllTriggerNodes } from "sql-parser-cst";
2
2
  import { CstToDocMap } from "../CstToDocMap";
3
- export declare const triggerMap: Partial<CstToDocMap<AllTriggerNodes>>;
3
+ export declare const triggerMap: CstToDocMap<AllTriggerNodes>;
@@ -2,5 +2,5 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.truncateMap = void 0;
4
4
  exports.truncateMap = {
5
- truncate_stmt: function (print) { return print.spaced(["truncateTableKw", "table"]); },
5
+ truncate_stmt: function (print) { return print.spaced(["truncateKw", "tableKw", "table"]); },
6
6
  };
@@ -1,3 +1,3 @@
1
1
  import { AllUpdateNodes } from "sql-parser-cst";
2
2
  import { CstToDocMap } from "../CstToDocMap";
3
- export declare const updateMap: Partial<CstToDocMap<AllUpdateNodes>>;
3
+ export declare const updateMap: CstToDocMap<AllUpdateNodes>;
@@ -1,3 +1,3 @@
1
1
  import { AllViewStatements } from "sql-parser-cst";
2
2
  import { CstToDocMap } from "../CstToDocMap";
3
- export declare const viewMap: Partial<CstToDocMap<AllViewStatements>>;
3
+ export declare const viewMap: CstToDocMap<AllViewStatements>;
@@ -9,7 +9,7 @@ var stripTrailingCommas = function (cst) {
9
9
  // Trailing comma is represented as an empty element at the end of column list
10
10
  var removeLastEmptyColumn = (0, sql_parser_cst_1.cstVisitor)({
11
11
  select_clause: function (node) {
12
- if ((0, node_utils_1.isEmpty)((0, utils_1.last)(node.columns.items))) {
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
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prettier-plugin-sql-cst",
3
- "version": "0.9.1",
3
+ "version": "0.10.0",
4
4
  "description": "Prettier plugin for SQL",
5
5
  "author": "Rene Saarsoo <nene@triin.net>",
6
6
  "license": "GPL-3.0-or-later",
@@ -22,7 +22,7 @@
22
22
  "clean": "rm -rf dist",
23
23
  "build": "yarn clean && tsc",
24
24
  "test": "yarn node --experimental-vm-modules $(yarn bin jest)",
25
- "pretty": "prettier -w src/"
25
+ "pretty": "prettier -w src/ test/"
26
26
  },
27
27
  "keywords": [
28
28
  "prettier",
@@ -31,7 +31,7 @@
31
31
  ],
32
32
  "dependencies": {
33
33
  "prettier": "^3.0.3",
34
- "sql-parser-cst": "^0.17.1"
34
+ "sql-parser-cst": "^0.20.0"
35
35
  },
36
36
  "devDependencies": {
37
37
  "@types/jest": "^29.2.5",