prettier-plugin-sql-cst 0.18.0 → 0.19.1
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/dist/CstToDocMap.d.ts +2 -2
- package/dist/CstToDocMap.js +1 -2
- package/dist/PrintFn.js +1 -2
- package/dist/embed.js +5 -13
- package/dist/embedJs.js +28 -84
- package/dist/embedJson.js +29 -85
- package/dist/embedSql.js +26 -76
- package/dist/index.js +28 -34
- package/dist/node_utils.d.ts +1 -0
- package/dist/node_utils.js +44 -54
- package/dist/options.js +1 -4
- package/dist/printComment.js +2 -6
- package/dist/printSql.js +29 -39
- package/dist/print_utils.js +19 -38
- package/dist/syntax/alias.js +2 -5
- package/dist/syntax/alter_action.js +115 -208
- package/dist/syntax/alter_table.js +18 -27
- package/dist/syntax/analyze.js +3 -8
- package/dist/syntax/base.js +6 -9
- package/dist/syntax/cast.js +3 -6
- package/dist/syntax/comment.js +53 -122
- package/dist/syntax/constraint.d.ts +1 -1
- package/dist/syntax/constraint.js +54 -90
- package/dist/syntax/create_table.js +49 -87
- package/dist/syntax/data_type.js +25 -44
- package/dist/syntax/dcl.js +78 -136
- package/dist/syntax/delete.js +4 -9
- package/dist/syntax/dialects/bigquery.js +70 -116
- package/dist/syntax/dialects/mysql.js +2 -5
- package/dist/syntax/dialects/postgresql.js +8 -13
- package/dist/syntax/dialects/sqlite.js +8 -17
- package/dist/syntax/do.js +3 -6
- package/dist/syntax/domain.js +10 -19
- package/dist/syntax/drop_table.js +10 -15
- package/dist/syntax/explain.js +6 -11
- package/dist/syntax/expr.js +124 -173
- package/dist/syntax/extension.js +12 -21
- package/dist/syntax/frame.js +11 -16
- package/dist/syntax/function.js +53 -63
- package/dist/syntax/index.js +54 -81
- package/dist/syntax/insert.js +32 -49
- package/dist/syntax/merge.js +25 -30
- package/dist/syntax/other_clauses.js +5 -14
- package/dist/syntax/parameter.js +13 -26
- package/dist/syntax/policy.js +26 -41
- package/dist/syntax/prepared_statements.js +23 -43
- package/dist/syntax/proc_clause.js +10 -15
- package/dist/syntax/procedural_language.js +80 -111
- package/dist/syntax/procedure.js +36 -40
- package/dist/syntax/program.js +15 -22
- package/dist/syntax/publication.js +26 -47
- package/dist/syntax/rename_table.js +7 -12
- package/dist/syntax/role.js +30 -55
- package/dist/syntax/schema.js +17 -35
- package/dist/syntax/select.js +157 -226
- package/dist/syntax/sequence.js +35 -52
- package/dist/syntax/subscription.js +9 -24
- package/dist/syntax/transaction.js +18 -33
- package/dist/syntax/transformMap.js +99 -63
- package/dist/syntax/trigger.js +48 -72
- package/dist/syntax/truncate.js +9 -14
- package/dist/syntax/type.js +11 -22
- package/dist/syntax/unsupported_grammar.js +3 -6
- package/dist/syntax/update.js +7 -14
- package/dist/syntax/view.js +32 -43
- package/dist/transform/addFinalSemicolon.js +5 -9
- package/dist/transform/aliasAs.js +4 -8
- package/dist/transform/canonicKeywords.js +16 -20
- package/dist/transform/canonicOperators.js +8 -12
- package/dist/transform/comments.js +10 -31
- package/dist/transform/stripTrailingCommas.js +7 -11
- package/dist/transform/transformCst.js +13 -17
- package/dist/transform/transformUtils.js +2 -6
- package/dist/utils.js +9 -30
- package/dist/visitAllNodes.js +8 -13
- package/package.json +9 -8
package/dist/syntax/expr.js
CHANGED
|
@@ -1,58 +1,46 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.printLiteral = exports.exprMap = void 0;
|
|
13
|
-
var print_utils_1 = require("../print_utils");
|
|
14
|
-
var node_utils_1 = require("../node_utils");
|
|
15
|
-
var utils_1 = require("../utils");
|
|
16
|
-
exports.exprMap = {
|
|
17
|
-
list_expr: function (print, node, path) {
|
|
18
|
-
var parent = path.getParentNode();
|
|
19
|
-
var children = print("items").map(function (it) { return (0, print_utils_1.group)(it); });
|
|
20
|
-
var lineType = (0, node_utils_1.isValuesClause)(parent) ? print_utils_1.hardline : print_utils_1.line;
|
|
1
|
+
import { join, line, softline, hardline, indent, group, stripTrailingHardline, } from "../print_utils";
|
|
2
|
+
import { isCreateTableStmt, isKeyword, isValuesClause, isEmpty, isArraySubscript, isParenExpr, isFuncArgs, isListExpr, isProgram, isSelectStmt, isCompoundSelectStmt, isBigqueryQuotedMemberExpr, isFuncCall, isMemberExpr, isCreateFunctionStmt, isAlterFunctionStmt, isAlterActionRename, isCreateProcedureStmt, isAlterProcedureStmt, isCreateTriggerStmt, isExecuteClause, isFunctionSignature, } from "../node_utils";
|
|
3
|
+
import { isString, last } from "../utils";
|
|
4
|
+
export const exprMap = {
|
|
5
|
+
list_expr: (print, node, path) => {
|
|
6
|
+
const parent = path.getParentNode();
|
|
7
|
+
const children = print("items").map((it) => group(it));
|
|
8
|
+
const lineType = isValuesClause(parent) ? hardline : line;
|
|
21
9
|
// When last item is type:empty, we're dealing with a trailing comma.
|
|
22
10
|
// Don't add a space (or newline) after it.
|
|
23
11
|
// We still want to print it though, as it might have comments attached.
|
|
24
|
-
if (
|
|
12
|
+
if (isEmpty(last(node.items))) {
|
|
25
13
|
return [
|
|
26
|
-
|
|
14
|
+
join([",", lineType], children.slice(0, -1)),
|
|
27
15
|
",",
|
|
28
|
-
|
|
16
|
+
last(children),
|
|
29
17
|
];
|
|
30
18
|
}
|
|
31
19
|
else {
|
|
32
|
-
return
|
|
20
|
+
return join([",", lineType], children);
|
|
33
21
|
}
|
|
34
22
|
},
|
|
35
|
-
paren_expr:
|
|
23
|
+
paren_expr: (print, node, path) => {
|
|
36
24
|
// discard unnecessary nested ((parentheses))
|
|
37
|
-
if (
|
|
25
|
+
if (isParenExpr(node.expr)) {
|
|
38
26
|
return print("expr");
|
|
39
27
|
}
|
|
40
28
|
// Discard unnecessary parenthesis around function arguments
|
|
41
|
-
if (
|
|
42
|
-
|
|
43
|
-
!
|
|
44
|
-
!
|
|
29
|
+
if (isListExpr(path.getParentNode(0)) &&
|
|
30
|
+
isFuncArgs(path.getParentNode(1)) &&
|
|
31
|
+
!isSelectStmt(node.expr) &&
|
|
32
|
+
!isCompoundSelectStmt(node.expr)) {
|
|
45
33
|
return print("expr");
|
|
46
34
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
?
|
|
50
|
-
:
|
|
51
|
-
return
|
|
52
|
-
},
|
|
53
|
-
binary_expr:
|
|
54
|
-
if (
|
|
55
|
-
return
|
|
35
|
+
const parent = path.getParentNode();
|
|
36
|
+
const lineStyle = isCreateTableStmt(parent) && print.dynamicLine() === hardline
|
|
37
|
+
? hardline
|
|
38
|
+
: softline;
|
|
39
|
+
return group(["(", indent([lineStyle, print("expr")]), lineStyle, ")"]);
|
|
40
|
+
},
|
|
41
|
+
binary_expr: (print, node) => {
|
|
42
|
+
if (isKeyword(node.operator) && isBooleanOp(node.operator)) {
|
|
43
|
+
return join(line, [print("left"), print.spaced(["operator", "right"])]);
|
|
56
44
|
}
|
|
57
45
|
if (node.operator === "") {
|
|
58
46
|
// String concatenation with whitespace (MySQL / MariaDB)
|
|
@@ -60,129 +48,109 @@ exports.exprMap = {
|
|
|
60
48
|
}
|
|
61
49
|
return print.spaced(["left", "operator", "right"]);
|
|
62
50
|
},
|
|
63
|
-
prefix_op_expr:
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
between_expr: function (print) {
|
|
68
|
-
return print.spaced(["left", "betweenKw", "begin", "andKw", "end"]);
|
|
69
|
-
},
|
|
70
|
-
case_expr: function (print) { return [
|
|
51
|
+
prefix_op_expr: (print, node) => (isString(node.operator) ? print : print.spaced)(["operator", "expr"]),
|
|
52
|
+
postfix_op_expr: (print) => print.spaced(["expr", "operator"]),
|
|
53
|
+
between_expr: (print) => print.spaced(["left", "betweenKw", "begin", "andKw", "end"]),
|
|
54
|
+
case_expr: (print) => [
|
|
71
55
|
print.spaced(["caseKw", "expr"]),
|
|
72
|
-
|
|
73
|
-
|
|
56
|
+
indent([hardline, join(hardline, print("clauses"))]),
|
|
57
|
+
hardline,
|
|
74
58
|
print("endKw"),
|
|
75
|
-
]
|
|
76
|
-
case_when:
|
|
77
|
-
if (
|
|
59
|
+
],
|
|
60
|
+
case_when: (print, node) => {
|
|
61
|
+
if (isProgram(node.result)) {
|
|
78
62
|
return [
|
|
79
63
|
print.spaced(["whenKw", "condition", "thenKw"]),
|
|
80
|
-
|
|
64
|
+
indent([hardline, stripTrailingHardline(print("result"))]),
|
|
81
65
|
];
|
|
82
66
|
}
|
|
83
67
|
return print.spaced(["whenKw", "condition", "thenKw", "result"]);
|
|
84
68
|
},
|
|
85
|
-
case_else:
|
|
86
|
-
if (
|
|
69
|
+
case_else: (print, node) => {
|
|
70
|
+
if (isProgram(node.result)) {
|
|
87
71
|
return [
|
|
88
72
|
print("elseKw"),
|
|
89
|
-
|
|
73
|
+
indent([hardline, stripTrailingHardline(print("result"))]),
|
|
90
74
|
];
|
|
91
75
|
}
|
|
92
76
|
return print.spaced(["elseKw", "result"]);
|
|
93
77
|
},
|
|
94
|
-
member_expr:
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
array_slice_specifier: function (print) { return [print("from"), ":", print("to")]; },
|
|
105
|
-
func_call: function (print) {
|
|
106
|
-
var fnCall = print(["name", "args"]);
|
|
107
|
-
var extras = print(["filter", "over"]);
|
|
78
|
+
member_expr: (print, node) => isArraySubscript(node.property)
|
|
79
|
+
? print(["object", "property"])
|
|
80
|
+
: [print("object"), ".", print("property")],
|
|
81
|
+
bigquery_quoted_member_expr: (print) => ["`", print("expr"), "`"],
|
|
82
|
+
array_subscript: (print) => group(["[", indent([softline, print("expr")]), softline, "]"]),
|
|
83
|
+
array_subscript_specifier: (print) => print(["specifierKw", "args"]),
|
|
84
|
+
array_slice_specifier: (print) => [print("from"), ":", print("to")],
|
|
85
|
+
func_call: (print) => {
|
|
86
|
+
const fnCall = print(["name", "args"]);
|
|
87
|
+
const extras = print(["filter", "over"]);
|
|
108
88
|
if (extras.length > 1) {
|
|
109
|
-
return
|
|
89
|
+
return group([fnCall, indent([line, join(line, extras)])]);
|
|
110
90
|
}
|
|
111
91
|
else {
|
|
112
|
-
return
|
|
92
|
+
return group(join(" ", [fnCall, ...extras]));
|
|
113
93
|
}
|
|
114
94
|
},
|
|
115
|
-
func_args:
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
])
|
|
128
|
-
|
|
129
|
-
cast_expr:
|
|
130
|
-
cast_arg:
|
|
131
|
-
cast_format:
|
|
132
|
-
cast_format_timezone:
|
|
133
|
-
cast_operator_expr:
|
|
95
|
+
func_args: (print, node) => join(line, [
|
|
96
|
+
...print(["distinctKw", "args"]),
|
|
97
|
+
...(node.nullHandlingKw ? print.spaced("nullHandlingKw") : []),
|
|
98
|
+
...print(["orderBy", "limit", "having"]),
|
|
99
|
+
]),
|
|
100
|
+
filter_arg: (print) => print.spaced(["filterKw", "where"]),
|
|
101
|
+
over_arg: (print) => print.spaced(["overKw", "window"]),
|
|
102
|
+
having_arg: (print) => print.spaced(["havingKw", "minMaxKw", "expr"]),
|
|
103
|
+
named_arg: (print) => group([
|
|
104
|
+
print("name"),
|
|
105
|
+
" ",
|
|
106
|
+
print("operator"),
|
|
107
|
+
indent([line, print("value")]),
|
|
108
|
+
]),
|
|
109
|
+
cast_expr: (print) => print(["castKw", "args"]),
|
|
110
|
+
cast_arg: (print) => print.spaced(["expr", "asKw", "dataType", "format"]),
|
|
111
|
+
cast_format: (print) => print.spaced(["formatKw", "string", "timezone"]),
|
|
112
|
+
cast_format_timezone: (print) => print.spaced(["atTimeZoneKw", "timezone"]),
|
|
113
|
+
cast_operator_expr: (print) => [
|
|
134
114
|
print("left"),
|
|
135
115
|
print("operator"),
|
|
136
116
|
print("right"),
|
|
137
|
-
]
|
|
138
|
-
string_with_charset:
|
|
139
|
-
raise_expr:
|
|
140
|
-
raise_expr_type:
|
|
141
|
-
extract_expr:
|
|
142
|
-
extract_from:
|
|
143
|
-
week_expr:
|
|
144
|
-
interval_literal:
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
typed_expr: function (print) { return print(["dataType", "expr"]); },
|
|
155
|
-
row_constructor: function (print) { return print(["rowKw", "row"]); },
|
|
156
|
-
array_constructor: function (print) { return print(["arrayKw", "expr"]); },
|
|
157
|
-
quantifier_expr: function (print) { return print.spaced(["quantifierKw", "expr"]); },
|
|
158
|
-
full_text_match_expr: function (print) {
|
|
159
|
-
return print.spaced(["matchKw", "columns", "againstKw", "args"]);
|
|
160
|
-
},
|
|
161
|
-
full_text_match_args: function (print) { return print.spaced(["expr", "modifier"]); },
|
|
117
|
+
],
|
|
118
|
+
string_with_charset: (print) => ["_", print(["charset", "string"])],
|
|
119
|
+
raise_expr: (print) => print(["raiseKw", "args"]),
|
|
120
|
+
raise_expr_type: (print) => print("typeKw"),
|
|
121
|
+
extract_expr: (print) => print(["extractKw", "args"]),
|
|
122
|
+
extract_from: (print) => print.spaced(["unit", "fromKw", "expr"]),
|
|
123
|
+
week_expr: (print) => print(["weekKw", "args"]),
|
|
124
|
+
interval_literal: (print) => print.spaced(["intervalKw", "precision", "value", "unit"]),
|
|
125
|
+
array_literal_expr: (print) => print(["arrayKw", "expr"]),
|
|
126
|
+
array_expr: (print) => group(["[", indent([softline, print("expr")]), softline, "]"]),
|
|
127
|
+
struct_expr: (print) => group(["(", indent([softline, print("expr")]), softline, ")"]),
|
|
128
|
+
typed_expr: (print) => print(["dataType", "expr"]),
|
|
129
|
+
row_constructor: (print) => print(["rowKw", "row"]),
|
|
130
|
+
array_constructor: (print) => print(["arrayKw", "expr"]),
|
|
131
|
+
quantifier_expr: (print) => print.spaced(["quantifierKw", "expr"]),
|
|
132
|
+
full_text_match_expr: (print) => print.spaced(["matchKw", "columns", "againstKw", "args"]),
|
|
133
|
+
full_text_match_args: (print) => print.spaced(["expr", "modifier"]),
|
|
162
134
|
/** cst-ignore: value */
|
|
163
|
-
number_literal:
|
|
135
|
+
number_literal: (print) => print("text"),
|
|
164
136
|
/** cst-ignore: value */
|
|
165
|
-
boolean_literal:
|
|
166
|
-
return (0, exports.printLiteral)(node.valueKw, options);
|
|
167
|
-
},
|
|
137
|
+
boolean_literal: (print, node, path, options) => printLiteral(node.valueKw, options),
|
|
168
138
|
/** cst-ignore: value */
|
|
169
|
-
string_literal:
|
|
139
|
+
string_literal: (print) => print("text"),
|
|
170
140
|
/** cst-ignore: value */
|
|
171
|
-
blob_literal:
|
|
141
|
+
blob_literal: (print) => print("text"),
|
|
172
142
|
/** cst-ignore: value */
|
|
173
|
-
null_literal:
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
json_literal: function (print) { return print.spaced(["jsonKw", "string"]); },
|
|
183
|
-
jsonb_literal: function (print) { return print.spaced(["jsonbKw", "string"]); },
|
|
143
|
+
null_literal: (print, node, path, options) => printLiteral(node.nullKw, options),
|
|
144
|
+
numeric_literal: (print) => print.spaced(["numericKw", "string"]),
|
|
145
|
+
bignumeric_literal: (print) => print.spaced(["bignumericKw", "string"]),
|
|
146
|
+
date_literal: (print) => print.spaced(["dateKw", "string"]),
|
|
147
|
+
time_literal: (print) => print.spaced(["timeKw", "string"]),
|
|
148
|
+
datetime_literal: (print) => print.spaced(["datetimeKw", "string"]),
|
|
149
|
+
timestamp_literal: (print) => print.spaced(["timestampKw", "string"]),
|
|
150
|
+
json_literal: (print) => print.spaced(["jsonKw", "string"]),
|
|
151
|
+
jsonb_literal: (print) => print.spaced(["jsonbKw", "string"]),
|
|
184
152
|
/** cst-ignore: name */
|
|
185
|
-
identifier:
|
|
153
|
+
identifier: (print, node, path, options) => {
|
|
186
154
|
if (isQuotedIdentifier(node) || isInsideBigqueryQuotedMemberExpr(path)) {
|
|
187
155
|
return print("text");
|
|
188
156
|
}
|
|
@@ -196,14 +164,10 @@ exports.exprMap = {
|
|
|
196
164
|
}
|
|
197
165
|
},
|
|
198
166
|
/** cst-ignore: name */
|
|
199
|
-
variable:
|
|
200
|
-
|
|
201
|
-
},
|
|
202
|
-
parameter: function (print, node, path, options) {
|
|
203
|
-
return isQuotedParameter(node) ? print("text") : printIdentifier(node, options);
|
|
204
|
-
},
|
|
167
|
+
variable: (print, node, path, options) => isQuotedVariable(node) ? print("text") : printIdentifier(node, options),
|
|
168
|
+
parameter: (print, node, path, options) => isQuotedParameter(node) ? print("text") : printIdentifier(node, options),
|
|
205
169
|
};
|
|
206
|
-
|
|
170
|
+
export const printLiteral = (node, options) => {
|
|
207
171
|
switch (options.sqlLiteralCase) {
|
|
208
172
|
case "preserve":
|
|
209
173
|
return node.text;
|
|
@@ -213,8 +177,7 @@ var printLiteral = function (node, options) {
|
|
|
213
177
|
return node.text.toLowerCase();
|
|
214
178
|
}
|
|
215
179
|
};
|
|
216
|
-
|
|
217
|
-
var printIdentifier = function (node, options) {
|
|
180
|
+
const printIdentifier = (node, options) => {
|
|
218
181
|
switch (options.sqlIdentifierCase) {
|
|
219
182
|
case "preserve":
|
|
220
183
|
return node.text;
|
|
@@ -224,7 +187,7 @@ var printIdentifier = function (node, options) {
|
|
|
224
187
|
return node.text.toLowerCase();
|
|
225
188
|
}
|
|
226
189
|
};
|
|
227
|
-
|
|
190
|
+
const printFunctionName = (node, options) => {
|
|
228
191
|
switch (options.sqlFunctionCase) {
|
|
229
192
|
case "preserve":
|
|
230
193
|
return node.text;
|
|
@@ -234,40 +197,28 @@ var printFunctionName = function (node, options) {
|
|
|
234
197
|
return node.text.toLowerCase();
|
|
235
198
|
}
|
|
236
199
|
};
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
var isQuotedParameter = function (node) { return /`$/.test(node.text); };
|
|
244
|
-
var isInsideBigqueryQuotedMemberExpr = function (path) {
|
|
245
|
-
return path.ancestors.some(node_utils_1.isBigqueryQuotedMemberExpr);
|
|
246
|
-
};
|
|
247
|
-
var isFunctionName = function (node, path) {
|
|
248
|
-
var parent = path.parent;
|
|
200
|
+
const isQuotedIdentifier = (node) => node.name !== node.text;
|
|
201
|
+
const isQuotedVariable = (node) => !(node.text === "@" + node.name || node.text === "@@" + node.name);
|
|
202
|
+
const isQuotedParameter = (node) => /`$/.test(node.text);
|
|
203
|
+
const isInsideBigqueryQuotedMemberExpr = (path) => path.ancestors.some(isBigqueryQuotedMemberExpr);
|
|
204
|
+
const isFunctionName = (node, path) => {
|
|
205
|
+
const parent = path.parent;
|
|
249
206
|
if (isFunctionContext(parent, path.grandparent)) {
|
|
250
207
|
return true;
|
|
251
208
|
}
|
|
252
|
-
if (
|
|
253
|
-
|
|
209
|
+
if (isMemberExpr(parent) && parent.property === node) {
|
|
210
|
+
const [_, gp, ggp] = path.ancestors;
|
|
254
211
|
return isFunctionContext(gp, ggp);
|
|
255
212
|
}
|
|
256
213
|
return false;
|
|
257
214
|
};
|
|
258
|
-
|
|
259
|
-
return (
|
|
260
|
-
(
|
|
261
|
-
(
|
|
262
|
-
(
|
|
263
|
-
(
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
(0, node_utils_1.isDropFunctionStmt)(node) ||
|
|
267
|
-
(0, node_utils_1.isDropProcedureStmt)(node) ||
|
|
268
|
-
((0, node_utils_1.isExecuteClause)(node) && (0, node_utils_1.isCreateTriggerStmt)(parent)));
|
|
269
|
-
};
|
|
270
|
-
var isBooleanOp = function (_a) {
|
|
271
|
-
var name = _a.name;
|
|
272
|
-
return name === "AND" || name === "OR";
|
|
215
|
+
const isFunctionContext = (node, parent) => {
|
|
216
|
+
return (isFuncCall(node) ||
|
|
217
|
+
isFunctionSignature(node) ||
|
|
218
|
+
isCreateFunctionStmt(node) ||
|
|
219
|
+
isCreateProcedureStmt(node) ||
|
|
220
|
+
(isAlterActionRename(node) &&
|
|
221
|
+
(isAlterFunctionStmt(parent) || isAlterProcedureStmt(parent))) ||
|
|
222
|
+
(isExecuteClause(node) && isCreateTriggerStmt(parent)));
|
|
273
223
|
};
|
|
224
|
+
const isBooleanOp = ({ name }) => name === "AND" || name === "OR";
|
package/dist/syntax/extension.js
CHANGED
|
@@ -1,22 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
},
|
|
14
|
-
extension_cascade_clause: function (print) { return (0, print_utils_1.group)(print.spaced(["cascadeKw"])); },
|
|
15
|
-
extension_schema_clause: function (print) { return (0, print_utils_1.group)(print.spaced(["schemaKw", "name"])); },
|
|
16
|
-
extension_version_clause: function (print) {
|
|
17
|
-
return (0, print_utils_1.group)(print.spaced(["versionKw", "name"]));
|
|
18
|
-
},
|
|
19
|
-
drop_extension_stmt: function (print) {
|
|
20
|
-
return (0, print_utils_1.group)(print.spaced(["dropExtensionKw", "ifExistsKw", "names", "behaviorKw"]));
|
|
21
|
-
},
|
|
1
|
+
import { group, indent, line } from "../print_utils";
|
|
2
|
+
export const extensionMap = {
|
|
3
|
+
create_extension_stmt: (print, node) => group([
|
|
4
|
+
print.spaced(["createExtensionKw", "ifNotExistsKw", "name"]),
|
|
5
|
+
node.clauses.length > 0
|
|
6
|
+
? indent([line, print.spaced(["withKw", "clauses"])])
|
|
7
|
+
: [],
|
|
8
|
+
]),
|
|
9
|
+
extension_cascade_clause: (print) => group(print.spaced(["cascadeKw"])),
|
|
10
|
+
extension_schema_clause: (print) => group(print.spaced(["schemaKw", "name"])),
|
|
11
|
+
extension_version_clause: (print) => group(print.spaced(["versionKw", "name"])),
|
|
12
|
+
drop_extension_stmt: (print) => group(print.spaced(["dropExtensionKw", "ifExistsKw", "names", "behaviorKw"])),
|
|
22
13
|
};
|
package/dist/syntax/frame.js
CHANGED
|
@@ -1,18 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var print_utils_1 = require("../print_utils");
|
|
5
|
-
exports.frameMap = {
|
|
6
|
-
frame_clause: function (print, node) { return [
|
|
1
|
+
import { hardline } from "../print_utils";
|
|
2
|
+
export const frameMap = {
|
|
3
|
+
frame_clause: (print, node) => [
|
|
7
4
|
print.spaced(["unitKw", "extent"]),
|
|
8
|
-
node.exclusion ? [
|
|
9
|
-
]
|
|
10
|
-
frame_bound_current_row:
|
|
11
|
-
frame_bound_preceding:
|
|
12
|
-
frame_bound_following:
|
|
13
|
-
frame_unbounded:
|
|
14
|
-
frame_between:
|
|
15
|
-
|
|
16
|
-
},
|
|
17
|
-
frame_exclusion: function (print) { return print.spaced(["excludeKw", "kindKw"]); },
|
|
5
|
+
node.exclusion ? [hardline, print("exclusion")] : [],
|
|
6
|
+
],
|
|
7
|
+
frame_bound_current_row: (print) => print.spaced("currentRowKw"),
|
|
8
|
+
frame_bound_preceding: (print) => print.spaced(["expr", "precedingKw"]),
|
|
9
|
+
frame_bound_following: (print) => print.spaced(["expr", "followingKw"]),
|
|
10
|
+
frame_unbounded: (print) => print.spaced("unboundedKw"),
|
|
11
|
+
frame_between: (print) => print.spaced(["betweenKw", "begin", "andKw", "end"]),
|
|
12
|
+
frame_exclusion: (print) => print.spaced(["excludeKw", "kindKw"]),
|
|
18
13
|
};
|
package/dist/syntax/function.js
CHANGED
|
@@ -1,65 +1,55 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
},
|
|
46
|
-
drop_function_stmt: function (print) {
|
|
47
|
-
return (0, print_utils_1.group)([
|
|
48
|
-
print.spaced(["dropKw", "tableKw", "functionKw", "ifExistsKw", "name"]),
|
|
49
|
-
print.spaced(["params", "behaviorKw"]),
|
|
50
|
-
]);
|
|
51
|
-
},
|
|
1
|
+
import { group, hardline, join } from "../print_utils";
|
|
2
|
+
import { isAsClause } from "../node_utils";
|
|
3
|
+
export const functionMap = {
|
|
4
|
+
create_function_stmt: (print, node) => group([
|
|
5
|
+
print.spaced([
|
|
6
|
+
"createKw",
|
|
7
|
+
"orReplaceKw",
|
|
8
|
+
"temporaryKw",
|
|
9
|
+
"tableKw",
|
|
10
|
+
"functionKw",
|
|
11
|
+
"ifNotExistsKw",
|
|
12
|
+
"name",
|
|
13
|
+
]),
|
|
14
|
+
print("params"),
|
|
15
|
+
hasOnlyAsClause(node)
|
|
16
|
+
? [" ", group(print("clauses"))]
|
|
17
|
+
: [
|
|
18
|
+
hardline,
|
|
19
|
+
join(hardline, print("clauses").map((cls) => group(cls))),
|
|
20
|
+
],
|
|
21
|
+
]),
|
|
22
|
+
function_signature: (print) => print(["name", "params"]),
|
|
23
|
+
function_param: (print) => print.spaced(["mode", "name", "dataType", "default"]),
|
|
24
|
+
function_param_default: (print) => print.spaced(["operator", "expr"]),
|
|
25
|
+
return_clause: (print) => print.spaced(["returnKw", "expr"]),
|
|
26
|
+
function_behavior_clause: (print) => print.spaced(["behaviorKw"]),
|
|
27
|
+
function_security_clause: (print) => print.spaced(["externalKw", "securityKw"]),
|
|
28
|
+
function_cost_clause: (print) => print.spaced(["costKw", "cost"]),
|
|
29
|
+
function_rows_clause: (print) => print.spaced(["rowsKw", "rows"]),
|
|
30
|
+
function_support_clause: (print) => print.spaced(["supportKw", "name"]),
|
|
31
|
+
function_window_clause: (print) => print.spaced("windowKw"),
|
|
32
|
+
function_transform_clause: (print) => print.spaced(["transformKw", "types"]),
|
|
33
|
+
transform_type: (print) => print.spaced(["forTypeKw", "dataType"]),
|
|
34
|
+
dynamically_loaded_function: (print) => join(", ", print(["objectFile", "symbol"])),
|
|
35
|
+
drop_function_stmt: (print) => group([
|
|
36
|
+
print.spaced([
|
|
37
|
+
"dropKw",
|
|
38
|
+
"tableKw",
|
|
39
|
+
"functionKw",
|
|
40
|
+
"ifExistsKw",
|
|
41
|
+
"signatures",
|
|
42
|
+
"behaviorKw",
|
|
43
|
+
]),
|
|
44
|
+
]),
|
|
52
45
|
// almost exact copy of alter_procedure_stmt
|
|
53
|
-
alter_function_stmt:
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
]);
|
|
62
|
-
},
|
|
46
|
+
alter_function_stmt: (print, node) => group([
|
|
47
|
+
print.spaced(["alterKw", "functionKw"]),
|
|
48
|
+
" ",
|
|
49
|
+
print(["signature"]),
|
|
50
|
+
print.dynamicLine(),
|
|
51
|
+
join(print.dynamicLine(), print("actions")),
|
|
52
|
+
node.behaviorKw ? [print.dynamicLine(), print("behaviorKw")] : [],
|
|
53
|
+
]),
|
|
63
54
|
};
|
|
64
|
-
|
|
65
|
-
exports.hasOnlyAsClause = hasOnlyAsClause;
|
|
55
|
+
export const hasOnlyAsClause = (node) => node.clauses.length === 1 && isAsClause(node.clauses[0]);
|