prettier-plugin-sql-cst 0.4.0 → 0.6.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
@@ -49,7 +49,6 @@ LIMIT 100;
49
49
 
50
50
  Currently this plugin preserves most of the syntax elements
51
51
  and concentrates mainly on the layout of whitespace.
52
- For example it does not add/remove paratheses.
53
52
 
54
53
  See [STYLE_GUIDE][] for overview of the SQL formatting style used.
55
54
 
@@ -61,7 +60,7 @@ Install it as any other Prettier plugin:
61
60
  npm install --save-dev prettier prettier-plugin-sql-cst
62
61
  ```
63
62
 
64
- Then use it on SQL files though Prettier command line tool or Prettier extension
63
+ Then use it on SQL files through Prettier command line tool or Prettier extension
65
64
  for your editor of choice.
66
65
 
67
66
  ## Choosing an SQL dialect
@@ -100,8 +99,9 @@ There are also some SQL-specific options:
100
99
 
101
100
  ## Limitations and development status
102
101
 
103
- Currently this plugin supports the most common everyday **SQLite** and **BigQuery** syntax.
104
- Formatting of the following SQL statements is fully implemented:
102
+ Currently this plugin supports full **SQLite** syntax.
103
+ It also supports most of the **BigQuery** syntax.
104
+ Specifically the formatting of the following BigQuery SQL statements is fully implemented:
105
105
 
106
106
  - SELECT
107
107
  - UPDATE
@@ -110,7 +110,7 @@ Formatting of the following SQL statements is fully implemented:
110
110
  - TRUNCATE
111
111
  - CREATE / DROP / ALTER TABLE
112
112
  - CREATE / DROP VIEW
113
- - CREATE / DROP INDEX
113
+ - transactions (BEGIN, COMMIT, ROLLBACK)
114
114
 
115
115
  [prettier]: https://prettier.io/
116
116
  [printWidth]: https://prettier.io/docs/en/options.html#print-width
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isAsClause = exports.isArraySubscript = exports.isStringLiteral = exports.isJsonLiteral = exports.isEmpty = exports.isKeyword = exports.isCreateTableStmt = exports.isFuncCall = exports.isValuesClause = void 0;
3
+ exports.isListExpr = exports.isParenExpr = exports.isAsClause = exports.isArraySubscript = exports.isStringLiteral = exports.isJsonLiteral = exports.isEmpty = exports.isKeyword = exports.isCreateTableStmt = exports.isFuncArgs = exports.isFuncCall = exports.isValuesClause = void 0;
4
4
  var utils_1 = require("./utils");
5
5
  var is = function (type) {
6
6
  return function (node) {
@@ -9,6 +9,7 @@ var is = function (type) {
9
9
  };
10
10
  exports.isValuesClause = is("values_clause");
11
11
  exports.isFuncCall = is("func_call");
12
+ exports.isFuncArgs = is("func_args");
12
13
  exports.isCreateTableStmt = is("create_table_stmt");
13
14
  exports.isKeyword = is("keyword");
14
15
  exports.isEmpty = is("empty");
@@ -16,3 +17,5 @@ exports.isJsonLiteral = is("json_literal");
16
17
  exports.isStringLiteral = is("string_literal");
17
18
  exports.isArraySubscript = is("array_subscript");
18
19
  exports.isAsClause = is("as_clause");
20
+ exports.isParenExpr = is("paren_expr");
21
+ exports.isListExpr = is("list_expr");
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.analyzeMap = void 0;
4
+ exports.analyzeMap = {
5
+ analyze_stmt: function (print) { return print.spaced(["analyzeKw", "tableKw", "tables"]); },
6
+ };
@@ -25,6 +25,7 @@ exports.createTableMap = {
25
25
  "temporaryKw",
26
26
  "externalKw",
27
27
  "snapshotKw",
28
+ "virtualKw",
28
29
  "tableKw",
29
30
  "ifNotExistsKw",
30
31
  "name",
@@ -44,6 +45,7 @@ exports.createTableMap = {
44
45
  with_partition_columns_clause: function (print) {
45
46
  return print.spaced(["withPartitionColumnsKw", "columns"]);
46
47
  },
48
+ create_table_using_clause: function (print) { return print.spaced(["usingKw", "module"]); },
47
49
  };
48
50
  var printClauses = function (print, node) {
49
51
  if (node.clauses.length === 1 && (0, node_utils_1.isAsClause)(node.clauses[0])) {
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.explainMap = void 0;
4
+ var print_utils_1 = require("../print_utils");
5
+ exports.explainMap = {
6
+ explain_stmt: function (print) {
7
+ return (0, print_utils_1.group)([
8
+ print.spaced(["explainKw", "queryPlanKw"]),
9
+ (0, print_utils_1.indent)([print_utils_1.line, print("statement")]),
10
+ ]);
11
+ },
12
+ };
@@ -33,6 +33,15 @@ exports.exprMap = {
33
33
  }
34
34
  },
35
35
  paren_expr: function (print, node, path) {
36
+ // discard unnecessary nested ((parentheses))
37
+ if ((0, node_utils_1.isParenExpr)(node.expr)) {
38
+ return print("expr");
39
+ }
40
+ // Discard unnecessary parenthesis around function arguments
41
+ if ((0, node_utils_1.isListExpr)(path.getParentNode(0)) &&
42
+ (0, node_utils_1.isFuncArgs)(path.getParentNode(1))) {
43
+ return print("expr");
44
+ }
36
45
  var parent = path.getParentNode();
37
46
  var lineStyle = (0, node_utils_1.isCreateTableStmt)(parent) ? print_utils_1.hardline : print_utils_1.softline;
38
47
  return (0, print_utils_1.group)(["(", (0, print_utils_1.indent)([lineStyle, print("expr")]), lineStyle, ")"]);
@@ -84,8 +93,11 @@ exports.exprMap = {
84
93
  filter_arg: function (print) { return print.spaced(["filterKw", "where"]); },
85
94
  over_arg: function (print) { return print.spaced(["overKw", "window"]); },
86
95
  cast_expr: function (print) { return print(["castKw", "args"]); },
87
- cast_arg: function (print) { return print.spaced(["expr", "asKw", "dataType"]); },
96
+ cast_arg: function (print) { return print.spaced(["expr", "asKw", "dataType", "format"]); },
97
+ cast_format: function (print) { return print.spaced(["formatKw", "string", "timezone"]); },
98
+ cast_format_timezone: function (print) { return print.spaced(["atTimeZoneKw", "timezone"]); },
88
99
  raise_expr: function (print) { return print(["raiseKw", "args"]); },
100
+ raise_expr_type: function (print) { return print("typeKw"); },
89
101
  interval_expr: function (print) { return print.spaced(["intervalKw", "expr", "unit"]); },
90
102
  interval_unit_range: function (print) {
91
103
  return print.spaced(["fromUnitKw", "toKw", "toUnitKw"]);
@@ -109,6 +121,7 @@ exports.exprMap = {
109
121
  timestamp_literal: function (print) { return print.spaced(["timestampKw", "string"]); },
110
122
  json_literal: function (print) { return print.spaced(["jsonKw", "string"]); },
111
123
  identifier: function (print) { return print("text"); },
124
+ variable: function (print) { return print("text"); },
112
125
  };
113
126
  var isBooleanOp = function (_a) {
114
127
  var name = _a.name;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.proceduralLanguageMap = void 0;
4
+ var print_utils_1 = require("../print_utils");
5
+ exports.proceduralLanguageMap = {
6
+ block_stmt: function (print) { return [
7
+ print("beginKw"),
8
+ (0, print_utils_1.indent)([print_utils_1.hardline, (0, print_utils_1.stripTrailingHardline)(print("program"))]),
9
+ print_utils_1.hardline,
10
+ print("endKw"),
11
+ ]; },
12
+ };
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.sqliteMap = void 0;
4
+ var print_utils_1 = require("../print_utils");
5
+ exports.sqliteMap = {
6
+ attach_database_stmt: function (print) {
7
+ return print.spaced(["attachKw", "databaseKw", "file", "asKw", "schema"]);
8
+ },
9
+ detach_database_stmt: function (print) {
10
+ return print.spaced(["detachKw", "databaseKw", "schema"]);
11
+ },
12
+ vacuum_stmt: function (print) {
13
+ return print.spaced(["vacuumKw", "schema", "intoKw", "file"]);
14
+ },
15
+ reindex_stmt: function (print) { return print.spaced(["reindexKw", "table"]); },
16
+ pragma_stmt: function (print) { return print.spaced(["pragmaKw", "pragma"]); },
17
+ pragma_assignment: function (print) { return (0, print_utils_1.join)(" = ", print(["name", "value"])); },
18
+ pragma_func_call: function (print) { return print(["name", "args"]); },
19
+ };
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.transactionMap = void 0;
4
+ exports.transactionMap = {
5
+ start_transaction_stmt: function (print) {
6
+ return print.spaced(["startKw", "behaviorKw", "transactionKw"]);
7
+ },
8
+ commit_transaction_stmt: function (print) {
9
+ return print.spaced(["commitKw", "transactionKw"]);
10
+ },
11
+ rollback_transaction_stmt: function (print) {
12
+ return print.spaced(["rollbackKw", "transactionKw", "savepoint"]);
13
+ },
14
+ rollback_to_savepoint: function (print) {
15
+ return print.spaced(["toKw", "savepointKw", "savepoint"]);
16
+ },
17
+ savepoint_stmt: function (print) { return print.spaced(["savepointKw", "savepoint"]); },
18
+ release_savepoint_stmt: function (print) {
19
+ return print.spaced(["releaseKw", "savepointKw", "savepoint"]);
20
+ },
21
+ };
@@ -14,6 +14,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
14
14
  exports.transformMap = void 0;
15
15
  var alias_1 = require("./alias");
16
16
  var alter_table_1 = require("./alter_table");
17
+ var analyze_1 = require("./analyze");
17
18
  var base_1 = require("./base");
18
19
  var bigquery_1 = require("./bigquery");
19
20
  var constraint_1 = require("./constraint");
@@ -21,14 +22,19 @@ var create_table_1 = require("./create_table");
21
22
  var data_type_1 = require("./data_type");
22
23
  var delete_1 = require("./delete");
23
24
  var drop_table_1 = require("./drop_table");
25
+ var explain_1 = require("./explain");
24
26
  var expr_1 = require("./expr");
25
27
  var frame_1 = require("./frame");
26
28
  var index_1 = require("./index");
27
29
  var insert_1 = require("./insert");
30
+ var procedural_language_1 = require("./procedural_language");
28
31
  var proc_clause_1 = require("./proc_clause");
29
32
  var program_1 = require("./program");
30
33
  var select_1 = require("./select");
34
+ var sqlite_1 = require("./sqlite");
35
+ var transaction_1 = require("./transaction");
36
+ var trigger_1 = require("./trigger");
31
37
  var truncate_1 = require("./truncate");
32
38
  var update_1 = require("./update");
33
39
  var view_1 = require("./view");
34
- exports.transformMap = __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), base_1.baseMap), bigquery_1.bigqueryMap), constraint_1.constraintMap), create_table_1.createTableMap), data_type_1.dataTypeMap), delete_1.deleteMap), drop_table_1.dropTableMap), expr_1.exprMap), frame_1.frameMap), index_1.indexMap), insert_1.insertMap), proc_clause_1.procClauseMap), program_1.programMap), select_1.selectMap), truncate_1.truncateMap), update_1.updateMap), view_1.viewMap);
40
+ 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({}, 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), delete_1.deleteMap), drop_table_1.dropTableMap), explain_1.explainMap), expr_1.exprMap), frame_1.frameMap), index_1.indexMap), insert_1.insertMap), proc_clause_1.procClauseMap), procedural_language_1.proceduralLanguageMap), program_1.programMap), select_1.selectMap), sqlite_1.sqliteMap), transaction_1.transactionMap), trigger_1.triggerMap), truncate_1.truncateMap), update_1.updateMap), view_1.viewMap);
@@ -0,0 +1,44 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.triggerMap = void 0;
13
+ var print_utils_1 = require("../print_utils");
14
+ exports.triggerMap = {
15
+ create_trigger_stmt: function (print, node) {
16
+ return (0, print_utils_1.join)(print_utils_1.hardline, __spreadArray(__spreadArray(__spreadArray([
17
+ print.spaced([
18
+ "createKw",
19
+ "temporaryKw",
20
+ "triggerKw",
21
+ "ifNotExistsKw",
22
+ "name",
23
+ ]),
24
+ print("event")
25
+ ], (node.forEachRowKw ? [print.spaced(["forEachRowKw"])] : []), true), (node.condition ? [print(["condition"])] : []), true), [
26
+ print("body"),
27
+ ], false));
28
+ },
29
+ trigger_event: function (print) {
30
+ return (0, print_utils_1.group)([
31
+ print.spaced(["timeKw", "eventKw", "ofKw"]),
32
+ (0, print_utils_1.indent)([
33
+ print_utils_1.line,
34
+ (0, print_utils_1.join)(print_utils_1.line, __spreadArray(__spreadArray([], print(["columns"]), true), [print.spaced(["onKw", "table"])], false)),
35
+ ]),
36
+ ]);
37
+ },
38
+ trigger_condition: function (print) {
39
+ return (0, print_utils_1.group)([print("whenKw"), (0, print_utils_1.indent)([print_utils_1.line, print("expr")])]);
40
+ },
41
+ drop_trigger_stmt: function (print) {
42
+ return print.spaced(["dropTriggerKw", "ifExistsKw", "trigger"]);
43
+ },
44
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prettier-plugin-sql-cst",
3
- "version": "0.4.0",
3
+ "version": "0.6.0",
4
4
  "description": "Prettier plugin for SQL",
5
5
  "author": "Rene Saarsoo <nene@triin.net>",
6
6
  "license": "GPL-3.0-or-later",
@@ -29,7 +29,7 @@
29
29
  ],
30
30
  "dependencies": {
31
31
  "prettier": "^2.8.2",
32
- "sql-parser-cst": "^0.12.0"
32
+ "sql-parser-cst": "^0.13.0"
33
33
  },
34
34
  "devDependencies": {
35
35
  "@types/jest": "^29.2.5",