prettier-plugin-sql-cst 0.15.0 → 0.17.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 +94 -10
- package/dist/node_utils.d.ts +15 -0
- package/dist/node_utils.js +22 -1
- package/dist/options.d.ts +3 -0
- package/dist/options.js +72 -3
- package/dist/syntax/alter_action.js +7 -2
- package/dist/syntax/analyze.js +4 -1
- package/dist/syntax/base.js +5 -7
- package/dist/syntax/constraint.d.ts +4 -1
- package/dist/syntax/constraint.js +4 -3
- package/dist/syntax/create_table.js +2 -2
- package/dist/syntax/data_type.js +25 -7
- package/dist/syntax/dialects/bigquery.js +42 -36
- package/dist/syntax/dialects/sqlite.js +4 -4
- package/dist/syntax/do.js +2 -1
- package/dist/syntax/drop_table.js +3 -2
- package/dist/syntax/expr.d.ts +1 -1
- package/dist/syntax/expr.js +72 -3
- package/dist/syntax/function.d.ts +2 -1
- package/dist/syntax/function.js +23 -22
- package/dist/syntax/index.js +2 -2
- package/dist/syntax/merge.js +1 -1
- package/dist/syntax/parameter.js +5 -4
- package/dist/syntax/prepared_statements.js +3 -3
- package/dist/syntax/procedural_language.js +72 -56
- package/dist/syntax/procedure.js +19 -12
- package/dist/syntax/schema.js +1 -1
- package/dist/syntax/select.js +1 -1
- package/dist/syntax/transaction.js +4 -4
- package/dist/syntax/trigger.js +4 -4
- package/dist/syntax/unsupported_grammar.js +2 -1
- package/dist/syntax/view.js +16 -14
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -125,16 +125,100 @@ The plugin provides the following parsers:
|
|
|
125
125
|
## Configuration
|
|
126
126
|
|
|
127
127
|
The standard Prettier options [printWidth][], [tabWidth][], [useTabs][] apply.
|
|
128
|
-
There are also
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
128
|
+
There are also several SQL-specific options:
|
|
129
|
+
|
|
130
|
+
- **`sqlKeywordCase`**: `"upper" | "lower" | "preserve"` (default `"upper"`)
|
|
131
|
+
|
|
132
|
+
Enforce case of keywords.
|
|
133
|
+
|
|
134
|
+
This effects all keywords except literals (see `sqlLiteralCase`) and data types (see `sqlTypeCase`).
|
|
135
|
+
|
|
136
|
+
For now `preserve` is somewhat incompatible with `sqlCanonicalSyntax: true` (e.g. the added `AS` keywords will always be in uppercase).
|
|
137
|
+
|
|
138
|
+
- **`sqlLiteralCase`**: `"upper" | "lower" | "preserve"` (default `"upper"`)
|
|
139
|
+
|
|
140
|
+
Enforce case of literals TRUE, FALSE and NULL.
|
|
141
|
+
|
|
142
|
+
Also applies to ON & OFF literals in PostgreSQL SET statements.
|
|
143
|
+
|
|
144
|
+
_Since 0.14.0_
|
|
145
|
+
|
|
146
|
+
- **`sqlTypeCase`**: `"upper" | "lower" | "preserve"` (default `"upper"`)
|
|
147
|
+
|
|
148
|
+
Enforce case of type names.
|
|
149
|
+
|
|
150
|
+
In PostgreSQL this will only effect a limited set of builtin data types, the rest will be formatted as identifiers.
|
|
151
|
+
It will effect casing of all the keywords in types like `TIMESTAMP WITH TIME ZONE` and `INTERVAL DAY TO SECOND`,
|
|
152
|
+
but it won't effect the casing of `SETOF` and `TABLE` keywords in `SETOF type` and `TABLE (x int, y int)`.
|
|
153
|
+
For PostgreSQL the recommended setting of this option is `lower`.
|
|
154
|
+
|
|
155
|
+
In BigQuery this also effects the names parametric types,
|
|
156
|
+
for example `array<struct<x int64>>` will get formatted as `ARRAY<STRUCT<x INT64>>`.
|
|
157
|
+
|
|
158
|
+
_Since 0.17.0_
|
|
159
|
+
|
|
160
|
+
- **`sqlIdentifierCase`**: `"upper" | "lower" | "preserve"` (default `"preserve"`)
|
|
161
|
+
|
|
162
|
+
Enforce case of unquoted identifier names.
|
|
163
|
+
|
|
164
|
+
This effects all identifiers except function names (see `sqlFunctionCase`).
|
|
165
|
+
|
|
166
|
+
Beware that in BigQuery unquoted identifiers are case-sensitive, so use of this option with BigQuery is not recommended.
|
|
167
|
+
|
|
168
|
+
**Experimental:** This option is still new and not thoroughly tested. You have been warned.
|
|
169
|
+
|
|
170
|
+
_Since 0.17.0_
|
|
171
|
+
|
|
172
|
+
- **`sqlFunctionCase`**: `"upper" | "lower" | "preserve"` (default `"preserve"`)
|
|
173
|
+
|
|
174
|
+
Enforce case of unquoted function names.
|
|
175
|
+
|
|
176
|
+
This option also applies to schema-qualified function names,
|
|
177
|
+
for example `my_schema.foo()` will get formatted as `my_schema.FOO()`
|
|
178
|
+
when `sqlFunctionCase: "upper"` is configured.
|
|
179
|
+
|
|
180
|
+
**Experimental:** This option is still new and not thoroughly tested. You have been warned.
|
|
181
|
+
|
|
182
|
+
_Since 0.17.0_
|
|
183
|
+
|
|
184
|
+
- **`sqlParamTypes`**: `("?", "?nr", "$nr", ":name", "$name", "@name" "@``@name``")[]` (default `[]`)
|
|
185
|
+
|
|
186
|
+
Array of bound parameter types to support.
|
|
187
|
+
|
|
188
|
+
By default the parser will reject the following SQL:
|
|
189
|
+
|
|
190
|
+
```sql
|
|
191
|
+
SELECT id, name FROM products WHERE price > ? AND category = ?
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
Configuring `sqlParamTypes: ["?"]` will make the parser recognize the `?` placeholders.
|
|
195
|
+
|
|
196
|
+
_Since 0.7.0_
|
|
197
|
+
|
|
198
|
+
- **`sqlCanonicalSyntax`**: `boolean` (default `true`)
|
|
199
|
+
|
|
200
|
+
When enabled, performs some opinionated changes of keywords and operators,
|
|
201
|
+
like enforcing the use of `AS` in aliases and replacing `<>` comparisons with `!=`.
|
|
202
|
+
See [STYLE_GUIDE][] for more details.
|
|
203
|
+
|
|
204
|
+
_Since 0.11.0_
|
|
205
|
+
|
|
206
|
+
- **`sqlFinalSemicolon`**: `boolean` (default `true`)
|
|
207
|
+
|
|
208
|
+
When enabled, enforces a semicolon at the end of last statement.
|
|
209
|
+
When disabled leaves it up to the author whether to add a final semicolon or not.
|
|
210
|
+
|
|
211
|
+
_Since 0.13.0_
|
|
212
|
+
|
|
213
|
+
- **`sqlAcceptUnsupportedGrammar`**: `boolean` (default `false`)
|
|
214
|
+
|
|
215
|
+
Normally when the plugin encounters SQL syntax it doesn't support
|
|
216
|
+
it will throw an error and won't format anything at all.
|
|
217
|
+
With this option enabled, it will skip over SQL statements it doesn't recognize, leaving them as-is.
|
|
218
|
+
|
|
219
|
+
**Deprecated:** This doesn't really work as advertised and will likely be removed.
|
|
220
|
+
|
|
221
|
+
_Since 0.12.0_
|
|
138
222
|
|
|
139
223
|
## Usage inside VSCode
|
|
140
224
|
|
package/dist/node_utils.d.ts
CHANGED
|
@@ -12,9 +12,24 @@ export declare const isStringLiteral: (node: any) => node is import("sql-parser-
|
|
|
12
12
|
export declare const isArraySubscript: (node: any) => node is import("sql-parser-cst").ArraySubscript;
|
|
13
13
|
export declare const isAsClause: (node: any) => node is import("sql-parser-cst").AsClause<Node>;
|
|
14
14
|
export declare const isParenExpr: (node: any) => node is import("sql-parser-cst").ParenExpr<Node>;
|
|
15
|
+
export declare const isMemberExpr: (node: any) => node is import("sql-parser-cst").MemberExpr;
|
|
15
16
|
export declare const isSelectStmt: (node: any) => node is import("sql-parser-cst").SelectStmt;
|
|
16
17
|
export declare const isCompoundSelectStmt: (node: any) => node is import("sql-parser-cst").CompoundSelectStmt;
|
|
17
18
|
export declare const isListExpr: (node: any) => node is import("sql-parser-cst").ListExpr<Node>;
|
|
18
19
|
export declare const isCreateFunctionStmt: (node: any) => node is import("sql-parser-cst").CreateFunctionStmt;
|
|
20
|
+
export declare const isAlterFunctionStmt: (node: any) => node is import("sql-parser-cst").AlterFunctionStmt;
|
|
21
|
+
export declare const isDropFunctionStmt: (node: any) => node is import("sql-parser-cst").DropFunctionStmt;
|
|
22
|
+
export declare const isCreateProcedureStmt: (node: any) => node is import("sql-parser-cst").CreateProcedureStmt;
|
|
23
|
+
export declare const isAlterProcedureStmt: (node: any) => node is import("sql-parser-cst").AlterProcedureStmt;
|
|
24
|
+
export declare const isDropProcedureStmt: (node: any) => node is import("sql-parser-cst").DropProcedureStmt;
|
|
25
|
+
export declare const isAlterActionRename: (node: any) => node is import("sql-parser-cst").AlterActionRename;
|
|
19
26
|
export declare const isLanguageClause: (node: any) => node is import("sql-parser-cst").LanguageClause;
|
|
20
27
|
export declare const isDynamicallyLoadedFunction: (node: any) => node is import("sql-parser-cst").DynamicallyLoadedFunction;
|
|
28
|
+
export declare const isBigqueryQuotedMemberExpr: (node: any) => node is import("sql-parser-cst").BigQueryQuotedMemberExpr;
|
|
29
|
+
export declare const isCreateTriggerStmt: (node: any) => node is import("sql-parser-cst").CreateTriggerStmt;
|
|
30
|
+
export declare const isExecuteClause: (node: any) => node is import("sql-parser-cst").ExecuteClause;
|
|
31
|
+
export declare const isDataTypeName: (node: any) => node is import("sql-parser-cst").DataTypeName;
|
|
32
|
+
export declare const isIntervalDataType: (node: any) => node is import("sql-parser-cst").IntervalDataType;
|
|
33
|
+
export declare const isTimeDataType: (node: any) => node is import("sql-parser-cst").TimeDataType;
|
|
34
|
+
export declare const isParametricDataType: (node: any) => node is import("sql-parser-cst").ParametricDataType;
|
|
35
|
+
export declare const isDataType: (node: any) => boolean;
|
package/dist/node_utils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isDynamicallyLoadedFunction = exports.isLanguageClause = exports.isCreateFunctionStmt = exports.isListExpr = exports.isCompoundSelectStmt = exports.isSelectStmt = 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.isDataType = exports.isParametricDataType = exports.isTimeDataType = exports.isIntervalDataType = exports.isDataTypeName = exports.isExecuteClause = exports.isCreateTriggerStmt = exports.isBigqueryQuotedMemberExpr = exports.isDynamicallyLoadedFunction = exports.isLanguageClause = exports.isAlterActionRename = exports.isDropProcedureStmt = exports.isAlterProcedureStmt = exports.isCreateProcedureStmt = exports.isDropFunctionStmt = exports.isAlterFunctionStmt = exports.isCreateFunctionStmt = exports.isListExpr = exports.isCompoundSelectStmt = exports.isSelectStmt = exports.isMemberExpr = 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) {
|
|
@@ -20,9 +20,30 @@ exports.isStringLiteral = is("string_literal");
|
|
|
20
20
|
exports.isArraySubscript = is("array_subscript");
|
|
21
21
|
exports.isAsClause = is("as_clause");
|
|
22
22
|
exports.isParenExpr = is("paren_expr");
|
|
23
|
+
exports.isMemberExpr = is("member_expr");
|
|
23
24
|
exports.isSelectStmt = is("select_stmt");
|
|
24
25
|
exports.isCompoundSelectStmt = is("compound_select_stmt");
|
|
25
26
|
exports.isListExpr = is("list_expr");
|
|
26
27
|
exports.isCreateFunctionStmt = is("create_function_stmt");
|
|
28
|
+
exports.isAlterFunctionStmt = is("alter_function_stmt");
|
|
29
|
+
exports.isDropFunctionStmt = is("drop_function_stmt");
|
|
30
|
+
exports.isCreateProcedureStmt = is("create_procedure_stmt");
|
|
31
|
+
exports.isAlterProcedureStmt = is("alter_procedure_stmt");
|
|
32
|
+
exports.isDropProcedureStmt = is("drop_procedure_stmt");
|
|
33
|
+
exports.isAlterActionRename = is("alter_action_rename");
|
|
27
34
|
exports.isLanguageClause = is("language_clause");
|
|
28
35
|
exports.isDynamicallyLoadedFunction = is("dynamically_loaded_function");
|
|
36
|
+
exports.isBigqueryQuotedMemberExpr = is("bigquery_quoted_member_expr");
|
|
37
|
+
exports.isCreateTriggerStmt = is("create_trigger_stmt");
|
|
38
|
+
exports.isExecuteClause = is("execute_clause");
|
|
39
|
+
exports.isDataTypeName = is("data_type_name");
|
|
40
|
+
exports.isIntervalDataType = is("interval_data_type");
|
|
41
|
+
exports.isTimeDataType = is("time_data_type");
|
|
42
|
+
exports.isParametricDataType = is("parametric_data_type");
|
|
43
|
+
var isDataType = function (node) {
|
|
44
|
+
return (0, exports.isDataTypeName)(node) ||
|
|
45
|
+
(0, exports.isIntervalDataType)(node) ||
|
|
46
|
+
(0, exports.isTimeDataType)(node) ||
|
|
47
|
+
(0, exports.isParametricDataType)(node);
|
|
48
|
+
};
|
|
49
|
+
exports.isDataType = isDataType;
|
package/dist/options.d.ts
CHANGED
|
@@ -3,6 +3,9 @@ import { Node, ParserOptions as CstParserOptions } from "sql-parser-cst";
|
|
|
3
3
|
export interface SqlPluginOptions {
|
|
4
4
|
sqlKeywordCase: "preserve" | "upper" | "lower";
|
|
5
5
|
sqlLiteralCase: "preserve" | "upper" | "lower";
|
|
6
|
+
sqlTypeCase: "preserve" | "upper" | "lower";
|
|
7
|
+
sqlIdentifierCase: "preserve" | "upper" | "lower";
|
|
8
|
+
sqlFunctionCase: "preserve" | "upper" | "lower";
|
|
6
9
|
sqlParamTypes: NonNullable<CstParserOptions["paramTypes"]>;
|
|
7
10
|
sqlCanonicalSyntax: boolean;
|
|
8
11
|
sqlFinalSemicolon: boolean;
|
package/dist/options.js
CHANGED
|
@@ -38,16 +38,85 @@ exports.options = {
|
|
|
38
38
|
},
|
|
39
39
|
{
|
|
40
40
|
value: "upper",
|
|
41
|
-
description: "forces all
|
|
41
|
+
description: "forces all literals to uppercase",
|
|
42
42
|
since: "0.14.0",
|
|
43
43
|
},
|
|
44
44
|
{
|
|
45
45
|
value: "lower",
|
|
46
|
-
description: "forces all
|
|
46
|
+
description: "forces all literals to lowercase",
|
|
47
47
|
since: "0.14.0",
|
|
48
48
|
},
|
|
49
49
|
],
|
|
50
50
|
},
|
|
51
|
+
sqlTypeCase: {
|
|
52
|
+
type: "choice",
|
|
53
|
+
category: "SQL",
|
|
54
|
+
default: "upper",
|
|
55
|
+
description: "Enforces upper/lower case for SQL types",
|
|
56
|
+
choices: [
|
|
57
|
+
{
|
|
58
|
+
value: "preserve",
|
|
59
|
+
description: "preserves the existing case",
|
|
60
|
+
since: "0.17.0",
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
value: "upper",
|
|
64
|
+
description: "forces all type names to uppercase",
|
|
65
|
+
since: "0.17.0",
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
value: "lower",
|
|
69
|
+
description: "forces all type names to lowercase",
|
|
70
|
+
since: "0.17.0",
|
|
71
|
+
},
|
|
72
|
+
],
|
|
73
|
+
},
|
|
74
|
+
sqlIdentifierCase: {
|
|
75
|
+
type: "choice",
|
|
76
|
+
category: "SQL",
|
|
77
|
+
default: "preserve",
|
|
78
|
+
description: "Enforces upper/lower case for unquoted SQL identifiers",
|
|
79
|
+
choices: [
|
|
80
|
+
{
|
|
81
|
+
value: "preserve",
|
|
82
|
+
description: "preserves the existing case",
|
|
83
|
+
since: "0.17.0",
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
value: "upper",
|
|
87
|
+
description: "forces all unquoted identifier names to uppercase",
|
|
88
|
+
since: "0.17.0",
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
value: "lower",
|
|
92
|
+
description: "forces all unquoted identifier names to lowercase",
|
|
93
|
+
since: "0.17.0",
|
|
94
|
+
},
|
|
95
|
+
],
|
|
96
|
+
},
|
|
97
|
+
sqlFunctionCase: {
|
|
98
|
+
type: "choice",
|
|
99
|
+
category: "SQL",
|
|
100
|
+
default: "preserve",
|
|
101
|
+
description: "Enforces upper/lower case for SQL function names",
|
|
102
|
+
choices: [
|
|
103
|
+
{
|
|
104
|
+
value: "preserve",
|
|
105
|
+
description: "preserves the existing case",
|
|
106
|
+
since: "0.17.0",
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
value: "upper",
|
|
110
|
+
description: "forces all unquoted function names to uppercase",
|
|
111
|
+
since: "0.17.0",
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
value: "lower",
|
|
115
|
+
description: "forces all unquoted function names to lowercase",
|
|
116
|
+
since: "0.17.0",
|
|
117
|
+
},
|
|
118
|
+
],
|
|
119
|
+
},
|
|
51
120
|
sqlParamTypes: {
|
|
52
121
|
type: "string",
|
|
53
122
|
array: true,
|
|
@@ -55,7 +124,7 @@ exports.options = {
|
|
|
55
124
|
default: [{ value: [] }],
|
|
56
125
|
description: "Syntax for bound parameters",
|
|
57
126
|
// Since 0.7.0
|
|
58
|
-
// Possible values in array: "?" | "?nr" | "$nr" | ":name" | "$name" | "@name"
|
|
127
|
+
// Possible values in array: "?" | "?nr" | "$nr" | ":name" | "$name" | "@name" | "@`name`"
|
|
59
128
|
},
|
|
60
129
|
sqlCanonicalSyntax: {
|
|
61
130
|
type: "boolean",
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.alterActionMap = void 0;
|
|
4
4
|
var print_utils_1 = require("../print_utils");
|
|
5
|
+
var constraint_1 = require("./constraint");
|
|
5
6
|
exports.alterActionMap = {
|
|
6
7
|
alter_action_rename: function (print) { return print.spaced(["renameKw", "newName"]); },
|
|
7
8
|
alter_action_rename_column: function (print) {
|
|
@@ -19,8 +20,12 @@ exports.alterActionMap = {
|
|
|
19
20
|
alter_action_set_default_collate: function (print) {
|
|
20
21
|
return print.spaced(["setDefaultCollateKw", "collation"]);
|
|
21
22
|
},
|
|
22
|
-
|
|
23
|
-
|
|
23
|
+
/** cst-ignore: constraint, modifiers */
|
|
24
|
+
alter_action_add_constraint: function (print, node) {
|
|
25
|
+
return (0, print_utils_1.group)([
|
|
26
|
+
print.spaced(["addKw", "name"]),
|
|
27
|
+
(0, print_utils_1.indent)([print_utils_1.line, (0, constraint_1.printUnnamedConstraint)(print, node)]),
|
|
28
|
+
]);
|
|
24
29
|
},
|
|
25
30
|
alter_action_add_constraint_constraint_name: function (print) {
|
|
26
31
|
return print.spaced(["constraintKw", "ifNotExistsKw", "name"]);
|
package/dist/syntax/analyze.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.analyzeMap = void 0;
|
|
4
|
+
var print_utils_1 = require("../print_utils");
|
|
4
5
|
exports.analyzeMap = {
|
|
5
|
-
analyze_stmt: function (print) {
|
|
6
|
+
analyze_stmt: function (print) {
|
|
7
|
+
return (0, print_utils_1.group)(print.spaced(["analyzeKw", "tableKw", "tables"]));
|
|
8
|
+
},
|
|
6
9
|
};
|
package/dist/syntax/base.js
CHANGED
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.baseMap = void 0;
|
|
4
|
+
var node_utils_1 = require("../node_utils");
|
|
4
5
|
exports.baseMap = {
|
|
5
6
|
/** cst-ignore: name */
|
|
6
7
|
keyword: function (print, node, path, options) {
|
|
7
|
-
var
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
return path.node.text;
|
|
12
|
-
}
|
|
13
|
-
switch (options.sqlKeywordCase) {
|
|
8
|
+
var keywordCase = (0, node_utils_1.isDataType)(path.parent)
|
|
9
|
+
? options.sqlTypeCase
|
|
10
|
+
: options.sqlKeywordCase;
|
|
11
|
+
switch (keywordCase) {
|
|
14
12
|
case "preserve":
|
|
15
13
|
return path.node.text;
|
|
16
14
|
case "upper":
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Doc } from "prettier";
|
|
2
|
+
import { AllConstraintNodes, AlterActionAddConstraint, Constraint } from "sql-parser-cst";
|
|
2
3
|
import { CstToDocMap } from "../CstToDocMap";
|
|
4
|
+
import { PrintFn } from "../PrintFn";
|
|
3
5
|
export declare const constraintMap: CstToDocMap<AllConstraintNodes>;
|
|
6
|
+
export declare const printUnnamedConstraint: <T>(print: PrintFn<Constraint<T>, "name" | "modifiers" | "constraint"> | PrintFn<AlterActionAddConstraint, "name" | "modifiers" | "constraint" | "addKw">, node: AlterActionAddConstraint | Constraint<T>) => Doc;
|
|
@@ -9,7 +9,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
9
9
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.constraintMap = void 0;
|
|
12
|
+
exports.printUnnamedConstraint = exports.constraintMap = void 0;
|
|
13
13
|
var print_utils_1 = require("../print_utils");
|
|
14
14
|
exports.constraintMap = {
|
|
15
15
|
/** cst-ignore: constraint, modifiers */
|
|
@@ -17,11 +17,11 @@ exports.constraintMap = {
|
|
|
17
17
|
if (node.name) {
|
|
18
18
|
return (0, print_utils_1.group)([
|
|
19
19
|
print("name"),
|
|
20
|
-
(0, print_utils_1.indent)([print_utils_1.line, printUnnamedConstraint(print, node)]),
|
|
20
|
+
(0, print_utils_1.indent)([print_utils_1.line, (0, exports.printUnnamedConstraint)(print, node)]),
|
|
21
21
|
]);
|
|
22
22
|
}
|
|
23
23
|
else {
|
|
24
|
-
return printUnnamedConstraint(print, node);
|
|
24
|
+
return (0, exports.printUnnamedConstraint)(print, node);
|
|
25
25
|
}
|
|
26
26
|
},
|
|
27
27
|
constraint_name: function (print) { return print.spaced(["constraintKw", "name"]); },
|
|
@@ -113,3 +113,4 @@ var printUnnamedConstraint = function (print, node) {
|
|
|
113
113
|
return print("constraint");
|
|
114
114
|
}
|
|
115
115
|
};
|
|
116
|
+
exports.printUnnamedConstraint = printUnnamedConstraint;
|
|
@@ -19,7 +19,7 @@ exports.createTableMap = {
|
|
|
19
19
|
for (var _i = 2; _i < arguments.length; _i++) {
|
|
20
20
|
rest[_i - 2] = arguments[_i];
|
|
21
21
|
}
|
|
22
|
-
return [
|
|
22
|
+
return (0, print_utils_1.group)([
|
|
23
23
|
print.spaced([
|
|
24
24
|
"createKw",
|
|
25
25
|
"orReplaceKw",
|
|
@@ -33,7 +33,7 @@ exports.createTableMap = {
|
|
|
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
38
|
relation_kind: function (print) { return print.spaced("kindKw"); },
|
|
39
39
|
column_definition: function (print) {
|
package/dist/syntax/data_type.js
CHANGED
|
@@ -1,20 +1,39 @@
|
|
|
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.dataTypeMap = void 0;
|
|
4
13
|
var utils_1 = require("../utils");
|
|
5
14
|
var print_utils_1 = require("../print_utils");
|
|
15
|
+
var node_utils_1 = require("../node_utils");
|
|
6
16
|
exports.dataTypeMap = {
|
|
17
|
+
data_type_name: function (print) { return print.spaced("name"); },
|
|
7
18
|
// print single-word types as `TYPE(10)` and multi-word types as `MY TYPE (10)`
|
|
8
|
-
|
|
9
|
-
return (isMultiWordTypeName(node) ? print.spaced : print)([
|
|
19
|
+
modified_data_type: function (print, node) {
|
|
20
|
+
return (isMultiWordTypeName(node.dataType) ? print.spaced : print)([
|
|
21
|
+
"dataType",
|
|
22
|
+
"modifiers",
|
|
23
|
+
]);
|
|
10
24
|
},
|
|
11
|
-
data_type_identifier: function (print) { return print.spaced("name"); },
|
|
12
25
|
setof_data_type: function (print) { return print.spaced(["setofKw", "dataType"]); },
|
|
13
26
|
array_data_type: function (print) { return print(["dataType", "bounds"]); },
|
|
14
27
|
array_bounds: function (print) { return ["[", print("bounds"), "]"]; },
|
|
15
|
-
|
|
16
|
-
return
|
|
28
|
+
time_data_type: function (print, node) {
|
|
29
|
+
return (0, print_utils_1.group)((0, print_utils_1.join)(" ", __spreadArray([
|
|
30
|
+
print(["timeKw", "precision"])
|
|
31
|
+
], (node.timeZoneKw ? [print.spaced("timeZoneKw")] : []), true)));
|
|
32
|
+
},
|
|
33
|
+
interval_data_type: function (print) {
|
|
34
|
+
return print.spaced(["intervalKw", "fieldsKw", "precision"]);
|
|
17
35
|
},
|
|
36
|
+
parametric_data_type: function (print) { return print(["typeKw", "params"]); },
|
|
18
37
|
generic_type_params: function (print) {
|
|
19
38
|
return (0, print_utils_1.group)(["<", (0, print_utils_1.indent)([print_utils_1.softline, print("params")]), print_utils_1.softline, ">"]);
|
|
20
39
|
},
|
|
@@ -25,6 +44,5 @@ exports.dataTypeMap = {
|
|
|
25
44
|
table_data_type: function (print) { return print.spaced(["tableKw", "columns"]); },
|
|
26
45
|
};
|
|
27
46
|
function isMultiWordTypeName(node) {
|
|
28
|
-
return ((0, utils_1.isArray)(node.name)
|
|
29
|
-
(node.name.type === "data_type_identifier" && (0, utils_1.isArray)(node.name.name)));
|
|
47
|
+
return (0, node_utils_1.isDataTypeName)(node) && (0, utils_1.isArray)(node.name) && node.name.length > 1;
|
|
30
48
|
}
|
|
@@ -18,7 +18,7 @@ exports.bigqueryMap = {
|
|
|
18
18
|
},
|
|
19
19
|
// ROW ACCESS POLICY
|
|
20
20
|
create_row_access_policy_stmt: function (print) {
|
|
21
|
-
return (0, print_utils_1.join)(print_utils_1.hardline, __spreadArray([
|
|
21
|
+
return (0, print_utils_1.group)((0, print_utils_1.join)(print_utils_1.hardline, __spreadArray([
|
|
22
22
|
print.spaced([
|
|
23
23
|
"createKw",
|
|
24
24
|
"orReplaceKw",
|
|
@@ -28,7 +28,7 @@ exports.bigqueryMap = {
|
|
|
28
28
|
"onKw",
|
|
29
29
|
"table",
|
|
30
30
|
])
|
|
31
|
-
], print("clauses"), true));
|
|
31
|
+
], print("clauses"), true)));
|
|
32
32
|
},
|
|
33
33
|
row_access_policy_grant_clause: function (print) {
|
|
34
34
|
return print.spaced(["grantToKw", "grantees"]);
|
|
@@ -37,7 +37,7 @@ exports.bigqueryMap = {
|
|
|
37
37
|
return print.spaced(["filterUsingKw", "expr"]);
|
|
38
38
|
},
|
|
39
39
|
drop_row_access_policy_stmt: function (print) {
|
|
40
|
-
return print.spaced([
|
|
40
|
+
return (0, print_utils_1.group)(print.spaced([
|
|
41
41
|
"dropKw",
|
|
42
42
|
"allKw",
|
|
43
43
|
"rowAccessPolicyKw",
|
|
@@ -45,80 +45,86 @@ exports.bigqueryMap = {
|
|
|
45
45
|
"name",
|
|
46
46
|
"onKw",
|
|
47
47
|
"table",
|
|
48
|
-
]);
|
|
48
|
+
]));
|
|
49
49
|
},
|
|
50
50
|
// CAPACITY
|
|
51
|
-
create_capacity_stmt: function (print) {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
51
|
+
create_capacity_stmt: function (print) {
|
|
52
|
+
return (0, print_utils_1.group)([
|
|
53
|
+
print.spaced(["createKw", "capacityKw", "name"]),
|
|
54
|
+
print_utils_1.hardline,
|
|
55
|
+
print("options"),
|
|
56
|
+
]);
|
|
57
|
+
},
|
|
56
58
|
drop_capacity_stmt: function (print) {
|
|
57
|
-
return print.spaced(["dropKw", "capacityKw", "ifExistsKw", "name"]);
|
|
59
|
+
return (0, print_utils_1.group)(print.spaced(["dropKw", "capacityKw", "ifExistsKw", "name"]));
|
|
58
60
|
},
|
|
59
61
|
// RESERVATION
|
|
60
|
-
create_reservation_stmt: function (print) {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
62
|
+
create_reservation_stmt: function (print) {
|
|
63
|
+
return (0, print_utils_1.group)([
|
|
64
|
+
print.spaced(["createKw", "reservationKw", "name"]),
|
|
65
|
+
print_utils_1.hardline,
|
|
66
|
+
print("options"),
|
|
67
|
+
]);
|
|
68
|
+
},
|
|
65
69
|
drop_reservation_stmt: function (print) {
|
|
66
|
-
return print.spaced(["dropKw", "reservationKw", "ifExistsKw", "name"]);
|
|
70
|
+
return (0, print_utils_1.group)(print.spaced(["dropKw", "reservationKw", "ifExistsKw", "name"]));
|
|
67
71
|
},
|
|
68
72
|
// ASSIGNMENT
|
|
69
|
-
create_assignment_stmt: function (print) {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
73
|
+
create_assignment_stmt: function (print) {
|
|
74
|
+
return (0, print_utils_1.group)([
|
|
75
|
+
print.spaced(["createKw", "assignmentKw", "name"]),
|
|
76
|
+
print_utils_1.hardline,
|
|
77
|
+
print("options"),
|
|
78
|
+
]);
|
|
79
|
+
},
|
|
74
80
|
drop_assignment_stmt: function (print) {
|
|
75
|
-
return print.spaced(["dropKw", "assignmentKw", "ifExistsKw", "name"]);
|
|
81
|
+
return (0, print_utils_1.group)(print.spaced(["dropKw", "assignmentKw", "ifExistsKw", "name"]));
|
|
76
82
|
},
|
|
77
83
|
// ALTER ORGANIZATION
|
|
78
84
|
alter_organization_stmt: function (print) {
|
|
79
|
-
return (0, print_utils_1.join)(print_utils_1.hardline, [print.spaced("alterOrganizationKw"), print("actions")]);
|
|
85
|
+
return (0, print_utils_1.group)((0, print_utils_1.join)(print_utils_1.hardline, [print.spaced("alterOrganizationKw"), print("actions")]));
|
|
80
86
|
},
|
|
81
87
|
// ALTER PROJECT
|
|
82
88
|
alter_project_stmt: function (print) {
|
|
83
|
-
return (0, print_utils_1.join)(print_utils_1.hardline, [
|
|
89
|
+
return (0, print_utils_1.group)((0, print_utils_1.join)(print_utils_1.hardline, [
|
|
84
90
|
print.spaced(["alterProjectKw", "name"]),
|
|
85
91
|
print("actions"),
|
|
86
|
-
]);
|
|
92
|
+
]));
|
|
87
93
|
},
|
|
88
94
|
alter_bi_capacity_stmt: function (print) {
|
|
89
|
-
return (0, print_utils_1.join)(print_utils_1.hardline, [
|
|
95
|
+
return (0, print_utils_1.group)((0, print_utils_1.join)(print_utils_1.hardline, [
|
|
90
96
|
print.spaced(["alterBiCapacityKw", "name"]),
|
|
91
97
|
print("actions"),
|
|
92
|
-
]);
|
|
98
|
+
]));
|
|
93
99
|
},
|
|
94
100
|
alter_capacity_stmt: function (print) {
|
|
95
|
-
return (0, print_utils_1.join)(print_utils_1.hardline, [
|
|
101
|
+
return (0, print_utils_1.group)((0, print_utils_1.join)(print_utils_1.hardline, [
|
|
96
102
|
print.spaced(["alterCapacityKw", "name"]),
|
|
97
103
|
print("actions"),
|
|
98
|
-
]);
|
|
104
|
+
]));
|
|
99
105
|
},
|
|
100
106
|
alter_reservation_stmt: function (print) {
|
|
101
|
-
return (0, print_utils_1.join)(print_utils_1.hardline, [
|
|
107
|
+
return (0, print_utils_1.group)((0, print_utils_1.join)(print_utils_1.hardline, [
|
|
102
108
|
print.spaced(["alterReservationKw", "name"]),
|
|
103
109
|
print("actions"),
|
|
104
|
-
]);
|
|
110
|
+
]));
|
|
105
111
|
},
|
|
106
112
|
// ASSERT
|
|
107
|
-
assert_stmt: function (print) { return print.spaced(["assertKw", "expr", "as"]); },
|
|
113
|
+
assert_stmt: function (print) { return (0, print_utils_1.group)(print.spaced(["assertKw", "expr", "as"])); },
|
|
108
114
|
// EXPORT
|
|
109
115
|
export_data_stmt: function (print) {
|
|
110
|
-
return (0, print_utils_1.join)(print_utils_1.hardline, __spreadArray(__spreadArray([
|
|
116
|
+
return (0, print_utils_1.group)((0, print_utils_1.join)(print_utils_1.hardline, __spreadArray(__spreadArray([
|
|
111
117
|
print.spaced("exportDataKw")
|
|
112
118
|
], print.spaced(["withConnection"]), true), [
|
|
113
119
|
print.spaced("options"),
|
|
114
120
|
print.spaced("as"),
|
|
115
|
-
], false));
|
|
121
|
+
], false)));
|
|
116
122
|
},
|
|
117
123
|
// LOAD
|
|
118
124
|
load_data_stmt: function (print) {
|
|
119
|
-
return (0, print_utils_1.join)(print_utils_1.hardline, __spreadArray([
|
|
125
|
+
return (0, print_utils_1.group)((0, print_utils_1.join)(print_utils_1.hardline, __spreadArray([
|
|
120
126
|
print.spaced(["loadDataKw", "intoKw", "table", "columns"])
|
|
121
|
-
], print("clauses"), true));
|
|
127
|
+
], print("clauses"), true)));
|
|
122
128
|
},
|
|
123
129
|
from_files_options: function (print) { return print.spaced(["fromFilesKw", "options"]); },
|
|
124
130
|
};
|
|
@@ -4,15 +4,15 @@ exports.sqliteMap = void 0;
|
|
|
4
4
|
var print_utils_1 = require("../../print_utils");
|
|
5
5
|
exports.sqliteMap = {
|
|
6
6
|
attach_database_stmt: function (print) {
|
|
7
|
-
return print.spaced(["attachKw", "databaseKw", "file", "asKw", "schema"]);
|
|
7
|
+
return (0, print_utils_1.group)(print.spaced(["attachKw", "databaseKw", "file", "asKw", "schema"]));
|
|
8
8
|
},
|
|
9
9
|
detach_database_stmt: function (print) {
|
|
10
|
-
return print.spaced(["detachKw", "databaseKw", "schema"]);
|
|
10
|
+
return (0, print_utils_1.group)(print.spaced(["detachKw", "databaseKw", "schema"]));
|
|
11
11
|
},
|
|
12
12
|
vacuum_stmt: function (print) {
|
|
13
|
-
return print.spaced(["vacuumKw", "schema", "intoKw", "file"]);
|
|
13
|
+
return (0, print_utils_1.group)(print.spaced(["vacuumKw", "schema", "intoKw", "file"]));
|
|
14
14
|
},
|
|
15
|
-
pragma_stmt: function (print) { return print.spaced(["pragmaKw", "pragma"]); },
|
|
15
|
+
pragma_stmt: function (print) { return (0, print_utils_1.group)(print.spaced(["pragmaKw", "pragma"])); },
|
|
16
16
|
pragma_assignment: function (print) { return (0, print_utils_1.join)(" = ", print(["name", "value"])); },
|
|
17
17
|
pragma_func_call: function (print) { return print(["name", "args"]); },
|
|
18
18
|
};
|
package/dist/syntax/do.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.doMap = void 0;
|
|
4
|
+
var print_utils_1 = require("../print_utils");
|
|
4
5
|
exports.doMap = {
|
|
5
|
-
do_stmt: function (print) { return print.spaced(["doKw", "language", "body"]); },
|
|
6
|
+
do_stmt: function (print) { return (0, print_utils_1.group)(print.spaced(["doKw", "language", "body"])); },
|
|
6
7
|
};
|