prettier-plugin-sql-cst 0.11.7 → 0.11.8
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 +39 -1
- package/dist/syntax/alter_action.js +40 -0
- package/dist/syntax/data_type.js +1 -1
- package/dist/syntax/domain.d.ts +3 -0
- package/dist/syntax/domain.js +20 -0
- package/dist/syntax/expr.js +5 -1
- package/dist/syntax/function.js +0 -2
- package/dist/syntax/transformMap.js +3 -1
- package/dist/syntax/type.d.ts +3 -0
- package/dist/syntax/type.js +23 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -60,6 +60,10 @@ Install it as any other Prettier plugin:
|
|
|
60
60
|
|
|
61
61
|
```
|
|
62
62
|
npm install --save-dev prettier prettier-plugin-sql-cst
|
|
63
|
+
# or
|
|
64
|
+
pnpm add --save-dev prettier prettier-plugin-sql-cst
|
|
65
|
+
# or
|
|
66
|
+
yarn add --dev prettier prettier-plugin-sql-cst
|
|
63
67
|
```
|
|
64
68
|
|
|
65
69
|
Then use it on SQL files through Prettier command line tool or Prettier extension
|
|
@@ -72,10 +76,11 @@ By default the plugin will determine SQL dialect based on file extension:
|
|
|
72
76
|
- `.sql` or `.sqlite` - SQLite
|
|
73
77
|
- `.bigquery` - BigQuery
|
|
74
78
|
|
|
75
|
-
You can override this behavior with a prettier configuration:
|
|
79
|
+
You can override this behavior with a prettier configuration in `.prettierrc.json` file:
|
|
76
80
|
|
|
77
81
|
```json
|
|
78
82
|
{
|
|
83
|
+
"plugins": ["prettier-plugin-sql-cst"],
|
|
79
84
|
"overrides": [
|
|
80
85
|
{
|
|
81
86
|
"files": ["*.sql"],
|
|
@@ -85,6 +90,22 @@ You can override this behavior with a prettier configuration:
|
|
|
85
90
|
}
|
|
86
91
|
```
|
|
87
92
|
|
|
93
|
+
Or you could also store it inside your `package.json`:
|
|
94
|
+
|
|
95
|
+
```json
|
|
96
|
+
{
|
|
97
|
+
"prettier": {
|
|
98
|
+
"plugins": ["prettier-plugin-sql-cst"],
|
|
99
|
+
"overrides": [
|
|
100
|
+
{
|
|
101
|
+
"files": ["*.sql"],
|
|
102
|
+
"options": { "parser": "bigquery" }
|
|
103
|
+
}
|
|
104
|
+
]
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
```
|
|
108
|
+
|
|
88
109
|
The plugin provides the following parsers:
|
|
89
110
|
|
|
90
111
|
- `sqlite`
|
|
@@ -104,6 +125,23 @@ There are also some SQL-specific options:
|
|
|
104
125
|
| `sqlParamTypes` | `[]` | Array of bound parameter types: `?`, `?nr`, `$nr`, `:name`, `@name`, `$name`. |
|
|
105
126
|
| `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) |
|
|
106
127
|
|
|
128
|
+
## Usage inside VSCode
|
|
129
|
+
|
|
130
|
+
To use this plugin inside VSCode,
|
|
131
|
+
install the [Prettier VSCode](https://github.com/prettier/prettier-vscode?tab=readme-ov-file#installation) extension.
|
|
132
|
+
|
|
133
|
+
Follow [Prettier VSCode docs](https://github.com/prettier/prettier-vscode?tab=readme-ov-file#default-formatter)
|
|
134
|
+
to configure it as the default formatter.
|
|
135
|
+
|
|
136
|
+
You might also need to configure
|
|
137
|
+
[prettier.documentSelectors](https://github.com/prettier/prettier-vscode?tab=readme-ov-file#prettierdocumentselectors)
|
|
138
|
+
to enable Prettier for `*.sql` files.
|
|
139
|
+
|
|
140
|
+
To see what Prettier is, or is not doing - open the VSCode Output window and select the Prettier dropdown.
|
|
141
|
+
On format, the window should show your `inferredParser`. It should reconfirm that by showing `"parser": "sqlite"`
|
|
142
|
+
(or whichever perser you have configured inside your prettier config `overrides` section)
|
|
143
|
+
and `plugins` with the path to this package. If you don't see that part, Prettier not using this package.
|
|
144
|
+
|
|
107
145
|
## FAQ
|
|
108
146
|
|
|
109
147
|
### The SQL dialect I'm using is not supported. Can you add support for it?
|
|
@@ -91,6 +91,46 @@ exports.alterActionMap = {
|
|
|
91
91
|
alter_action_attach_partition: function (print) {
|
|
92
92
|
return print.spaced(["attachPartitionKw", "index"]);
|
|
93
93
|
},
|
|
94
|
+
alter_action_add_enum_value: function (print) {
|
|
95
|
+
return print.spaced(["addValueKw", "ifNotExistsKw", "value", "position"]);
|
|
96
|
+
},
|
|
97
|
+
alter_action_add_enum_value_position: function (print) {
|
|
98
|
+
return print.spaced(["positionKw", "value"]);
|
|
99
|
+
},
|
|
100
|
+
alter_action_rename_enum_value: function (print) {
|
|
101
|
+
return print.spaced(["renameValueKw", "oldValue", "toKw", "newValue"]);
|
|
102
|
+
},
|
|
103
|
+
alter_action_add_attribute: function (print) {
|
|
104
|
+
return print.spaced([
|
|
105
|
+
"addAttributeKw",
|
|
106
|
+
"name",
|
|
107
|
+
"dataType",
|
|
108
|
+
"constraint",
|
|
109
|
+
"behaviorKw",
|
|
110
|
+
]);
|
|
111
|
+
},
|
|
112
|
+
alter_action_drop_attribute: function (print) {
|
|
113
|
+
return print.spaced(["dropAttributeKw", "ifExistsKw", "name", "behaviorKw"]);
|
|
114
|
+
},
|
|
115
|
+
alter_action_alter_attribute: function (print) {
|
|
116
|
+
return print.spaced([
|
|
117
|
+
"alterAttributeKw",
|
|
118
|
+
"name",
|
|
119
|
+
"setDataTypeKw",
|
|
120
|
+
"dataType",
|
|
121
|
+
"constraint",
|
|
122
|
+
"behaviorKw",
|
|
123
|
+
]);
|
|
124
|
+
},
|
|
125
|
+
alter_action_rename_attribute: function (print) {
|
|
126
|
+
return print.spaced([
|
|
127
|
+
"renameAttributeKw",
|
|
128
|
+
"oldName",
|
|
129
|
+
"toKw",
|
|
130
|
+
"newName",
|
|
131
|
+
"behaviorKw",
|
|
132
|
+
]);
|
|
133
|
+
},
|
|
94
134
|
// ALTER COLUMN
|
|
95
135
|
alter_action_alter_column: function (print) {
|
|
96
136
|
return (0, print_utils_1.group)([
|
package/dist/syntax/data_type.js
CHANGED
|
@@ -6,7 +6,7 @@ var print_utils_1 = require("../print_utils");
|
|
|
6
6
|
exports.dataTypeMap = {
|
|
7
7
|
// print single-word types as `TYPE(10)` and multi-word types as `MY TYPE (10)`
|
|
8
8
|
named_data_type: function (print, node) {
|
|
9
|
-
return ((0, utils_1.isArray)(node.
|
|
9
|
+
return ((0, utils_1.isArray)(node.name) ? print.spaced : print)(["name", "params"]);
|
|
10
10
|
},
|
|
11
11
|
array_data_type: function (print) { return print(["dataType", "bounds"]); },
|
|
12
12
|
array_bounds: function (print) { return ["[", print("bounds"), "]"]; },
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.domainMap = void 0;
|
|
4
|
+
var print_utils_1 = require("../print_utils");
|
|
5
|
+
exports.domainMap = {
|
|
6
|
+
create_domain_stmt: function (print, node) {
|
|
7
|
+
return (0, print_utils_1.group)([
|
|
8
|
+
print.spaced(["createDomainKw", "name", "asKw", "dataType"]),
|
|
9
|
+
node.constraints.length > 0
|
|
10
|
+
? (0, print_utils_1.indent)([print.dynamicLine(), (0, print_utils_1.join)(print_utils_1.line, print("constraints"))])
|
|
11
|
+
: [],
|
|
12
|
+
]);
|
|
13
|
+
},
|
|
14
|
+
alter_domain_stmt: function (print, node) {
|
|
15
|
+
return (0, print_utils_1.group)(print.spaced(["alterDomainKw", "name", "action"]));
|
|
16
|
+
},
|
|
17
|
+
drop_domain_stmt: function (print) {
|
|
18
|
+
return (0, print_utils_1.group)(print.spaced(["dropDomainKw", "ifExistsKw", "domains", "behaviorKw"]));
|
|
19
|
+
},
|
|
20
|
+
};
|
package/dist/syntax/expr.js
CHANGED
|
@@ -128,7 +128,11 @@ exports.exprMap = {
|
|
|
128
128
|
cast_arg: function (print) { return print.spaced(["expr", "asKw", "dataType", "format"]); },
|
|
129
129
|
cast_format: function (print) { return print.spaced(["formatKw", "string", "timezone"]); },
|
|
130
130
|
cast_format_timezone: function (print) { return print.spaced(["atTimeZoneKw", "timezone"]); },
|
|
131
|
-
cast_operator_expr: function (print) { return [
|
|
131
|
+
cast_operator_expr: function (print) { return [
|
|
132
|
+
print("left"),
|
|
133
|
+
print("operator"),
|
|
134
|
+
print("right"),
|
|
135
|
+
]; },
|
|
132
136
|
string_with_charset: function (print) { return ["_", print(["charset", "string"])]; },
|
|
133
137
|
raise_expr: function (print) { return print(["raiseKw", "args"]); },
|
|
134
138
|
raise_expr_type: function (print) { return print("typeKw"); },
|
package/dist/syntax/function.js
CHANGED
|
@@ -4,7 +4,6 @@ exports.functionMap = void 0;
|
|
|
4
4
|
var print_utils_1 = require("../print_utils");
|
|
5
5
|
var node_utils_1 = require("../node_utils");
|
|
6
6
|
exports.functionMap = {
|
|
7
|
-
/** cst-ignore: behaviorKw */
|
|
8
7
|
create_function_stmt: function (print, node) { return [
|
|
9
8
|
print.spaced([
|
|
10
9
|
"createKw",
|
|
@@ -65,7 +64,6 @@ exports.functionMap = {
|
|
|
65
64
|
]);
|
|
66
65
|
},
|
|
67
66
|
reset_parameter_clause: function (print) { return print.spaced(["resetKw", "name"]); },
|
|
68
|
-
/** cst-ignore: name */
|
|
69
67
|
reset_all_parameters_clause: function (print) { return print.spaced("resetAllKw"); },
|
|
70
68
|
};
|
|
71
69
|
var hasOnlyAsClause = function (node) {
|
|
@@ -22,6 +22,7 @@ var create_table_1 = require("./create_table");
|
|
|
22
22
|
var data_type_1 = require("./data_type");
|
|
23
23
|
var dcl_1 = require("./dcl");
|
|
24
24
|
var delete_1 = require("./delete");
|
|
25
|
+
var domain_1 = require("./domain");
|
|
25
26
|
var drop_table_1 = require("./drop_table");
|
|
26
27
|
var explain_1 = require("./explain");
|
|
27
28
|
var expr_1 = require("./expr");
|
|
@@ -43,10 +44,11 @@ var sequence_1 = require("./sequence");
|
|
|
43
44
|
var transaction_1 = require("./transaction");
|
|
44
45
|
var trigger_1 = require("./trigger");
|
|
45
46
|
var truncate_1 = require("./truncate");
|
|
47
|
+
var type_1 = require("./type");
|
|
46
48
|
var update_1 = require("./update");
|
|
47
49
|
var view_1 = require("./view");
|
|
48
50
|
var bigquery_1 = require("./dialects/bigquery");
|
|
49
51
|
var mysql_1 = require("./dialects/mysql");
|
|
50
52
|
var sqlite_1 = require("./dialects/sqlite");
|
|
51
53
|
var postgresql_1 = require("./dialects/postgresql");
|
|
52
|
-
exports.transformMap = __assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign({}, alias_1.aliasMap), alter_action_1.alterActionMap), alter_table_1.alterTableMap), analyze_1.analyzeMap), base_1.baseMap), constraint_1.constraintMap), create_table_1.createTableMap), data_type_1.dataTypeMap), dcl_1.dclMap), delete_1.deleteMap), drop_table_1.dropTableMap), explain_1.explainMap), expr_1.exprMap), frame_1.frameMap), function_1.functionMap), index_1.indexMap), insert_1.insertMap), merge_1.mergeMap), other_clauses_1.otherClausesMap), prepared_statements_1.preparedStatementsMap), proc_clause_1.procClauseMap), procedural_language_1.proceduralLanguageMap), procedure_1.procedureMap), program_1.programMap), rename_table_1.renameTableMap), schema_1.schemaMap), select_1.selectMap), sequence_1.sequenceMap), transaction_1.transactionMap), trigger_1.triggerMap), truncate_1.truncateMap), update_1.updateMap), view_1.viewMap), bigquery_1.bigqueryMap), mysql_1.mysqlMap), postgresql_1.postgresqlMap), sqlite_1.sqliteMap);
|
|
54
|
+
exports.transformMap = __assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign({}, alias_1.aliasMap), alter_action_1.alterActionMap), alter_table_1.alterTableMap), analyze_1.analyzeMap), base_1.baseMap), constraint_1.constraintMap), create_table_1.createTableMap), data_type_1.dataTypeMap), dcl_1.dclMap), delete_1.deleteMap), domain_1.domainMap), drop_table_1.dropTableMap), explain_1.explainMap), expr_1.exprMap), frame_1.frameMap), function_1.functionMap), index_1.indexMap), insert_1.insertMap), merge_1.mergeMap), other_clauses_1.otherClausesMap), prepared_statements_1.preparedStatementsMap), proc_clause_1.procClauseMap), procedural_language_1.proceduralLanguageMap), procedure_1.procedureMap), program_1.programMap), rename_table_1.renameTableMap), schema_1.schemaMap), select_1.selectMap), sequence_1.sequenceMap), transaction_1.transactionMap), trigger_1.triggerMap), truncate_1.truncateMap), type_1.typeMap), update_1.updateMap), view_1.viewMap), bigquery_1.bigqueryMap), mysql_1.mysqlMap), postgresql_1.postgresqlMap), sqlite_1.sqliteMap);
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.typeMap = void 0;
|
|
4
|
+
var print_utils_1 = require("../print_utils");
|
|
5
|
+
exports.typeMap = {
|
|
6
|
+
create_type_stmt: function (print) {
|
|
7
|
+
return (0, print_utils_1.group)([print.spaced(["createTypeKw", "name", "definition"])]);
|
|
8
|
+
},
|
|
9
|
+
composite_type_definition: function (print) {
|
|
10
|
+
return (0, print_utils_1.group)(print.spaced(["asKw", "columns"]));
|
|
11
|
+
},
|
|
12
|
+
enum_type_definition: function (print) { return (0, print_utils_1.group)(print.spaced(["asEnumKw", "values"])); },
|
|
13
|
+
alter_type_stmt: function (print, node) {
|
|
14
|
+
return (0, print_utils_1.group)([
|
|
15
|
+
print.spaced(["alterTypeKw", "name"]),
|
|
16
|
+
print.dynamicLine(),
|
|
17
|
+
print("actions"),
|
|
18
|
+
]);
|
|
19
|
+
},
|
|
20
|
+
drop_type_stmt: function (print) {
|
|
21
|
+
return (0, print_utils_1.group)(print.spaced(["dropTypeKw", "ifExistsKw", "types", "behaviorKw"]));
|
|
22
|
+
},
|
|
23
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "prettier-plugin-sql-cst",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.8",
|
|
4
4
|
"description": "Prettier plugin for SQL",
|
|
5
5
|
"contributors": [
|
|
6
6
|
"Bowen Parnell <bparnell@4tel.com.au>",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
],
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"prettier": "^3.0.3",
|
|
39
|
-
"sql-parser-cst": "^0.
|
|
39
|
+
"sql-parser-cst": "^0.29.1"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@types/jest": "^29.2.5",
|