prettier-plugin-sql-cst 0.10.2 → 0.11.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/README.md +7 -6
- package/dist/PrintFn.d.ts +1 -0
- package/dist/embedJs.js +1 -1
- package/dist/embedJson.js +1 -1
- package/dist/index.js +1 -1
- package/dist/node_utils.d.ts +1 -0
- package/dist/node_utils.js +2 -1
- package/dist/options.d.ts +1 -0
- package/dist/options.js +7 -0
- package/dist/printComment.js +1 -1
- package/dist/printSql.js +9 -5
- package/dist/syntax/alter_table.js +39 -11
- package/dist/syntax/base.js +4 -3
- package/dist/syntax/constraint.js +44 -13
- package/dist/syntax/create_table.js +47 -6
- package/dist/syntax/data_type.js +1 -0
- package/dist/syntax/dcl.js +4 -4
- package/dist/syntax/delete.js +1 -1
- package/dist/syntax/dialects/postgresql.js +1 -0
- package/dist/syntax/drop_table.js +2 -2
- package/dist/syntax/explain.js +1 -1
- package/dist/syntax/expr.js +13 -1
- package/dist/syntax/function.js +28 -2
- package/dist/syntax/index.js +3 -3
- package/dist/syntax/insert.js +26 -15
- package/dist/syntax/proc_clause.js +1 -1
- package/dist/syntax/procedural_language.js +2 -2
- package/dist/syntax/procedure.js +4 -2
- package/dist/syntax/select.js +3 -5
- package/dist/syntax/update.js +1 -1
- package/dist/syntax/view.js +16 -2
- package/dist/transform/aliasAs.js +2 -3
- package/dist/transform/canonicKeywords.d.ts +2 -0
- package/dist/transform/canonicKeywords.js +66 -0
- package/dist/transform/canonicOperators.d.ts +3 -0
- package/dist/transform/canonicOperators.js +32 -0
- package/dist/transform/stripTrailingCommas.js +2 -3
- package/dist/transform/transformCst.d.ts +4 -1
- package/dist/transform/transformCst.js +14 -4
- package/dist/transform/transformUtils.d.ts +2 -0
- package/dist/transform/transformUtils.js +7 -0
- package/package.json +6 -4
package/README.md
CHANGED
|
@@ -98,10 +98,11 @@ The plugin provides the following parsers:
|
|
|
98
98
|
The standard Prettier options [printWidth][], [tabWidth][], [useTabs][] apply.
|
|
99
99
|
There are also some SQL-specific options:
|
|
100
100
|
|
|
101
|
-
| API Option
|
|
102
|
-
|
|
|
103
|
-
| `sqlKeywordCase`
|
|
104
|
-
| `sqlParamTypes`
|
|
101
|
+
| API Option | Default | Description |
|
|
102
|
+
| -------------------- | :-----: | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
103
|
+
| `sqlKeywordCase` | `upper` | Converts SQL keywords to `upper` or `lower` case, or `preserve` existing. Note that for now `preserve` is somewhat incompatible with `sqlCanonicalSyntax: true` (e.g. the added `AS` keywords will always be in uppercase). |
|
|
104
|
+
| `sqlParamTypes` | `[]` | Array of bound parameter types: `?`, `?nr`, `:name`, `@name`, `$name`. |
|
|
105
|
+
| `sqlCanonicalSyntax` | `true` | When enabled, performs some opinionated changes of keywords and operators, like enforcing the use of `AS` in aliases and replacing `<>` comparisons with `!=`. See [STYLE_GUIDE][] for more details. (Since 0.11.0) |
|
|
105
106
|
|
|
106
107
|
## FAQ
|
|
107
108
|
|
|
@@ -133,8 +134,8 @@ It also has experimental support for the following dialects:
|
|
|
133
134
|
The main limitation is that [the parser][sql-parser-cst] does not support full syntax of
|
|
134
135
|
these dialects. One should expect the parser to crash for syntax that's more specific to
|
|
135
136
|
these dialects. But as long as the parsing succeeds, the formatting should also succeed.
|
|
136
|
-
Mainly one can expect the formatting of SELECT statements to work.
|
|
137
|
-
keep your expectations low. You have been warned.
|
|
137
|
+
Mainly one can expect the formatting of SELECT, INSERT, UPDATE, DELETE statements to work.
|
|
138
|
+
But beyond that you should keep your expectations low. You have been warned.
|
|
138
139
|
|
|
139
140
|
The specifics of the [SQL formatting style][STYLE_GUIDE] are still very much subject to change.
|
|
140
141
|
Though the general principles should be mostly in place by now.
|
package/dist/PrintFn.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ export type PrintFn<T, K = PrintableKey<T>> = {
|
|
|
10
10
|
spaced(path: K[]): Doc[];
|
|
11
11
|
separated(separator: Doc, path: K): Doc[];
|
|
12
12
|
separated(separator: Doc, path: K[]): Doc[];
|
|
13
|
+
dynamicLine(): Doc;
|
|
13
14
|
};
|
|
14
15
|
export type PrintableKey<T> = Exclude<keyof T, ReservedKey>;
|
|
15
16
|
type ReservedKey = "type" | "range" | "leading" | "trailing";
|
package/dist/embedJs.js
CHANGED
|
@@ -51,7 +51,7 @@ exports.embedJs = void 0;
|
|
|
51
51
|
var node_utils_1 = require("./node_utils");
|
|
52
52
|
var print_utils_1 = require("./print_utils");
|
|
53
53
|
var embedJs = function (path, options) {
|
|
54
|
-
var node = path.
|
|
54
|
+
var node = path.node;
|
|
55
55
|
var parent = path.getParentNode(0);
|
|
56
56
|
var grandParent = path.getParentNode(1);
|
|
57
57
|
if ((0, node_utils_1.isStringLiteral)(node) &&
|
package/dist/embedJson.js
CHANGED
|
@@ -51,7 +51,7 @@ exports.embedJson = void 0;
|
|
|
51
51
|
var node_utils_1 = require("./node_utils");
|
|
52
52
|
var print_utils_1 = require("./print_utils");
|
|
53
53
|
var embedJson = function (path, options) {
|
|
54
|
-
var node = path.
|
|
54
|
+
var node = path.node;
|
|
55
55
|
var parent = path.getParentNode();
|
|
56
56
|
if ((0, node_utils_1.isStringLiteral)(node) &&
|
|
57
57
|
((0, node_utils_1.isJsonLiteral)(parent) || (0, node_utils_1.isJsonbLiteral)(parent))) {
|
package/dist/index.js
CHANGED
|
@@ -44,7 +44,7 @@ var createParser = function (dialect) { return ({
|
|
|
44
44
|
includeComments: true,
|
|
45
45
|
filename: options.filepath,
|
|
46
46
|
paramTypes: options.sqlParamTypes,
|
|
47
|
-
}), text);
|
|
47
|
+
}), text, options);
|
|
48
48
|
},
|
|
49
49
|
astFormat: "sql-cst",
|
|
50
50
|
locStart: function (node) { var _a; return (_a = node.range) === null || _a === void 0 ? void 0 : _a[0]; },
|
package/dist/node_utils.d.ts
CHANGED
|
@@ -15,3 +15,4 @@ export declare const isParenExpr: (node: any) => node is import("sql-parser-cst"
|
|
|
15
15
|
export declare const isListExpr: (node: any) => node is import("sql-parser-cst").ListExpr<Node>;
|
|
16
16
|
export declare const isCreateFunctionStmt: (node: any) => node is import("sql-parser-cst").CreateFunctionStmt;
|
|
17
17
|
export declare const isLanguageClause: (node: any) => node is import("sql-parser-cst").LanguageClause;
|
|
18
|
+
export declare const isDynamicallyLoadedFunction: (node: any) => node is import("sql-parser-cst").DynamicallyLoadedFunction;
|
package/dist/node_utils.js
CHANGED
|
@@ -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.isJsonbLiteral = exports.isJsonLiteral = exports.isEmpty = exports.isKeyword = exports.isCreateTableStmt = exports.isFuncArgs = exports.isFuncCall = exports.isValuesClause = exports.isProgram = void 0;
|
|
3
|
+
exports.isDynamicallyLoadedFunction = 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) {
|
|
@@ -23,3 +23,4 @@ exports.isParenExpr = is("paren_expr");
|
|
|
23
23
|
exports.isListExpr = is("list_expr");
|
|
24
24
|
exports.isCreateFunctionStmt = is("create_function_stmt");
|
|
25
25
|
exports.isLanguageClause = is("language_clause");
|
|
26
|
+
exports.isDynamicallyLoadedFunction = is("dynamically_loaded_function");
|
package/dist/options.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { Node, ParserOptions as CstParserOptions } from "sql-parser-cst";
|
|
|
3
3
|
export interface SqlPluginOptions {
|
|
4
4
|
sqlKeywordCase: "preserve" | "upper" | "lower";
|
|
5
5
|
sqlParamTypes: NonNullable<CstParserOptions["paramTypes"]>;
|
|
6
|
+
sqlCanonicalSyntax: boolean;
|
|
6
7
|
}
|
|
7
8
|
export type AllPrettierOptions<T = Node> = ParserOptions<T> & SqlPluginOptions;
|
|
8
9
|
export declare const options: SupportOptions;
|
package/dist/options.js
CHANGED
|
@@ -34,4 +34,11 @@ exports.options = {
|
|
|
34
34
|
// Since 0.7.0
|
|
35
35
|
// Possible values in array: "?" | "?nr" | ":name" | "$name" | "@name"
|
|
36
36
|
},
|
|
37
|
+
sqlCanonicalSyntax: {
|
|
38
|
+
type: "boolean",
|
|
39
|
+
category: "SQL",
|
|
40
|
+
default: true,
|
|
41
|
+
description: "Enforces one true style of SQL syntax (adds and removes keywords)",
|
|
42
|
+
// Since 0.11.0
|
|
43
|
+
},
|
|
37
44
|
};
|
package/dist/printComment.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.printComment = void 0;
|
|
4
4
|
var printComment = function (path) {
|
|
5
|
-
var node = path.
|
|
5
|
+
var node = path.node;
|
|
6
6
|
if (node.type === "line_comment") {
|
|
7
7
|
if (/^--[^ \t]/.test(node.text)) {
|
|
8
8
|
return node.text.replace(/^--/, "-- ");
|
package/dist/printSql.js
CHANGED
|
@@ -5,12 +5,12 @@ var utils_1 = require("./utils");
|
|
|
5
5
|
var transformMap_1 = require("./syntax/transformMap");
|
|
6
6
|
var print_utils_1 = require("./print_utils");
|
|
7
7
|
function printSql(path, options, oldPrint) {
|
|
8
|
-
return printNode(path, options, createPrintFn(path, oldPrint));
|
|
8
|
+
return printNode(path, options, createPrintFn(path, oldPrint, options));
|
|
9
9
|
}
|
|
10
10
|
exports.printSql = printSql;
|
|
11
11
|
var cachedPrintFn;
|
|
12
12
|
var cachedPath;
|
|
13
|
-
function createPrintFn(path, oldPrint) {
|
|
13
|
+
function createPrintFn(path, oldPrint, opts) {
|
|
14
14
|
// The path parameter will reference the same AstPath instance
|
|
15
15
|
// during the whole printing cycle.
|
|
16
16
|
// So we can keep using the same print function as long as
|
|
@@ -21,7 +21,7 @@ function createPrintFn(path, oldPrint) {
|
|
|
21
21
|
cachedPath = path;
|
|
22
22
|
cachedPrintFn = (function (selector) {
|
|
23
23
|
if ((0, utils_1.isArray)(selector)) {
|
|
24
|
-
var node_1 = path.
|
|
24
|
+
var node_1 = path.node;
|
|
25
25
|
return selector.filter(function (sel) { return (0, utils_1.isDefined)(node_1[sel]); }).map(oldPrint);
|
|
26
26
|
}
|
|
27
27
|
else {
|
|
@@ -29,7 +29,7 @@ function createPrintFn(path, oldPrint) {
|
|
|
29
29
|
}
|
|
30
30
|
});
|
|
31
31
|
cachedPrintFn.separated = function (separator, selector) {
|
|
32
|
-
var node = path.
|
|
32
|
+
var node = path.node;
|
|
33
33
|
var docs = (0, utils_1.arrayWrap)(selector)
|
|
34
34
|
.filter(function (sel) { return (0, utils_1.isDefined)(node[sel]); })
|
|
35
35
|
.map(function (sel) { return [sel, oldPrint(sel)]; })
|
|
@@ -46,10 +46,14 @@ function createPrintFn(path, oldPrint) {
|
|
|
46
46
|
return docs.length > 0 ? [(0, print_utils_1.join)(separator, docs)] : [];
|
|
47
47
|
};
|
|
48
48
|
cachedPrintFn.spaced = function (selector) { return cachedPrintFn.separated(" ", selector); };
|
|
49
|
+
cachedPrintFn.dynamicLine = function () {
|
|
50
|
+
var node = path.node;
|
|
51
|
+
return (0, print_utils_1.containsNewline)(node, opts) ? print_utils_1.hardline : print_utils_1.line;
|
|
52
|
+
};
|
|
49
53
|
return cachedPrintFn;
|
|
50
54
|
}
|
|
51
55
|
function printNode(path, options, print) {
|
|
52
|
-
var node = path.
|
|
56
|
+
var node = path.node;
|
|
53
57
|
if ((0, utils_1.isArray)(node)) {
|
|
54
58
|
return path.map(print);
|
|
55
59
|
}
|
|
@@ -3,11 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.alterTableMap = void 0;
|
|
4
4
|
var print_utils_1 = require("../print_utils");
|
|
5
5
|
exports.alterTableMap = {
|
|
6
|
-
alter_table_stmt: function (print) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
alter_table_stmt: function (print) {
|
|
7
|
+
return (0, print_utils_1.group)([
|
|
8
|
+
print.spaced(["alterTableKw", "ifExistsKw", "table"]),
|
|
9
|
+
print.dynamicLine(),
|
|
10
|
+
print("actions"),
|
|
11
|
+
]);
|
|
12
|
+
},
|
|
11
13
|
alter_action_rename_table: function (print) { return print.spaced(["renameKw", "newName"]); },
|
|
12
14
|
alter_action_rename_column: function (print) {
|
|
13
15
|
return print.spaced(["renameKw", "ifExistsKw", "oldName", "toKw", "newName"]);
|
|
@@ -16,19 +18,45 @@ exports.alterTableMap = {
|
|
|
16
18
|
return print.spaced(["addKw", "ifNotExistsKw", "column"]);
|
|
17
19
|
},
|
|
18
20
|
alter_action_drop_column: function (print) {
|
|
19
|
-
return print.spaced(["dropKw", "ifExistsKw", "column"]);
|
|
21
|
+
return print.spaced(["dropKw", "ifExistsKw", "column", "behaviorKw"]);
|
|
20
22
|
},
|
|
21
23
|
alter_action_set_options: function (print) { return print.spaced(["setKw", "options"]); },
|
|
22
24
|
alter_action_set_default_collate: function (print) {
|
|
23
25
|
return print.spaced(["setDefaultCollateKw", "collation"]);
|
|
24
26
|
},
|
|
25
|
-
|
|
26
|
-
print.spaced(["
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
alter_action_add_constraint: function (print) {
|
|
28
|
+
return print.spaced(["addKw", "constraint"]);
|
|
29
|
+
},
|
|
30
|
+
alter_action_drop_constraint: function (print) {
|
|
31
|
+
return print.spaced([
|
|
32
|
+
"dropConstraintKw",
|
|
33
|
+
"ifExistsKw",
|
|
34
|
+
"constraint",
|
|
35
|
+
"behaviorKw",
|
|
36
|
+
]);
|
|
37
|
+
},
|
|
38
|
+
alter_action_alter_constraint: function (print) {
|
|
39
|
+
return print.spaced(["alterConstraintKw", "constraint", "modifiers"]);
|
|
40
|
+
},
|
|
41
|
+
alter_action_rename_constraint: function (print) {
|
|
42
|
+
return print.spaced(["renameConstraintKw", "oldName", "toKw", "newName"]);
|
|
43
|
+
},
|
|
44
|
+
alter_action_validate_constraint: function (print) {
|
|
45
|
+
return print.spaced(["validateConstraintKw", "constraint"]);
|
|
46
|
+
},
|
|
47
|
+
alter_action_set_visible: function (print) { return print.spaced("setVisibleKw"); },
|
|
48
|
+
alter_action_set_invisible: function (print) { return print.spaced("setInvisibleKw"); },
|
|
49
|
+
// ALTER COLUMN
|
|
50
|
+
alter_action_alter_column: function (print) {
|
|
51
|
+
return (0, print_utils_1.group)([
|
|
52
|
+
print.spaced(["alterKw", "ifExistsKw", "column"]),
|
|
53
|
+
print.dynamicLine(),
|
|
54
|
+
print("action"),
|
|
55
|
+
]);
|
|
56
|
+
},
|
|
30
57
|
alter_action_set_default: function (print) { return print.spaced(["setDefaultKw", "expr"]); },
|
|
31
58
|
alter_action_drop_default: function (print) { return print.spaced("dropDefaultKw"); },
|
|
59
|
+
alter_action_set_not_null: function (print) { return print.spaced("setNotNullKw"); },
|
|
32
60
|
alter_action_drop_not_null: function (print) { return print.spaced("dropNotNullKw"); },
|
|
33
61
|
alter_action_set_data_type: function (print) {
|
|
34
62
|
return print.spaced(["setDataTypeKw", "dataType"]);
|
package/dist/syntax/base.js
CHANGED
|
@@ -2,14 +2,15 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.baseMap = void 0;
|
|
4
4
|
exports.baseMap = {
|
|
5
|
+
/** cst-ignore: name */
|
|
5
6
|
keyword: function (print, node, path, options) {
|
|
6
7
|
switch (options.sqlKeywordCase) {
|
|
7
8
|
case "preserve":
|
|
8
|
-
return path.
|
|
9
|
+
return path.node.text;
|
|
9
10
|
case "upper":
|
|
10
|
-
return path.
|
|
11
|
+
return path.node.text.toUpperCase();
|
|
11
12
|
case "lower":
|
|
12
|
-
return path.
|
|
13
|
+
return path.node.text.toLowerCase();
|
|
13
14
|
}
|
|
14
15
|
},
|
|
15
16
|
all_columns: function () { return "*"; },
|
|
@@ -1,8 +1,18 @@
|
|
|
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.constraintMap = void 0;
|
|
4
13
|
var print_utils_1 = require("../print_utils");
|
|
5
14
|
exports.constraintMap = {
|
|
15
|
+
/** cst-ignore: constraint, modifiers */
|
|
6
16
|
constraint: function (print, node) {
|
|
7
17
|
if (node.name) {
|
|
8
18
|
return (0, print_utils_1.group)([
|
|
@@ -15,26 +25,24 @@ exports.constraintMap = {
|
|
|
15
25
|
}
|
|
16
26
|
},
|
|
17
27
|
constraint_name: function (print) { return print.spaced(["constraintKw", "name"]); },
|
|
18
|
-
|
|
19
|
-
return print.spaced(["deferrableKw", "initiallyKw"]);
|
|
20
|
-
},
|
|
28
|
+
constraint_modifier: function (print) { return print.spaced("kw"); },
|
|
21
29
|
constraint_null: function (print) { return print("nullKw"); },
|
|
22
|
-
constraint_not_null: function (print) {
|
|
23
|
-
return (0, print_utils_1.group)(print.spaced(["notNullKw", "onConflict"]));
|
|
24
|
-
},
|
|
30
|
+
constraint_not_null: function (print) { return (0, print_utils_1.group)(print.spaced(["notNullKw", "clauses"])); },
|
|
25
31
|
constraint_default: function (print) { return (0, print_utils_1.group)(print.spaced(["defaultKw", "expr"])); },
|
|
26
32
|
constraint_primary_key: function (print) {
|
|
27
|
-
return (0, print_utils_1.group)(print.spaced(["primaryKeyKw", "direction", "columns", "
|
|
33
|
+
return (0, print_utils_1.group)(print.spaced(["primaryKeyKw", "direction", "columns", "clauses"]));
|
|
28
34
|
},
|
|
29
35
|
constraint_unique: function (print) {
|
|
30
|
-
return (0, print_utils_1.group)(print.spaced(["uniqueKw", "columns", "
|
|
36
|
+
return (0, print_utils_1.group)(print.spaced(["uniqueKw", "columns", "nullsKw", "clauses"]));
|
|
37
|
+
},
|
|
38
|
+
constraint_check: function (print) {
|
|
39
|
+
return (0, print_utils_1.group)(print.spaced(["checkKw", "expr", "clauses"]));
|
|
31
40
|
},
|
|
32
|
-
constraint_check: function (print) { return (0, print_utils_1.group)(print.spaced(["checkKw", "expr"])); },
|
|
33
41
|
constraint_collate: function (print) {
|
|
34
42
|
return (0, print_utils_1.group)(print.spaced(["collateKw", "collation"]));
|
|
35
43
|
},
|
|
36
44
|
constraint_foreign_key: function (print) {
|
|
37
|
-
return (0, print_utils_1.group)(print.spaced(["foreignKeyKw", "columns", "references"]));
|
|
45
|
+
return (0, print_utils_1.group)(print.spaced(["foreignKeyKw", "indexName", "columns", "references"]));
|
|
38
46
|
},
|
|
39
47
|
references_specification: function (print, node) {
|
|
40
48
|
var baseDoc = print.spaced(["referencesKw", "table", "columns"]);
|
|
@@ -48,11 +56,17 @@ exports.constraintMap = {
|
|
|
48
56
|
return baseDoc;
|
|
49
57
|
}
|
|
50
58
|
},
|
|
51
|
-
|
|
59
|
+
index_specification: function (print) {
|
|
60
|
+
return print.spaced(["expr", "opclass", "direction", "nullHandlingKw"]);
|
|
61
|
+
},
|
|
62
|
+
referential_action: function (print) {
|
|
63
|
+
return print.spaced(["onKw", "eventKw", "actionKw", "columns"]);
|
|
64
|
+
},
|
|
52
65
|
referential_match: function (print) { return print.spaced(["matchKw", "typeKw"]); },
|
|
53
66
|
constraint_generated: function (print) {
|
|
54
67
|
return print.spaced(["generatedKw", "asKw", "expr", "storageKw"]);
|
|
55
68
|
},
|
|
69
|
+
identity_column: function (print) { return print("identityKw"); },
|
|
56
70
|
constraint_auto_increment: function (print) { return print("autoIncrementKw"); },
|
|
57
71
|
on_conflict_clause: function (print) { return print.spaced(["onConflictKw", "resolutionKw"]); },
|
|
58
72
|
constraint_comment: function (print) { return print.spaced(["commentKw", "value"]); },
|
|
@@ -67,12 +81,29 @@ exports.constraintMap = {
|
|
|
67
81
|
constraint_engine_attribute: function (print, node) {
|
|
68
82
|
return (0, print_utils_1.join)(node.hasEq ? " = " : " ", print(["engineAttributeKw", "value"]));
|
|
69
83
|
},
|
|
84
|
+
constraint_compression: function (print) { return print.spaced(["compressionKw", "method"]); },
|
|
85
|
+
constraint_exclude: function (print, node) {
|
|
86
|
+
return (0, print_utils_1.group)([
|
|
87
|
+
print("excludeKw"),
|
|
88
|
+
(0, print_utils_1.indent)([
|
|
89
|
+
print_utils_1.line,
|
|
90
|
+
(0, print_utils_1.join)(print_utils_1.line, __spreadArray([
|
|
91
|
+
print.separated(print_utils_1.line, ["using", "params"])
|
|
92
|
+
], print("clauses"), true)),
|
|
93
|
+
]),
|
|
94
|
+
]);
|
|
95
|
+
},
|
|
96
|
+
exclusion_param: function (print) { return print.spaced(["index", "withKw", "operator"]); },
|
|
97
|
+
index_include_clause: function (print) { return print.spaced(["includeKw", "columns"]); },
|
|
98
|
+
index_tablespace_clause: function (print) {
|
|
99
|
+
return print.spaced(["usingIndexTablespaceKw", "name"]);
|
|
100
|
+
},
|
|
70
101
|
};
|
|
71
102
|
var printUnnamedConstraint = function (print, node) {
|
|
72
|
-
if (node.
|
|
103
|
+
if (node.modifiers.length > 0) {
|
|
73
104
|
return (0, print_utils_1.group)([
|
|
74
105
|
print("constraint"),
|
|
75
|
-
(0, print_utils_1.indent)([print_utils_1.
|
|
106
|
+
(0, print_utils_1.indent)([print_utils_1.line, print.spaced("modifiers")]),
|
|
76
107
|
]);
|
|
77
108
|
}
|
|
78
109
|
else {
|
|
@@ -13,6 +13,7 @@ exports.createTableMap = void 0;
|
|
|
13
13
|
var node_utils_1 = require("../node_utils");
|
|
14
14
|
var print_utils_1 = require("../print_utils");
|
|
15
15
|
exports.createTableMap = {
|
|
16
|
+
/** cst-ignore: clauses */
|
|
16
17
|
create_table_stmt: function (print, node) {
|
|
17
18
|
var rest = [];
|
|
18
19
|
for (var _i = 2; _i < arguments.length; _i++) {
|
|
@@ -22,21 +23,21 @@ exports.createTableMap = {
|
|
|
22
23
|
print.spaced([
|
|
23
24
|
"createKw",
|
|
24
25
|
"orReplaceKw",
|
|
25
|
-
"
|
|
26
|
-
"externalKw",
|
|
27
|
-
"snapshotKw",
|
|
28
|
-
"virtualKw",
|
|
26
|
+
"kind",
|
|
29
27
|
"tableKw",
|
|
30
28
|
"ifNotExistsKw",
|
|
31
29
|
"name",
|
|
30
|
+
"partitionOf",
|
|
31
|
+
"ofType",
|
|
32
32
|
"columns",
|
|
33
33
|
]),
|
|
34
34
|
printClauses.apply(void 0, __spreadArray([print, node], rest, false)),
|
|
35
35
|
node.options ? [print_utils_1.line, (0, print_utils_1.group)(print("options"))] : [],
|
|
36
36
|
];
|
|
37
37
|
},
|
|
38
|
+
table_kind: function (print) { return print.spaced("kindKw"); },
|
|
38
39
|
column_definition: function (print) {
|
|
39
|
-
return print.spaced(["name", "dataType", "constraints"]);
|
|
40
|
+
return print.spaced(["name", "dataType", "withOptionsKw", "constraints"]);
|
|
40
41
|
},
|
|
41
42
|
table_option: function (print, node) {
|
|
42
43
|
if (node.value && node.hasEq) {
|
|
@@ -49,13 +50,53 @@ exports.createTableMap = {
|
|
|
49
50
|
return print.spaced("name");
|
|
50
51
|
}
|
|
51
52
|
},
|
|
52
|
-
create_table_like_clause: function (print) {
|
|
53
|
+
create_table_like_clause: function (print) {
|
|
54
|
+
return print.spaced(["likeKw", "name", "options"]);
|
|
55
|
+
},
|
|
56
|
+
table_like_option: function (print) {
|
|
57
|
+
return print.spaced(["includingOrExcludingKw", "optionKw"]);
|
|
58
|
+
},
|
|
53
59
|
create_table_copy_clause: function (print) { return print.spaced(["copyKw", "name"]); },
|
|
54
60
|
create_table_clone_clause: function (print) { return print.spaced(["cloneKw", "table"]); },
|
|
55
61
|
with_partition_columns_clause: function (print) {
|
|
56
62
|
return print.spaced(["withPartitionColumnsKw", "columns"]);
|
|
57
63
|
},
|
|
58
64
|
create_table_using_clause: function (print) { return print.spaced(["usingKw", "module"]); },
|
|
65
|
+
create_table_inherits_clause: function (print) {
|
|
66
|
+
return print.spaced(["inheritsKw", "tables"]);
|
|
67
|
+
},
|
|
68
|
+
create_table_partition_by_clause: function (print) {
|
|
69
|
+
return print.spaced(["partitionByKw", "strategyKw", "columns"]);
|
|
70
|
+
},
|
|
71
|
+
create_table_partition_of_clause: function (print) {
|
|
72
|
+
return print.spaced(["partitionOfKw", "table"]);
|
|
73
|
+
},
|
|
74
|
+
create_table_partition_bound_clause: function (print) {
|
|
75
|
+
return print.spaced(["forValuesKw", "bound"]);
|
|
76
|
+
},
|
|
77
|
+
partition_bound_in: function (print) { return print.spaced(["inKw", "values"]); },
|
|
78
|
+
partition_bound_from_to: function (print) {
|
|
79
|
+
return print.spaced(["fromKw", "from", "toKw", "to"]);
|
|
80
|
+
},
|
|
81
|
+
partition_bound_minvalue: function (print) { return print.spaced("minvalueKw"); },
|
|
82
|
+
partition_bound_maxvalue: function (print) { return print.spaced("maxvalueKw"); },
|
|
83
|
+
partition_bound_with: function (print) { return print.spaced(["withKw", "values"]); },
|
|
84
|
+
partition_bound_modulus: function (print) { return print.spaced(["modulusKw", "value"]); },
|
|
85
|
+
partition_bound_remainder: function (print) { return print.spaced(["remainderKw", "value"]); },
|
|
86
|
+
create_table_default_partition_clause: function (print) { return print.spaced("defaultKw"); },
|
|
87
|
+
create_table_of_type_clause: function (print) { return print.spaced(["ofKw", "typeName"]); },
|
|
88
|
+
using_access_method_clause: function (print) { return print.spaced(["usingKw", "method"]); },
|
|
89
|
+
create_table_tablespace_clause: function (print) {
|
|
90
|
+
return print.spaced(["tablespaceKw", "name"]);
|
|
91
|
+
},
|
|
92
|
+
with_storage_parameters_clause: function (print) {
|
|
93
|
+
return print.spaced(["withKw", "options"]);
|
|
94
|
+
},
|
|
95
|
+
create_table_without_oids_clause: function (print) { return print.spaced("withoutOidsKw"); },
|
|
96
|
+
create_table_on_commit_clause: function (print) {
|
|
97
|
+
return print.spaced(["onCommitKw", "actionKw"]);
|
|
98
|
+
},
|
|
99
|
+
create_table_with_data_clause: function (print) { return print.spaced("withDataKw"); },
|
|
59
100
|
};
|
|
60
101
|
var printClauses = function (print, node) {
|
|
61
102
|
if (node.clauses.length === 1 && (0, node_utils_1.isAsClause)(node.clauses[0])) {
|
package/dist/syntax/data_type.js
CHANGED
package/dist/syntax/dcl.js
CHANGED
|
@@ -4,17 +4,17 @@ exports.dclMap = void 0;
|
|
|
4
4
|
var print_utils_1 = require("../print_utils");
|
|
5
5
|
exports.dclMap = {
|
|
6
6
|
grant_stmt: function (print) {
|
|
7
|
-
return (0, print_utils_1.
|
|
7
|
+
return (0, print_utils_1.group)((0, print_utils_1.join)(print.dynamicLine(), [
|
|
8
8
|
(0, print_utils_1.group)([print("grantKw"), (0, print_utils_1.indent)([print_utils_1.line, print("roles")])]),
|
|
9
9
|
(0, print_utils_1.group)(print.spaced(["onKw", "resourceType", "resourceName"])),
|
|
10
10
|
(0, print_utils_1.group)([print("toKw"), (0, print_utils_1.indent)([print_utils_1.line, print("users")])]),
|
|
11
|
-
]);
|
|
11
|
+
]));
|
|
12
12
|
},
|
|
13
13
|
revoke_stmt: function (print) {
|
|
14
|
-
return (0, print_utils_1.
|
|
14
|
+
return (0, print_utils_1.group)((0, print_utils_1.join)(print.dynamicLine(), [
|
|
15
15
|
(0, print_utils_1.group)([print("revokeKw"), (0, print_utils_1.indent)([print_utils_1.line, print("roles")])]),
|
|
16
16
|
(0, print_utils_1.group)(print.spaced(["onKw", "resourceType", "resourceName"])),
|
|
17
17
|
(0, print_utils_1.group)([print("fromKw"), (0, print_utils_1.indent)([print_utils_1.line, print("users")])]),
|
|
18
|
-
]);
|
|
18
|
+
]));
|
|
19
19
|
},
|
|
20
20
|
};
|
package/dist/syntax/delete.js
CHANGED
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.deleteMap = void 0;
|
|
4
4
|
var print_utils_1 = require("../print_utils");
|
|
5
5
|
exports.deleteMap = {
|
|
6
|
-
delete_stmt: function (print) { return (0, print_utils_1.
|
|
6
|
+
delete_stmt: function (print) { return (0, print_utils_1.group)((0, print_utils_1.join)(print.dynamicLine(), print("clauses"))); },
|
|
7
7
|
delete_clause: function (print) {
|
|
8
8
|
return print.spaced(["deleteKw", "modifiers", "fromKw", "tables"]);
|
|
9
9
|
},
|
|
@@ -4,4 +4,5 @@ exports.postgresqlMap = void 0;
|
|
|
4
4
|
exports.postgresqlMap = {
|
|
5
5
|
postgresql_operator_expr: function (print) { return print(["operatorKw", "expr"]); },
|
|
6
6
|
postgresql_operator: function (print) { return print("operator"); },
|
|
7
|
+
postgresql_operator_class: function (print) { return print("name"); },
|
|
7
8
|
};
|
package/dist/syntax/explain.js
CHANGED
|
@@ -5,7 +5,7 @@ var print_utils_1 = require("../print_utils");
|
|
|
5
5
|
exports.explainMap = {
|
|
6
6
|
explain_stmt: function (print) {
|
|
7
7
|
return (0, print_utils_1.group)([
|
|
8
|
-
print.spaced(["explainKw", "queryPlanKw"]),
|
|
8
|
+
print.spaced(["explainKw", "analyzeKw", "queryPlanKw"]),
|
|
9
9
|
(0, print_utils_1.indent)([print_utils_1.line, print("statement")]),
|
|
10
10
|
]);
|
|
11
11
|
},
|
package/dist/syntax/expr.js
CHANGED
|
@@ -115,7 +115,12 @@ exports.exprMap = {
|
|
|
115
115
|
over_arg: function (print) { return print.spaced(["overKw", "window"]); },
|
|
116
116
|
having_arg: function (print) { return print.spaced(["havingKw", "minMaxKw", "expr"]); },
|
|
117
117
|
named_arg: function (print) {
|
|
118
|
-
return (0, print_utils_1.group)([
|
|
118
|
+
return (0, print_utils_1.group)([
|
|
119
|
+
print("name"),
|
|
120
|
+
" ",
|
|
121
|
+
print("operator"),
|
|
122
|
+
(0, print_utils_1.indent)([print_utils_1.line, print("value")]),
|
|
123
|
+
]);
|
|
119
124
|
},
|
|
120
125
|
cast_expr: function (print) { return print(["castKw", "args"]); },
|
|
121
126
|
cast_arg: function (print) { return print.spaced(["expr", "asKw", "dataType", "format"]); },
|
|
@@ -145,10 +150,15 @@ exports.exprMap = {
|
|
|
145
150
|
return print.spaced(["matchKw", "columns", "againstKw", "args"]);
|
|
146
151
|
},
|
|
147
152
|
full_text_match_args: function (print) { return print.spaced(["expr", "modifier"]); },
|
|
153
|
+
/** cst-ignore: value */
|
|
148
154
|
number_literal: function (print) { return print("text"); },
|
|
155
|
+
/** cst-ignore: value */
|
|
149
156
|
boolean_literal: function (print) { return print("valueKw"); },
|
|
157
|
+
/** cst-ignore: value */
|
|
150
158
|
string_literal: function (print) { return print("text"); },
|
|
159
|
+
/** cst-ignore: value */
|
|
151
160
|
blob_literal: function (print) { return print("text"); },
|
|
161
|
+
/** cst-ignore: value */
|
|
152
162
|
null_literal: function (print) { return print("nullKw"); },
|
|
153
163
|
numeric_literal: function (print) { return print.spaced(["numericKw", "string"]); },
|
|
154
164
|
bignumeric_literal: function (print) { return print.spaced(["bignumericKw", "string"]); },
|
|
@@ -158,7 +168,9 @@ exports.exprMap = {
|
|
|
158
168
|
timestamp_literal: function (print) { return print.spaced(["timestampKw", "string"]); },
|
|
159
169
|
json_literal: function (print) { return print.spaced(["jsonKw", "string"]); },
|
|
160
170
|
jsonb_literal: function (print) { return print.spaced(["jsonbKw", "string"]); },
|
|
171
|
+
/** cst-ignore: name */
|
|
161
172
|
identifier: function (print) { return print("text"); },
|
|
173
|
+
/** cst-ignore: name */
|
|
162
174
|
variable: function (print) { return print("text"); },
|
|
163
175
|
parameter: function (print) { return print("text"); },
|
|
164
176
|
};
|
package/dist/syntax/function.js
CHANGED
|
@@ -22,9 +22,35 @@ exports.functionMap = {
|
|
|
22
22
|
(0, print_utils_1.join)(print_utils_1.hardline, print("clauses").map(function (cls) { return (0, print_utils_1.group)(cls); })),
|
|
23
23
|
],
|
|
24
24
|
]; },
|
|
25
|
-
function_param: function (print) {
|
|
25
|
+
function_param: function (print) {
|
|
26
|
+
return print.spaced(["mode", "name", "dataType", "default"]);
|
|
27
|
+
},
|
|
28
|
+
function_param_default: function (print) { return print.spaced(["operator", "expr"]); },
|
|
29
|
+
return_clause: function (print) { return print.spaced(["returnKw", "expr"]); },
|
|
30
|
+
function_behavior_clause: function (print) { return print.spaced(["behaviorKw"]); },
|
|
31
|
+
function_security_clause: function (print) {
|
|
32
|
+
return print.spaced(["externalKw", "securityKw"]);
|
|
33
|
+
},
|
|
34
|
+
function_cost_clause: function (print) { return print.spaced(["costKw", "cost"]); },
|
|
35
|
+
function_rows_clause: function (print) { return print.spaced(["rowsKw", "rows"]); },
|
|
36
|
+
function_support_clause: function (print) { return print.spaced(["supportKw", "name"]); },
|
|
37
|
+
function_window_clause: function (print) { return print.spaced("windowKw"); },
|
|
38
|
+
function_transform_clause: function (print) { return print.spaced(["transformKw", "types"]); },
|
|
39
|
+
transform_type: function (print) { return print.spaced(["forTypeKw", "dataType"]); },
|
|
40
|
+
set_parameter_clause: function (print) {
|
|
41
|
+
return print.spaced(["setKw", "name", "operator", "value"]);
|
|
42
|
+
},
|
|
43
|
+
set_parameter_from_current_clause: function (print) {
|
|
44
|
+
return print.spaced(["setKw", "name", "fromCurrentKw"]);
|
|
45
|
+
},
|
|
46
|
+
dynamically_loaded_function: function (print) {
|
|
47
|
+
return (0, print_utils_1.join)(", ", print(["objectFile", "symbol"]));
|
|
48
|
+
},
|
|
26
49
|
drop_function_stmt: function (print) {
|
|
27
|
-
return
|
|
50
|
+
return (0, print_utils_1.group)([
|
|
51
|
+
print.spaced(["dropKw", "tableKw", "functionKw", "ifExistsKw", "name"]),
|
|
52
|
+
print.spaced(["params", "behaviorKw"]),
|
|
53
|
+
]);
|
|
28
54
|
},
|
|
29
55
|
};
|
|
30
56
|
var hasOnlyAsClause = function (node) {
|
package/dist/syntax/index.js
CHANGED
|
@@ -12,8 +12,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.indexMap = void 0;
|
|
13
13
|
var print_utils_1 = require("../print_utils");
|
|
14
14
|
exports.indexMap = {
|
|
15
|
-
create_index_stmt: function (print
|
|
16
|
-
return (0, print_utils_1.
|
|
15
|
+
create_index_stmt: function (print) {
|
|
16
|
+
return (0, print_utils_1.group)((0, print_utils_1.join)(print.dynamicLine(), __spreadArray([
|
|
17
17
|
print.spaced([
|
|
18
18
|
"createKw",
|
|
19
19
|
"indexTypeKw",
|
|
@@ -24,7 +24,7 @@ exports.indexMap = {
|
|
|
24
24
|
"table",
|
|
25
25
|
"columns",
|
|
26
26
|
])
|
|
27
|
-
],
|
|
27
|
+
], print("clauses"), true)));
|
|
28
28
|
},
|
|
29
29
|
drop_index_stmt: function (print) {
|
|
30
30
|
return print.spaced([
|
package/dist/syntax/insert.js
CHANGED
|
@@ -3,15 +3,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.insertMap = void 0;
|
|
4
4
|
var print_utils_1 = require("../print_utils");
|
|
5
5
|
exports.insertMap = {
|
|
6
|
-
insert_stmt: function (print) { return (0, print_utils_1.
|
|
6
|
+
insert_stmt: function (print) { return (0, print_utils_1.group)((0, print_utils_1.join)(print.dynamicLine(), print("clauses"))); },
|
|
7
7
|
insert_clause: function (print, node) {
|
|
8
8
|
return (0, print_utils_1.group)([
|
|
9
9
|
print.spaced(["insertKw", "modifiers", "orAction", "intoKw", "table"]),
|
|
10
|
-
node.columns ? (0, print_utils_1.indent)([
|
|
10
|
+
node.columns ? (0, print_utils_1.indent)([print.dynamicLine(), print("columns")]) : [],
|
|
11
11
|
]);
|
|
12
12
|
},
|
|
13
13
|
values_clause: function (print) {
|
|
14
|
-
return (0, print_utils_1.group)([print("valuesKw"), (0, print_utils_1.indent)([
|
|
14
|
+
return (0, print_utils_1.group)([print("valuesKw"), (0, print_utils_1.indent)([print.dynamicLine(), print("values")])]);
|
|
15
15
|
},
|
|
16
16
|
or_alternate_action: function (print) { return print.spaced(["orKw", "actionKw"]); },
|
|
17
17
|
default: function (print) { return print("defaultKw"); },
|
|
@@ -23,17 +23,28 @@ exports.insertMap = {
|
|
|
23
23
|
return print.spaced(["onConstraintKw", "constraint"]);
|
|
24
24
|
},
|
|
25
25
|
upsert_action_nothing: function (print) { return print("nothingKw"); },
|
|
26
|
-
upsert_action_update: function (print) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
(0, print_utils_1.
|
|
37
|
-
|
|
26
|
+
upsert_action_update: function (print) {
|
|
27
|
+
return (0, print_utils_1.group)([
|
|
28
|
+
print("updateKw"),
|
|
29
|
+
(0, print_utils_1.indent)([
|
|
30
|
+
print.dynamicLine(),
|
|
31
|
+
(0, print_utils_1.join)(print.dynamicLine(), print(["set", "where"])),
|
|
32
|
+
]),
|
|
33
|
+
]);
|
|
34
|
+
},
|
|
35
|
+
row_alias_clause: function (print, node) {
|
|
36
|
+
return (0, print_utils_1.group)([
|
|
37
|
+
print.spaced(["asKw", "rowAlias"]),
|
|
38
|
+
node.columnAliases
|
|
39
|
+
? (0, print_utils_1.indent)([print.dynamicLine(), print("columnAliases")])
|
|
40
|
+
: [],
|
|
41
|
+
]);
|
|
42
|
+
},
|
|
43
|
+
on_duplicate_key_update_clause: function (print) {
|
|
44
|
+
return (0, print_utils_1.group)([
|
|
45
|
+
print.spaced("onDuplicateKeyUpdateKw"),
|
|
46
|
+
(0, print_utils_1.indent)([print.dynamicLine(), print("assignments")]),
|
|
47
|
+
]);
|
|
48
|
+
},
|
|
38
49
|
overriding_clause: function (print) { return print.spaced("overridingKw"); },
|
|
39
50
|
};
|
|
@@ -8,7 +8,7 @@ exports.procClauseMap = {
|
|
|
8
8
|
determinism_clause: function (print) { return print.spaced("deterministicKw"); },
|
|
9
9
|
language_clause: function (print) { return print.spaced(["languageKw", "name"]); },
|
|
10
10
|
as_clause: function (print, node) {
|
|
11
|
-
if ((0, node_utils_1.isStringLiteral)(node.expr)) {
|
|
11
|
+
if ((0, node_utils_1.isStringLiteral)(node.expr) || (0, node_utils_1.isDynamicallyLoadedFunction)(node.expr)) {
|
|
12
12
|
return print.spaced(["asKw", "expr"]);
|
|
13
13
|
}
|
|
14
14
|
return [print("asKw"), (0, print_utils_1.indent)([print_utils_1.hardline, print("expr")])];
|
|
@@ -14,7 +14,7 @@ var print_utils_1 = require("../print_utils");
|
|
|
14
14
|
exports.proceduralLanguageMap = {
|
|
15
15
|
// BEGIN .. END
|
|
16
16
|
block_stmt: function (print, node) { return [
|
|
17
|
-
print("beginKw"),
|
|
17
|
+
print.spaced(["beginKw", "atomicKw"]),
|
|
18
18
|
(0, print_utils_1.indent)([print_utils_1.hardline, (0, print_utils_1.stripTrailingHardline)(print("program"))]),
|
|
19
19
|
node.exception ? [print_utils_1.hardline, print("exception")] : [],
|
|
20
20
|
print_utils_1.hardline,
|
|
@@ -108,7 +108,7 @@ exports.proceduralLanguageMap = {
|
|
|
108
108
|
// CALL
|
|
109
109
|
call_stmt: function (print) { return print.spaced(["callKw", "func"]); },
|
|
110
110
|
// RETURN
|
|
111
|
-
return_stmt: function (print) { return print("returnKw"); },
|
|
111
|
+
return_stmt: function (print) { return print.spaced(["returnKw", "expr"]); },
|
|
112
112
|
// RAISE
|
|
113
113
|
raise_stmt: function (print) { return print.spaced(["raiseKw", "message"]); },
|
|
114
114
|
raise_message: function (print) { return [
|
package/dist/syntax/procedure.js
CHANGED
|
@@ -15,8 +15,10 @@ exports.procedureMap = {
|
|
|
15
15
|
print_utils_1.hardline,
|
|
16
16
|
(0, print_utils_1.join)(print_utils_1.hardline, print("clauses").map(function (clause) { return (0, print_utils_1.group)(clause); })),
|
|
17
17
|
]; },
|
|
18
|
-
procedure_param: function (print) { return print.spaced(["mode", "name", "dataType"]); },
|
|
19
18
|
drop_procedure_stmt: function (print) {
|
|
20
|
-
return
|
|
19
|
+
return (0, print_utils_1.group)([
|
|
20
|
+
print.spaced(["dropKw", "procedureKw", "ifExistsKw", "name"]),
|
|
21
|
+
print.spaced(["params", "behaviorKw"]),
|
|
22
|
+
]);
|
|
21
23
|
},
|
|
22
24
|
};
|
package/dist/syntax/select.js
CHANGED
|
@@ -7,10 +7,7 @@ exports.selectMap = {
|
|
|
7
7
|
compound_select_stmt: function (print) {
|
|
8
8
|
return (0, print_utils_1.join)(print_utils_1.hardline, [print("left"), print.spaced("operator"), print("right")]);
|
|
9
9
|
},
|
|
10
|
-
select_stmt: function (print,
|
|
11
|
-
var lineType = (0, print_utils_1.containsNewline)(node, opts) ? print_utils_1.hardline : print_utils_1.line;
|
|
12
|
-
return (0, print_utils_1.group)((0, print_utils_1.join)(lineType, print("clauses")));
|
|
13
|
-
},
|
|
10
|
+
select_stmt: function (print) { return (0, print_utils_1.group)((0, print_utils_1.join)(print.dynamicLine(), print("clauses"))); },
|
|
14
11
|
// WITH clause
|
|
15
12
|
with_clause: function (print) {
|
|
16
13
|
return (0, print_utils_1.group)([
|
|
@@ -191,6 +188,7 @@ exports.selectMap = {
|
|
|
191
188
|
return (0, print_utils_1.group)([print("qualifyKw"), (0, print_utils_1.indent)([print_utils_1.line, print("expr")])]);
|
|
192
189
|
},
|
|
193
190
|
// LIMIT clause
|
|
191
|
+
/** cst-ignore: count, offsetKw, offset */
|
|
194
192
|
limit_clause: function (print, node) {
|
|
195
193
|
return (0, print_utils_1.group)([
|
|
196
194
|
print("limitKw"),
|
|
@@ -235,7 +233,7 @@ exports.selectMap = {
|
|
|
235
233
|
},
|
|
236
234
|
// INTO clause
|
|
237
235
|
into_table_clause: function (print) {
|
|
238
|
-
return print.spaced(["intoKw", "
|
|
236
|
+
return print.spaced(["intoKw", "kind", "tableKw", "name"]);
|
|
239
237
|
},
|
|
240
238
|
into_variables_clause: function (print) {
|
|
241
239
|
return (0, print_utils_1.group)([print("intoKw"), (0, print_utils_1.indent)([print_utils_1.line, print("variables")])]);
|
package/dist/syntax/update.js
CHANGED
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.updateMap = void 0;
|
|
4
4
|
var print_utils_1 = require("../print_utils");
|
|
5
5
|
exports.updateMap = {
|
|
6
|
-
update_stmt: function (print) { return (0, print_utils_1.
|
|
6
|
+
update_stmt: function (print) { return (0, print_utils_1.group)((0, print_utils_1.join)(print.dynamicLine(), print("clauses"))); },
|
|
7
7
|
update_clause: function (print) {
|
|
8
8
|
return print.spaced(["updateKw", "modifiers", "orAction", "tables"]);
|
|
9
9
|
},
|
package/dist/syntax/view.js
CHANGED
|
@@ -22,10 +22,24 @@ exports.viewMap = {
|
|
|
22
22
|
];
|
|
23
23
|
},
|
|
24
24
|
drop_view_stmt: function (print) {
|
|
25
|
-
return print.spaced([
|
|
25
|
+
return print.spaced([
|
|
26
|
+
"dropKw",
|
|
27
|
+
"materializedKw",
|
|
28
|
+
"viewKw",
|
|
29
|
+
"ifExistsKw",
|
|
30
|
+
"views",
|
|
31
|
+
"behaviorKw",
|
|
32
|
+
]);
|
|
26
33
|
},
|
|
27
34
|
alter_view_stmt: function (print) { return [
|
|
28
|
-
print.spaced([
|
|
35
|
+
print.spaced([
|
|
36
|
+
"alterKw",
|
|
37
|
+
"materializedKw",
|
|
38
|
+
"viewKw",
|
|
39
|
+
"ifExistsKw",
|
|
40
|
+
"name",
|
|
41
|
+
"columns",
|
|
42
|
+
]),
|
|
29
43
|
print_utils_1.hardline,
|
|
30
44
|
(0, print_utils_1.join)(print_utils_1.hardline, print("actions")),
|
|
31
45
|
]; },
|
|
@@ -4,12 +4,11 @@ exports.processAliasAs = void 0;
|
|
|
4
4
|
var sql_parser_cst_1 = require("sql-parser-cst");
|
|
5
5
|
// Adds AS keyword to aliases if none exists
|
|
6
6
|
var processAliasAs = function (cst) {
|
|
7
|
-
|
|
7
|
+
(0, sql_parser_cst_1.cstVisitor)({
|
|
8
8
|
alias: function (node) {
|
|
9
9
|
node.asKw = node.asKw || { type: "keyword", name: "AS", text: "AS" };
|
|
10
10
|
},
|
|
11
|
-
});
|
|
12
|
-
mutateAliases(cst);
|
|
11
|
+
})(cst);
|
|
13
12
|
return cst;
|
|
14
13
|
};
|
|
15
14
|
exports.processAliasAs = processAliasAs;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.canonicKeywords = void 0;
|
|
4
|
+
var sql_parser_cst_1 = require("sql-parser-cst");
|
|
5
|
+
var transformUtils_1 = require("./transformUtils");
|
|
6
|
+
var canonicKeywords = function (cst) {
|
|
7
|
+
(0, sql_parser_cst_1.cstVisitor)({
|
|
8
|
+
// Replaces TEMP with TEMPORARY
|
|
9
|
+
table_kind: function (node) {
|
|
10
|
+
if (Array.isArray(node.kindKw)) {
|
|
11
|
+
// TODO...
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
if (node.kindKw.name === "TEMP") {
|
|
15
|
+
node.kindKw.name = "TEMPORARY";
|
|
16
|
+
node.kindKw.text = "TEMPORARY";
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
// Replaces MySQL SELECT DISTINCTROW with SELECT DISTINCT
|
|
21
|
+
select_distinct: function (node) {
|
|
22
|
+
if (node.distinctKw.name === "DISTINCTROW") {
|
|
23
|
+
node.distinctKw.name = "DISTINCT";
|
|
24
|
+
node.distinctKw.text = "DISTINCT";
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
// Replaces RENAME & RENAME AS with RENAME TO
|
|
28
|
+
alter_action_rename_table: function (node) {
|
|
29
|
+
if (Array.isArray(node.renameKw)) {
|
|
30
|
+
if (node.renameKw[1].name === "AS") {
|
|
31
|
+
node.renameKw[1].name = "TO";
|
|
32
|
+
node.renameKw[1].text = "TO";
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
node.renameKw = [node.renameKw, (0, transformUtils_1.keyword)("TO")];
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
// Replaces INSERT with INSERT INTO
|
|
40
|
+
insert_clause: function (node) {
|
|
41
|
+
if (!node.intoKw) {
|
|
42
|
+
node.intoKw = (0, transformUtils_1.keyword)("INTO");
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
// Replaces MERGE with MERGE INTO
|
|
46
|
+
merge_clause: function (node) {
|
|
47
|
+
if (!node.intoKw) {
|
|
48
|
+
node.intoKw = (0, transformUtils_1.keyword)("INTO");
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
// Replaces DELETE with DELETE FROM
|
|
52
|
+
delete_clause: function (node) {
|
|
53
|
+
if (!node.fromKw) {
|
|
54
|
+
node.fromKw = (0, transformUtils_1.keyword)("FROM");
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
// Replaces TRUNCATE with TRUNCATE TABLE
|
|
58
|
+
truncate_stmt: function (node) {
|
|
59
|
+
if (!node.tableKw) {
|
|
60
|
+
node.tableKw = (0, transformUtils_1.keyword)("TABLE");
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
})(cst);
|
|
64
|
+
return cst;
|
|
65
|
+
};
|
|
66
|
+
exports.canonicKeywords = canonicKeywords;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.canonicOperators = void 0;
|
|
4
|
+
var sql_parser_cst_1 = require("sql-parser-cst");
|
|
5
|
+
var transformUtils_1 = require("./transformUtils");
|
|
6
|
+
var canonicOperators = function (cst, originalText, options) {
|
|
7
|
+
(0, sql_parser_cst_1.cstVisitor)({
|
|
8
|
+
binary_expr: function (node) {
|
|
9
|
+
// Replaces <> operator with !=
|
|
10
|
+
if (node.operator === "<>") {
|
|
11
|
+
node.operator = "!=";
|
|
12
|
+
}
|
|
13
|
+
// Replace MySQL && and || operators with AND and OR
|
|
14
|
+
if (options.parser === "mysql" || options.parser === "mariadb") {
|
|
15
|
+
if (node.operator === "&&") {
|
|
16
|
+
node.operator = (0, transformUtils_1.keyword)("AND");
|
|
17
|
+
}
|
|
18
|
+
if (node.operator === "||") {
|
|
19
|
+
node.operator = (0, transformUtils_1.keyword)("OR");
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
// Replaces PostgreSQL deprecated := operator with =>
|
|
24
|
+
named_arg: function (node) {
|
|
25
|
+
if (node.operator === ":=") {
|
|
26
|
+
node.operator = "=>";
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
})(cst);
|
|
30
|
+
return cst;
|
|
31
|
+
};
|
|
32
|
+
exports.canonicOperators = canonicOperators;
|
|
@@ -7,14 +7,13 @@ var utils_1 = require("../utils");
|
|
|
7
7
|
// Removes trailing comma from SELECT clauses
|
|
8
8
|
var stripTrailingCommas = function (cst) {
|
|
9
9
|
// Trailing comma is represented as an empty element at the end of column list
|
|
10
|
-
|
|
10
|
+
(0, sql_parser_cst_1.cstVisitor)({
|
|
11
11
|
select_clause: function (node) {
|
|
12
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
|
},
|
|
16
|
-
});
|
|
17
|
-
removeLastEmptyColumn(cst);
|
|
16
|
+
})(cst);
|
|
18
17
|
return cst;
|
|
19
18
|
};
|
|
20
19
|
exports.stripTrailingCommas = stripTrailingCommas;
|
|
@@ -1,2 +1,5 @@
|
|
|
1
1
|
import { Program } from "sql-parser-cst";
|
|
2
|
-
|
|
2
|
+
import { AllPrettierOptions } from "src/options";
|
|
3
|
+
export declare const transformCst: TransformFn;
|
|
4
|
+
type TransformFn = (cst: Program, originalText: string, options: AllPrettierOptions) => Program;
|
|
5
|
+
export {};
|
|
@@ -5,9 +5,19 @@ var comments_1 = require("./comments");
|
|
|
5
5
|
var aliasAs_1 = require("./aliasAs");
|
|
6
6
|
var stripTrailingCommas_1 = require("./stripTrailingCommas");
|
|
7
7
|
var addFinalSemicolon_1 = require("./addFinalSemicolon");
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
var transformCst = function (cst, originalText) {
|
|
11
|
-
|
|
8
|
+
var canonicKeywords_1 = require("./canonicKeywords");
|
|
9
|
+
var canonicOperators_1 = require("./canonicOperators");
|
|
10
|
+
var transformCst = function (cst, originalText, options) {
|
|
11
|
+
var transforms = [
|
|
12
|
+
// Note that we first perform moveCommentsToRoot transform,
|
|
13
|
+
// so we don't need to worry about comments interfering with other transforms
|
|
14
|
+
comments_1.moveCommentsToRoot,
|
|
15
|
+
stripTrailingCommas_1.stripTrailingCommas,
|
|
16
|
+
addFinalSemicolon_1.addFinalSemicolon,
|
|
17
|
+
];
|
|
18
|
+
if (options.sqlCanonicalSyntax) {
|
|
19
|
+
transforms.push(aliasAs_1.processAliasAs, canonicOperators_1.canonicOperators, canonicKeywords_1.canonicKeywords);
|
|
20
|
+
}
|
|
21
|
+
return transforms.reduce(function (cst, transform) { return transform(cst, originalText, options); }, cst);
|
|
12
22
|
};
|
|
13
23
|
exports.transformCst = transformCst;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "prettier-plugin-sql-cst",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.1",
|
|
4
4
|
"description": "Prettier plugin for SQL",
|
|
5
5
|
"author": "Rene Saarsoo <nene@triin.net>",
|
|
6
6
|
"license": "GPL-3.0-or-later",
|
|
@@ -18,12 +18,13 @@
|
|
|
18
18
|
"dist/"
|
|
19
19
|
],
|
|
20
20
|
"scripts": {
|
|
21
|
-
"prepublishOnly": "yarn test && yarn build",
|
|
21
|
+
"prepublishOnly": "yarn analyze-field-access && yarn test && yarn build",
|
|
22
22
|
"clean": "rm -rf dist",
|
|
23
23
|
"build": "yarn clean && tsc",
|
|
24
24
|
"test": "yarn node --experimental-vm-modules $(yarn bin jest)",
|
|
25
25
|
"pretty": "prettier -w src/ test/",
|
|
26
|
-
"ts:check": "tsc --noEmit"
|
|
26
|
+
"ts:check": "tsc --noEmit",
|
|
27
|
+
"analyze-field-access": "ts-node scripts/analyze-field-access.ts src/index.ts"
|
|
27
28
|
},
|
|
28
29
|
"keywords": [
|
|
29
30
|
"prettier",
|
|
@@ -32,13 +33,14 @@
|
|
|
32
33
|
],
|
|
33
34
|
"dependencies": {
|
|
34
35
|
"prettier": "^3.0.3",
|
|
35
|
-
"sql-parser-cst": "^0.
|
|
36
|
+
"sql-parser-cst": "^0.24.0"
|
|
36
37
|
},
|
|
37
38
|
"devDependencies": {
|
|
38
39
|
"@types/jest": "^29.2.5",
|
|
39
40
|
"dedent-js": "^1.0.1",
|
|
40
41
|
"jest": "^29.7.0",
|
|
41
42
|
"ts-jest": "^29.1.1",
|
|
43
|
+
"ts-node": "^10.9.2",
|
|
42
44
|
"typescript": "^4.9.4"
|
|
43
45
|
}
|
|
44
46
|
}
|