prettier-plugin-sql-cst 0.5.0 → 0.7.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 +5 -12
- package/dist/embed.js +13 -0
- package/dist/embedJs.js +53 -0
- package/dist/index.js +3 -2
- package/dist/node_utils.js +6 -1
- package/dist/options.js +9 -0
- package/dist/syntax/bigquery.js +85 -0
- package/dist/syntax/create_table.js +2 -0
- package/dist/syntax/expr.js +15 -1
- package/dist/syntax/function.js +32 -0
- package/dist/syntax/index.js +10 -1
- package/dist/syntax/merge.js +42 -0
- package/dist/syntax/proc_clause.js +10 -1
- package/dist/syntax/procedure.js +22 -0
- package/dist/syntax/schema.js +28 -0
- package/dist/syntax/sqlite.js +0 -6
- package/dist/syntax/transformMap.js +5 -1
- package/dist/syntax/trigger.js +10 -5
- package/dist/syntax/view.js +5 -0
- package/package.json +2 -2
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
|
|
|
@@ -97,21 +96,14 @@ There are also some SQL-specific options:
|
|
|
97
96
|
| API Option | Default | Description |
|
|
98
97
|
| ---------------- | :-----: | ------------------------------------------------------------------------- |
|
|
99
98
|
| `sqlKeywordCase` | `upper` | Converts SQL keywords to `upper` or `lower` case, or `preserve` existing. |
|
|
99
|
+
| `sqlParamTypes` | `[]` | Array of bound parameter types: `?`, `?nr`, `:name`, `@name`, `$name`. |
|
|
100
100
|
|
|
101
101
|
## Limitations and development status
|
|
102
102
|
|
|
103
|
-
Currently this plugin supports
|
|
104
|
-
It also supports most of the **BigQuery** syntax.
|
|
105
|
-
Specifically the formatting of the following BigQuery SQL statements is fully implemented:
|
|
103
|
+
Currently this plugin supports two SQL dialects:
|
|
106
104
|
|
|
107
|
-
-
|
|
108
|
-
-
|
|
109
|
-
- INSERT
|
|
110
|
-
- DELETE
|
|
111
|
-
- TRUNCATE
|
|
112
|
-
- CREATE / DROP / ALTER TABLE
|
|
113
|
-
- CREATE / DROP VIEW
|
|
114
|
-
- transactions (BEGIN, COMMIT, ROLLBACK)
|
|
105
|
+
- **SQLite** - full support.
|
|
106
|
+
- **BigQuery** - most of the common SQL syntax is supported (see [#2][] for implementation progress).
|
|
115
107
|
|
|
116
108
|
[prettier]: https://prettier.io/
|
|
117
109
|
[printWidth]: https://prettier.io/docs/en/options.html#print-width
|
|
@@ -120,3 +112,4 @@ Specifically the formatting of the following BigQuery SQL statements is fully im
|
|
|
120
112
|
[sql-parser-cst]: https://github.com/nene/sql-parser-cst
|
|
121
113
|
[wadler-prettier]: http://homepages.inf.ed.ac.uk/wadler/papers/prettier/prettier.pdf
|
|
122
114
|
[STYLE_GUIDE]: ./STYLE_GUIDE.md
|
|
115
|
+
[#2]: https://github.com/nene/prettier-plugin-sql-cst/issues/2
|
package/dist/embed.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.embed = void 0;
|
|
4
|
+
var embedJs_1 = require("./embedJs");
|
|
5
|
+
var embedJson_1 = require("./embedJson");
|
|
6
|
+
var embed = function () {
|
|
7
|
+
var args = [];
|
|
8
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
9
|
+
args[_i] = arguments[_i];
|
|
10
|
+
}
|
|
11
|
+
return embedJson_1.embedJson.apply(void 0, args) || embedJs_1.embedJs.apply(void 0, args);
|
|
12
|
+
};
|
|
13
|
+
exports.embed = embed;
|
package/dist/embedJs.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.embedJs = void 0;
|
|
15
|
+
var node_utils_1 = require("./node_utils");
|
|
16
|
+
var print_utils_1 = require("./print_utils");
|
|
17
|
+
var embedJs = function (path, print, textToDoc, options) {
|
|
18
|
+
var node = path.getValue();
|
|
19
|
+
var parent = path.getParentNode(0);
|
|
20
|
+
var grandParent = path.getParentNode(1);
|
|
21
|
+
if ((0, node_utils_1.isStringLiteral)(node) &&
|
|
22
|
+
(0, node_utils_1.isAsClause)(parent) &&
|
|
23
|
+
(0, node_utils_1.isCreateFunctionStmt)(grandParent) &&
|
|
24
|
+
grandParent.clauses.some(isJavaScriptLanguageClause)) {
|
|
25
|
+
var quotes = detectQuotes(node.value);
|
|
26
|
+
if (!quotes) {
|
|
27
|
+
// Give up for now. Don't format JavaScript inside the string.
|
|
28
|
+
// Perhaps tackle this corner-case in the future.
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
var js = textToDoc(node.value, __assign(__assign({}, options), { parser: "babel" }));
|
|
32
|
+
return [
|
|
33
|
+
quotes[0],
|
|
34
|
+
(0, print_utils_1.indent)([print_utils_1.hardline, (0, print_utils_1.stripTrailingHardline)(js)]),
|
|
35
|
+
print_utils_1.hardline,
|
|
36
|
+
quotes[1],
|
|
37
|
+
];
|
|
38
|
+
}
|
|
39
|
+
return null;
|
|
40
|
+
};
|
|
41
|
+
exports.embedJs = embedJs;
|
|
42
|
+
var isJavaScriptLanguageClause = function (clause) { return (0, node_utils_1.isLanguageClause)(clause) && clause.name.name === "js"; };
|
|
43
|
+
// Whether to quote the code with single- or double-quotes.
|
|
44
|
+
// Returns undefined when neither can be used without escaping.
|
|
45
|
+
var detectQuotes = function (js) {
|
|
46
|
+
if (!/'''/.test(js)) {
|
|
47
|
+
return ["r'''", "'''"];
|
|
48
|
+
}
|
|
49
|
+
if (!/"""/.test(js)) {
|
|
50
|
+
return ['r"""', '"""'];
|
|
51
|
+
}
|
|
52
|
+
return undefined;
|
|
53
|
+
};
|
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.printers = exports.parsers = exports.languages = exports.options = void 0;
|
|
4
4
|
var sql_parser_cst_1 = require("sql-parser-cst");
|
|
5
5
|
var printSql_1 = require("./printSql");
|
|
6
|
-
var
|
|
6
|
+
var embed_1 = require("./embed");
|
|
7
7
|
var utils_1 = require("./utils");
|
|
8
8
|
var transformCst_1 = require("./transform/transformCst");
|
|
9
9
|
var options_1 = require("./options");
|
|
@@ -27,6 +27,7 @@ var createParser = function (dialect) { return ({
|
|
|
27
27
|
includeRange: true,
|
|
28
28
|
includeComments: true,
|
|
29
29
|
filename: options.filepath,
|
|
30
|
+
paramTypes: options.sqlParamTypes,
|
|
30
31
|
}), text);
|
|
31
32
|
},
|
|
32
33
|
astFormat: "sql-cst",
|
|
@@ -40,7 +41,7 @@ exports.parsers = {
|
|
|
40
41
|
exports.printers = {
|
|
41
42
|
"sql-cst": {
|
|
42
43
|
print: printSql_1.printSql,
|
|
43
|
-
embed:
|
|
44
|
+
embed: embed_1.embed,
|
|
44
45
|
printComment: function (path) {
|
|
45
46
|
return path.getValue().text;
|
|
46
47
|
},
|
package/dist/node_utils.js
CHANGED
|
@@ -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.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 = 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,7 @@ 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");
|
|
22
|
+
exports.isCreateFunctionStmt = is("create_function_stmt");
|
|
23
|
+
exports.isLanguageClause = is("language_clause");
|
package/dist/options.js
CHANGED
|
@@ -17,4 +17,13 @@ exports.options = {
|
|
|
17
17
|
{ value: "lower", description: "forces all keywords to lowercase" },
|
|
18
18
|
],
|
|
19
19
|
},
|
|
20
|
+
sqlParamTypes: {
|
|
21
|
+
type: "string",
|
|
22
|
+
array: true,
|
|
23
|
+
category: "SQL",
|
|
24
|
+
since: "0.7.0",
|
|
25
|
+
default: [{ value: [] }],
|
|
26
|
+
description: "Syntax for bound parameters",
|
|
27
|
+
// Possible values in array: "?" | "?nr" | ":name" | "$name" | "@name"
|
|
28
|
+
},
|
|
20
29
|
};
|
package/dist/syntax/bigquery.js
CHANGED
|
@@ -1,9 +1,94 @@
|
|
|
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.bigqueryMap = void 0;
|
|
13
|
+
var print_utils_1 = require("../print_utils");
|
|
4
14
|
exports.bigqueryMap = {
|
|
5
15
|
bigquery_options: function (print) { return print(["optionsKw", "options"]); },
|
|
6
16
|
bigquery_option_default_collate: function (print) {
|
|
7
17
|
return print.spaced(["defaultCollateKw", "collation"]);
|
|
8
18
|
},
|
|
19
|
+
// ROW ACCESS POLICY
|
|
20
|
+
create_row_access_policy_stmt: function (print) {
|
|
21
|
+
return (0, print_utils_1.join)(print_utils_1.hardline, __spreadArray([
|
|
22
|
+
print.spaced([
|
|
23
|
+
"createKw",
|
|
24
|
+
"orReplaceKw",
|
|
25
|
+
"rowAccessPolicyKw",
|
|
26
|
+
"ifNotExistsKw",
|
|
27
|
+
"name",
|
|
28
|
+
"onKw",
|
|
29
|
+
"table",
|
|
30
|
+
])
|
|
31
|
+
], print("clauses"), true));
|
|
32
|
+
},
|
|
33
|
+
row_access_policy_grant_clause: function (print) {
|
|
34
|
+
return print.spaced(["grantToKw", "grantees"]);
|
|
35
|
+
},
|
|
36
|
+
row_access_policy_filter_clause: function (print) {
|
|
37
|
+
return print.spaced(["filterUsingKw", "expr"]);
|
|
38
|
+
},
|
|
39
|
+
drop_row_access_policy_stmt: function (print) {
|
|
40
|
+
return print.spaced([
|
|
41
|
+
"dropKw",
|
|
42
|
+
"allKw",
|
|
43
|
+
"rowAccessPolicyKw",
|
|
44
|
+
"ifExistsKw",
|
|
45
|
+
"name",
|
|
46
|
+
"onKw",
|
|
47
|
+
"table",
|
|
48
|
+
]);
|
|
49
|
+
},
|
|
50
|
+
// CAPACITY
|
|
51
|
+
create_capacity_stmt: function (print) { return [
|
|
52
|
+
print.spaced(["createKw", "capacityKw", "name"]),
|
|
53
|
+
print_utils_1.hardline,
|
|
54
|
+
print("options"),
|
|
55
|
+
]; },
|
|
56
|
+
drop_capacity_stmt: function (print) {
|
|
57
|
+
return print.spaced(["dropKw", "capacityKw", "ifExistsKw", "name"]);
|
|
58
|
+
},
|
|
59
|
+
// RESERVATION
|
|
60
|
+
create_reservation_stmt: function (print) { return [
|
|
61
|
+
print.spaced(["createKw", "reservationKw", "name"]),
|
|
62
|
+
print_utils_1.hardline,
|
|
63
|
+
print("options"),
|
|
64
|
+
]; },
|
|
65
|
+
drop_reservation_stmt: function (print) {
|
|
66
|
+
return print.spaced(["dropKw", "reservationKw", "ifExistsKw", "name"]);
|
|
67
|
+
},
|
|
68
|
+
// ASSIGNMENT
|
|
69
|
+
create_assignment_stmt: function (print) { return [
|
|
70
|
+
print.spaced(["createKw", "assignmentKw", "name"]),
|
|
71
|
+
print_utils_1.hardline,
|
|
72
|
+
print("options"),
|
|
73
|
+
]; },
|
|
74
|
+
drop_assignment_stmt: function (print) {
|
|
75
|
+
return print.spaced(["dropKw", "assignmentKw", "ifExistsKw", "name"]);
|
|
76
|
+
},
|
|
77
|
+
// ALTER ORGANIZATION
|
|
78
|
+
alter_organization_stmt: function (print) {
|
|
79
|
+
return (0, print_utils_1.join)(print_utils_1.hardline, [print.spaced("alterOrganizationKw"), print("actions")]);
|
|
80
|
+
},
|
|
81
|
+
// ALTER PROJECT
|
|
82
|
+
alter_project_stmt: function (print) {
|
|
83
|
+
return (0, print_utils_1.join)(print_utils_1.hardline, [
|
|
84
|
+
print.spaced(["alterProjectKw", "name"]),
|
|
85
|
+
print("actions"),
|
|
86
|
+
]);
|
|
87
|
+
},
|
|
88
|
+
alter_bi_capacity_stmt: function (print) {
|
|
89
|
+
return (0, print_utils_1.join)(print_utils_1.hardline, [
|
|
90
|
+
print.spaced(["alterBiCapacityKw", "name"]),
|
|
91
|
+
print("actions"),
|
|
92
|
+
]);
|
|
93
|
+
},
|
|
9
94
|
};
|
|
@@ -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])) {
|
package/dist/syntax/expr.js
CHANGED
|
@@ -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,8 @@ 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"); },
|
|
125
|
+
parameter: function (print) { return print("text"); },
|
|
112
126
|
};
|
|
113
127
|
var isBooleanOp = function (_a) {
|
|
114
128
|
var name = _a.name;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.functionMap = void 0;
|
|
4
|
+
var print_utils_1 = require("../print_utils");
|
|
5
|
+
var node_utils_1 = require("../node_utils");
|
|
6
|
+
exports.functionMap = {
|
|
7
|
+
create_function_stmt: function (print, node) { return [
|
|
8
|
+
print.spaced([
|
|
9
|
+
"createKw",
|
|
10
|
+
"orReplaceKw",
|
|
11
|
+
"temporaryKw",
|
|
12
|
+
"tableKw",
|
|
13
|
+
"functionKw",
|
|
14
|
+
"ifNotExistsKw",
|
|
15
|
+
"name",
|
|
16
|
+
]),
|
|
17
|
+
print("params"),
|
|
18
|
+
hasOnlyAsClause(node)
|
|
19
|
+
? [" ", (0, print_utils_1.group)(print("clauses"))]
|
|
20
|
+
: [
|
|
21
|
+
print_utils_1.hardline,
|
|
22
|
+
(0, print_utils_1.join)(print_utils_1.hardline, print("clauses").map(function (cls) { return (0, print_utils_1.group)(cls); })),
|
|
23
|
+
],
|
|
24
|
+
]; },
|
|
25
|
+
function_param: function (print) { return print.spaced(["name", "dataType"]); },
|
|
26
|
+
drop_function_stmt: function (print) {
|
|
27
|
+
return print.spaced(["dropKw", "tableKw", "functionKw", "ifExistsKw", "name"]);
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
var hasOnlyAsClause = function (node) {
|
|
31
|
+
return node.clauses.length === 1 && (0, node_utils_1.isAsClause)(node.clauses[0]);
|
|
32
|
+
};
|
package/dist/syntax/index.js
CHANGED
|
@@ -27,6 +27,15 @@ exports.indexMap = {
|
|
|
27
27
|
], (node.clauses.length > 0 ? [(0, print_utils_1.join)(print_utils_1.hardline, print("clauses"))] : []), true));
|
|
28
28
|
},
|
|
29
29
|
drop_index_stmt: function (print) {
|
|
30
|
-
return print.spaced([
|
|
30
|
+
return print.spaced([
|
|
31
|
+
"dropKw",
|
|
32
|
+
"indexTypeKw",
|
|
33
|
+
"indexKw",
|
|
34
|
+
"ifExistsKw",
|
|
35
|
+
"indexes",
|
|
36
|
+
"onKw",
|
|
37
|
+
"table",
|
|
38
|
+
]);
|
|
31
39
|
},
|
|
40
|
+
verbose_all_columns: function (print) { return print.spaced("allColumnsKw"); },
|
|
32
41
|
};
|
|
@@ -0,0 +1,42 @@
|
|
|
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.mergeMap = void 0;
|
|
13
|
+
var print_utils_1 = require("../print_utils");
|
|
14
|
+
exports.mergeMap = {
|
|
15
|
+
merge_stmt: function (print) {
|
|
16
|
+
return (0, print_utils_1.join)(print_utils_1.line, __spreadArray([
|
|
17
|
+
print.spaced(["mergeKw", "intoKw", "target"]),
|
|
18
|
+
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));
|
|
21
|
+
},
|
|
22
|
+
merge_when_clause: function (print, node) { return [
|
|
23
|
+
(0, print_utils_1.group)([
|
|
24
|
+
print.spaced(["whenKw", "matchedKw", "byKw"]),
|
|
25
|
+
node.condition ? (0, print_utils_1.indent)([print_utils_1.line, print("condition")]) : [],
|
|
26
|
+
[print_utils_1.line, print("thenKw")],
|
|
27
|
+
]),
|
|
28
|
+
(0, print_utils_1.indent)([print_utils_1.hardline, (0, print_utils_1.group)(print("action"))]),
|
|
29
|
+
]; },
|
|
30
|
+
merge_when_condition: function (print) { return print.spaced(["andKw", "expr"]); },
|
|
31
|
+
merge_action_delete: function (print) { return print("deleteKw"); },
|
|
32
|
+
merge_action_insert: function (print, node) { return [
|
|
33
|
+
(0, print_utils_1.group)([
|
|
34
|
+
print("insertKw"),
|
|
35
|
+
node.columns ? (0, print_utils_1.indent)([print_utils_1.hardline, print("columns")]) : [],
|
|
36
|
+
]),
|
|
37
|
+
print_utils_1.line,
|
|
38
|
+
(0, print_utils_1.group)(print("values")),
|
|
39
|
+
]; },
|
|
40
|
+
merge_action_insert_row_clause: function (print) { return print("rowKw"); },
|
|
41
|
+
merge_action_update: function (print) { return print.spaced(["updateKw", "set"]); },
|
|
42
|
+
};
|
|
@@ -1,9 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.procClauseMap = void 0;
|
|
4
|
+
var node_utils_1 = require("../node_utils");
|
|
4
5
|
var print_utils_1 = require("../print_utils");
|
|
5
6
|
exports.procClauseMap = {
|
|
6
|
-
|
|
7
|
+
returns_clause: function (print) { return print.spaced(["returnsKw", "dataType"]); },
|
|
8
|
+
determinism_clause: function (print) { return print.spaced("deterministicKw"); },
|
|
9
|
+
language_clause: function (print) { return print.spaced(["languageKw", "name"]); },
|
|
10
|
+
as_clause: function (print, node) {
|
|
11
|
+
if ((0, node_utils_1.isStringLiteral)(node.expr)) {
|
|
12
|
+
return print.spaced(["asKw", "expr"]);
|
|
13
|
+
}
|
|
14
|
+
return [print("asKw"), (0, print_utils_1.indent)([print_utils_1.hardline, print("expr")])];
|
|
15
|
+
},
|
|
7
16
|
with_connection_clause: function (print) {
|
|
8
17
|
return print.spaced(["withConnectionKw", "connection"]);
|
|
9
18
|
},
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.procedureMap = void 0;
|
|
4
|
+
var print_utils_1 = require("../print_utils");
|
|
5
|
+
exports.procedureMap = {
|
|
6
|
+
create_procedure_stmt: function (print, node) { return [
|
|
7
|
+
print.spaced([
|
|
8
|
+
"createKw",
|
|
9
|
+
"orReplaceKw",
|
|
10
|
+
"procedureKw",
|
|
11
|
+
"ifNotExistsKw",
|
|
12
|
+
"name",
|
|
13
|
+
]),
|
|
14
|
+
print("params"),
|
|
15
|
+
print_utils_1.hardline,
|
|
16
|
+
(0, print_utils_1.join)(print_utils_1.hardline, print("clauses").map(function (clause) { return (0, print_utils_1.group)(clause); })),
|
|
17
|
+
]; },
|
|
18
|
+
procedure_param: function (print) { return print.spaced(["mode", "name", "dataType"]); },
|
|
19
|
+
drop_procedure_stmt: function (print) {
|
|
20
|
+
return print.spaced(["dropKw", "procedureKw", "ifExistsKw", "name"]);
|
|
21
|
+
},
|
|
22
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
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.schemaMap = void 0;
|
|
13
|
+
var print_utils_1 = require("../print_utils");
|
|
14
|
+
exports.schemaMap = {
|
|
15
|
+
create_schema_stmt: function (print) {
|
|
16
|
+
return (0, print_utils_1.join)(print_utils_1.hardline, __spreadArray([
|
|
17
|
+
print.spaced(["createSchemaKw", "ifNotExistsKw", "name"])
|
|
18
|
+
], print("options"), true));
|
|
19
|
+
},
|
|
20
|
+
drop_schema_stmt: function (print) {
|
|
21
|
+
return print.spaced(["dropSchemaKw", "ifExistsKw", "name", "behaviorKw"]);
|
|
22
|
+
},
|
|
23
|
+
alter_schema_stmt: function (print) {
|
|
24
|
+
return (0, print_utils_1.join)(print_utils_1.hardline, __spreadArray([
|
|
25
|
+
print.spaced(["alterSchemaKw", "ifExistsKw", "name"])
|
|
26
|
+
], print("actions"), true));
|
|
27
|
+
},
|
|
28
|
+
};
|
package/dist/syntax/sqlite.js
CHANGED
|
@@ -16,10 +16,4 @@ exports.sqliteMap = {
|
|
|
16
16
|
pragma_stmt: function (print) { return print.spaced(["pragmaKw", "pragma"]); },
|
|
17
17
|
pragma_assignment: function (print) { return (0, print_utils_1.join)(" = ", print(["name", "value"])); },
|
|
18
18
|
pragma_func_call: function (print) { return print(["name", "args"]); },
|
|
19
|
-
create_virtual_table_stmt: function (print) {
|
|
20
|
-
return (0, print_utils_1.join)(print_utils_1.hardline, [
|
|
21
|
-
print.spaced(["createVirtualTableKw", "ifNotExistsKw", "name"]),
|
|
22
|
-
print.spaced(["usingKw", "module"]),
|
|
23
|
-
]);
|
|
24
|
-
},
|
|
25
19
|
};
|
|
@@ -25,11 +25,15 @@ var drop_table_1 = require("./drop_table");
|
|
|
25
25
|
var explain_1 = require("./explain");
|
|
26
26
|
var expr_1 = require("./expr");
|
|
27
27
|
var frame_1 = require("./frame");
|
|
28
|
+
var function_1 = require("./function");
|
|
28
29
|
var index_1 = require("./index");
|
|
29
30
|
var insert_1 = require("./insert");
|
|
31
|
+
var merge_1 = require("./merge");
|
|
30
32
|
var procedural_language_1 = require("./procedural_language");
|
|
33
|
+
var procedure_1 = require("./procedure");
|
|
31
34
|
var proc_clause_1 = require("./proc_clause");
|
|
32
35
|
var program_1 = require("./program");
|
|
36
|
+
var schema_1 = require("./schema");
|
|
33
37
|
var select_1 = require("./select");
|
|
34
38
|
var sqlite_1 = require("./sqlite");
|
|
35
39
|
var transaction_1 = require("./transaction");
|
|
@@ -37,4 +41,4 @@ var trigger_1 = require("./trigger");
|
|
|
37
41
|
var truncate_1 = require("./truncate");
|
|
38
42
|
var update_1 = require("./update");
|
|
39
43
|
var view_1 = require("./view");
|
|
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);
|
|
44
|
+
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({}, 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), function_1.functionMap), index_1.indexMap), insert_1.insertMap), merge_1.mergeMap), 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);
|
package/dist/syntax/trigger.js
CHANGED
|
@@ -21,15 +21,20 @@ exports.triggerMap = {
|
|
|
21
21
|
"ifNotExistsKw",
|
|
22
22
|
"name",
|
|
23
23
|
]),
|
|
24
|
-
|
|
24
|
+
print("event")
|
|
25
25
|
], (node.forEachRowKw ? [print.spaced(["forEachRowKw"])] : []), true), (node.condition ? [print(["condition"])] : []), true), [
|
|
26
26
|
print("body"),
|
|
27
27
|
], false));
|
|
28
28
|
},
|
|
29
|
-
trigger_event: function (print
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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
|
+
},
|
|
33
38
|
trigger_condition: function (print) {
|
|
34
39
|
return (0, print_utils_1.group)([print("whenKw"), (0, print_utils_1.indent)([print_utils_1.line, print("expr")])]);
|
|
35
40
|
},
|
package/dist/syntax/view.js
CHANGED
|
@@ -24,4 +24,9 @@ exports.viewMap = {
|
|
|
24
24
|
drop_view_stmt: function (print) {
|
|
25
25
|
return print.spaced(["dropKw", "materializedKw", "viewKw", "ifExistsKw", "views"]);
|
|
26
26
|
},
|
|
27
|
+
alter_view_stmt: function (print) { return [
|
|
28
|
+
print.spaced(["alterKw", "materializedKw", "viewKw", "ifExistsKw", "name"]),
|
|
29
|
+
print_utils_1.hardline,
|
|
30
|
+
(0, print_utils_1.join)(print_utils_1.hardline, print("actions")),
|
|
31
|
+
]; },
|
|
27
32
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "prettier-plugin-sql-cst",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.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.
|
|
32
|
+
"sql-parser-cst": "^0.14.0"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"@types/jest": "^29.2.5",
|