prettier-plugin-sql-cst 0.10.1 → 0.10.2
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 +15 -0
- package/dist/PrintFn.d.ts +2 -0
- package/dist/printSql.js +3 -2
- package/dist/syntax/dialects/postgresql.d.ts +1 -1
- package/dist/syntax/insert.js +5 -1
- package/dist/syntax/merge.js +7 -14
- package/dist/syntax/other_clauses.d.ts +3 -0
- package/dist/syntax/other_clauses.js +18 -0
- package/dist/syntax/rename_table.d.ts +3 -0
- package/dist/syntax/rename_table.js +13 -0
- package/dist/syntax/select.js +3 -30
- package/dist/syntax/transformMap.d.ts +1 -1
- package/dist/syntax/transformMap.js +3 -1
- package/dist/syntax/trigger.js +1 -1
- package/dist/syntax/truncate.js +14 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -103,6 +103,20 @@ There are also some SQL-specific options:
|
|
|
103
103
|
| `sqlKeywordCase` | `upper` | Converts SQL keywords to `upper` or `lower` case, or `preserve` existing. |
|
|
104
104
|
| `sqlParamTypes` | `[]` | Array of bound parameter types: `?`, `?nr`, `:name`, `@name`, `$name`. |
|
|
105
105
|
|
|
106
|
+
## FAQ
|
|
107
|
+
|
|
108
|
+
### The SQL dialect I'm using is not supported. Can you add support for it?
|
|
109
|
+
|
|
110
|
+
Support for new SQL dialects depends on these dialects being supported by [sql-parser-cst][].
|
|
111
|
+
If you really want to, you can open a new issue for that in the parser repo.
|
|
112
|
+
But be aware that implementing parser support for new dialects takes a lot of work.
|
|
113
|
+
As long as the ongoing implementation of PostgreSQL, MySQL and MariaDB is not finished,
|
|
114
|
+
it's unlikely that work on any other dialect will start.
|
|
115
|
+
|
|
116
|
+
### How can I format SQL strings inside JavaScript files?
|
|
117
|
+
|
|
118
|
+
Use [prettier-plugin-embed][] together with `prettier-plugin-sql-cst`.
|
|
119
|
+
|
|
106
120
|
## Limitations and development status
|
|
107
121
|
|
|
108
122
|
Currently this plugin supports two SQL dialects:
|
|
@@ -132,4 +146,5 @@ Though the general principles should be mostly in place by now.
|
|
|
132
146
|
[useTabs]: https://prettier.io/docs/en/options.html#tabs
|
|
133
147
|
[sql-parser-cst]: https://github.com/nene/sql-parser-cst
|
|
134
148
|
[wadler-prettier]: http://homepages.inf.ed.ac.uk/wadler/papers/prettier/prettier.pdf
|
|
149
|
+
[prettier-plugin-embed]: https://github.com/Sec-ant/prettier-plugin-embed
|
|
135
150
|
[STYLE_GUIDE]: ./STYLE_GUIDE.md
|
package/dist/PrintFn.d.ts
CHANGED
|
@@ -8,6 +8,8 @@ export type PrintFn<T, K = PrintableKey<T>> = {
|
|
|
8
8
|
(path: K[]): Doc[];
|
|
9
9
|
spaced(path: K): Doc[];
|
|
10
10
|
spaced(path: K[]): Doc[];
|
|
11
|
+
separated(separator: Doc, path: K): Doc[];
|
|
12
|
+
separated(separator: Doc, path: K[]): Doc[];
|
|
11
13
|
};
|
|
12
14
|
export type PrintableKey<T> = Exclude<keyof T, ReservedKey>;
|
|
13
15
|
type ReservedKey = "type" | "range" | "leading" | "trailing";
|
package/dist/printSql.js
CHANGED
|
@@ -28,7 +28,7 @@ function createPrintFn(path, oldPrint) {
|
|
|
28
28
|
return oldPrint(selector);
|
|
29
29
|
}
|
|
30
30
|
});
|
|
31
|
-
cachedPrintFn.
|
|
31
|
+
cachedPrintFn.separated = function (separator, selector) {
|
|
32
32
|
var node = path.getValue();
|
|
33
33
|
var docs = (0, utils_1.arrayWrap)(selector)
|
|
34
34
|
.filter(function (sel) { return (0, utils_1.isDefined)(node[sel]); })
|
|
@@ -43,8 +43,9 @@ function createPrintFn(path, oldPrint) {
|
|
|
43
43
|
var sel = _a[0], doc = _a[1];
|
|
44
44
|
return ((0, utils_1.isArray)(node[sel]) ? (0, print_utils_1.join)(" ", doc) : doc);
|
|
45
45
|
});
|
|
46
|
-
return docs.length > 0 ? [(0, print_utils_1.join)(
|
|
46
|
+
return docs.length > 0 ? [(0, print_utils_1.join)(separator, docs)] : [];
|
|
47
47
|
};
|
|
48
|
+
cachedPrintFn.spaced = function (selector) { return cachedPrintFn.separated(" ", selector); };
|
|
48
49
|
return cachedPrintFn;
|
|
49
50
|
}
|
|
50
51
|
function printNode(path, options, print) {
|
package/dist/syntax/insert.js
CHANGED
|
@@ -17,7 +17,10 @@ exports.insertMap = {
|
|
|
17
17
|
default: function (print) { return print("defaultKw"); },
|
|
18
18
|
default_values: function (print) { return print.spaced("defaultValuesKw"); },
|
|
19
19
|
upsert_clause: function (print) {
|
|
20
|
-
return print.spaced(["onConflictKw", "
|
|
20
|
+
return print.spaced(["onConflictKw", "conflictTarget", "where", "doKw", "action"]);
|
|
21
|
+
},
|
|
22
|
+
conflict_target_on_constraint: function (print) {
|
|
23
|
+
return print.spaced(["onConstraintKw", "constraint"]);
|
|
21
24
|
},
|
|
22
25
|
upsert_action_nothing: function (print) { return print("nothingKw"); },
|
|
23
26
|
upsert_action_update: function (print) { return [
|
|
@@ -32,4 +35,5 @@ exports.insertMap = {
|
|
|
32
35
|
print.spaced("onDuplicateKeyUpdateKw"),
|
|
33
36
|
(0, print_utils_1.indent)([print_utils_1.hardline, print("assignments")]),
|
|
34
37
|
]; },
|
|
38
|
+
overriding_clause: function (print) { return print.spaced("overridingKw"); },
|
|
35
39
|
};
|
package/dist/syntax/merge.js
CHANGED
|
@@ -1,23 +1,15 @@
|
|
|
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
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.mergeMap = void 0;
|
|
13
4
|
var print_utils_1 = require("../print_utils");
|
|
14
5
|
exports.mergeMap = {
|
|
15
|
-
merge_stmt: function (print) {
|
|
16
|
-
|
|
6
|
+
merge_stmt: function (print) { return (0, print_utils_1.join)(print_utils_1.line, print("clauses")); },
|
|
7
|
+
merge_clause: function (print) {
|
|
8
|
+
return (0, print_utils_1.join)(print_utils_1.line, [
|
|
17
9
|
print.spaced(["mergeKw", "intoKw", "target"]),
|
|
18
10
|
print.spaced(["usingKw", "source"]),
|
|
19
|
-
(0, print_utils_1.group)([print("onKw"), (0, print_utils_1.indent)([print_utils_1.line, print("condition")])])
|
|
20
|
-
]
|
|
11
|
+
(0, print_utils_1.group)([print("onKw"), (0, print_utils_1.indent)([print_utils_1.line, print("condition")])]),
|
|
12
|
+
]);
|
|
21
13
|
},
|
|
22
14
|
merge_when_clause: function (print, node) { return [
|
|
23
15
|
(0, print_utils_1.group)([
|
|
@@ -35,8 +27,9 @@ exports.mergeMap = {
|
|
|
35
27
|
node.columns ? (0, print_utils_1.indent)([print_utils_1.hardline, print("columns")]) : [],
|
|
36
28
|
]),
|
|
37
29
|
print_utils_1.line,
|
|
38
|
-
(0, print_utils_1.
|
|
30
|
+
(0, print_utils_1.join)(print_utils_1.hardline, print("clauses")),
|
|
39
31
|
]; },
|
|
40
32
|
merge_action_insert_row_clause: function (print) { return print("rowKw"); },
|
|
41
33
|
merge_action_update: function (print) { return print.spaced(["updateKw", "set"]); },
|
|
34
|
+
merge_action_do_nothing: function (print) { return print.spaced(["doNothingKw"]); },
|
|
42
35
|
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.otherClausesMap = void 0;
|
|
4
|
+
var print_utils_1 = require("../print_utils");
|
|
5
|
+
exports.otherClausesMap = {
|
|
6
|
+
// CLUSTER BY clause
|
|
7
|
+
cluster_by_clause: function (print) {
|
|
8
|
+
return (0, print_utils_1.group)([print.spaced("clusterByKw"), (0, print_utils_1.indent)([print_utils_1.line, print("columns")])]);
|
|
9
|
+
},
|
|
10
|
+
// RETURNING clause
|
|
11
|
+
returning_clause: function (print) {
|
|
12
|
+
return (0, print_utils_1.group)([print("returningKw"), (0, print_utils_1.indent)([print_utils_1.line, print("columns")])]);
|
|
13
|
+
},
|
|
14
|
+
// WHERE CURRENT OF clause
|
|
15
|
+
where_current_of_clause: function (print) {
|
|
16
|
+
return print.spaced(["whereCurrentOfKw", "cursor"]);
|
|
17
|
+
},
|
|
18
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.renameTableMap = void 0;
|
|
4
|
+
var print_utils_1 = require("../print_utils");
|
|
5
|
+
exports.renameTableMap = {
|
|
6
|
+
rename_table_stmt: function (print) {
|
|
7
|
+
return (0, print_utils_1.group)([
|
|
8
|
+
print.spaced(["renameKw", "tableKw"]),
|
|
9
|
+
(0, print_utils_1.indent)([print_utils_1.line, print("actions")]),
|
|
10
|
+
]);
|
|
11
|
+
},
|
|
12
|
+
rename_action: function (print) { return print.spaced(["from", "toKw", "to"]); },
|
|
13
|
+
};
|
package/dist/syntax/select.js
CHANGED
|
@@ -1,13 +1,4 @@
|
|
|
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
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.selectMap = void 0;
|
|
13
4
|
var utils_1 = require("../utils");
|
|
@@ -33,7 +24,7 @@ exports.selectMap = {
|
|
|
33
24
|
print.spaced(["asKw", "materializedKw", "expr"]),
|
|
34
25
|
(0, print_utils_1.group)([
|
|
35
26
|
node.search || node.cycle
|
|
36
|
-
? (0, print_utils_1.indent)([print_utils_1.line,
|
|
27
|
+
? (0, print_utils_1.indent)([print_utils_1.line, print.separated(print_utils_1.line, ["search", "cycle"])])
|
|
37
28
|
: [],
|
|
38
29
|
]),
|
|
39
30
|
]; },
|
|
@@ -161,12 +152,7 @@ exports.selectMap = {
|
|
|
161
152
|
order_by_clause: function (print, node) {
|
|
162
153
|
return (0, print_utils_1.group)([
|
|
163
154
|
print.spaced("orderByKw"),
|
|
164
|
-
(0, print_utils_1.indent)([
|
|
165
|
-
print_utils_1.line,
|
|
166
|
-
(0, print_utils_1.join)(print_utils_1.line, __spreadArray([
|
|
167
|
-
print("specifications")
|
|
168
|
-
], (node.withRollupKw ? print.spaced("withRollupKw") : []), true)),
|
|
169
|
-
]),
|
|
155
|
+
(0, print_utils_1.indent)([print_utils_1.line, print.separated(print_utils_1.line, ["specifications", "withRollupKw"])]),
|
|
170
156
|
]);
|
|
171
157
|
},
|
|
172
158
|
sort_specification: function (print) {
|
|
@@ -181,12 +167,7 @@ exports.selectMap = {
|
|
|
181
167
|
group_by_clause: function (print, node) {
|
|
182
168
|
return (0, print_utils_1.group)([
|
|
183
169
|
print.spaced(["groupByKw", "distinctKw"]),
|
|
184
|
-
(0, print_utils_1.indent)([
|
|
185
|
-
print_utils_1.line,
|
|
186
|
-
(0, print_utils_1.join)(print_utils_1.line, __spreadArray([
|
|
187
|
-
print("columns")
|
|
188
|
-
], (node.withRollupKw ? print.spaced("withRollupKw") : []), true)),
|
|
189
|
-
]),
|
|
170
|
+
(0, print_utils_1.indent)([print_utils_1.line, print.separated(print_utils_1.line, ["columns", "withRollupKw"])]),
|
|
190
171
|
]);
|
|
191
172
|
},
|
|
192
173
|
group_by_rollup: function (print) { return print(["rollupKw", "columns"]); },
|
|
@@ -201,10 +182,6 @@ exports.selectMap = {
|
|
|
201
182
|
(0, print_utils_1.indent)([print_utils_1.line, print("specifications")]),
|
|
202
183
|
]);
|
|
203
184
|
},
|
|
204
|
-
// CLUSTER BY clause
|
|
205
|
-
cluster_by_clause: function (print) {
|
|
206
|
-
return (0, print_utils_1.group)([print.spaced("clusterByKw"), (0, print_utils_1.indent)([print_utils_1.line, print("columns")])]);
|
|
207
|
-
},
|
|
208
185
|
// HAVING clause
|
|
209
186
|
having_clause: function (print) {
|
|
210
187
|
return (0, print_utils_1.group)([print("havingKw"), (0, print_utils_1.indent)([print_utils_1.line, print("expr")])]);
|
|
@@ -213,10 +190,6 @@ exports.selectMap = {
|
|
|
213
190
|
qualify_clause: function (print) {
|
|
214
191
|
return (0, print_utils_1.group)([print("qualifyKw"), (0, print_utils_1.indent)([print_utils_1.line, print("expr")])]);
|
|
215
192
|
},
|
|
216
|
-
// RETURNING clause
|
|
217
|
-
returning_clause: function (print) {
|
|
218
|
-
return (0, print_utils_1.group)([print("returningKw"), (0, print_utils_1.indent)([print_utils_1.line, print("columns")])]);
|
|
219
|
-
},
|
|
220
193
|
// LIMIT clause
|
|
221
194
|
limit_clause: function (print, node) {
|
|
222
195
|
return (0, print_utils_1.group)([
|
|
@@ -29,6 +29,8 @@ var function_1 = require("./function");
|
|
|
29
29
|
var index_1 = require("./index");
|
|
30
30
|
var insert_1 = require("./insert");
|
|
31
31
|
var merge_1 = require("./merge");
|
|
32
|
+
var other_clauses_1 = require("./other_clauses");
|
|
33
|
+
var rename_table_1 = require("./rename_table");
|
|
32
34
|
var prepared_statements_1 = require("./prepared_statements");
|
|
33
35
|
var procedural_language_1 = require("./procedural_language");
|
|
34
36
|
var procedure_1 = require("./procedure");
|
|
@@ -45,4 +47,4 @@ var bigquery_1 = require("./dialects/bigquery");
|
|
|
45
47
|
var mysql_1 = require("./dialects/mysql");
|
|
46
48
|
var sqlite_1 = require("./dialects/sqlite");
|
|
47
49
|
var postgresql_1 = require("./dialects/postgresql");
|
|
48
|
-
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({}, alias_1.aliasMap), 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), prepared_statements_1.preparedStatementsMap), proc_clause_1.procClauseMap), procedural_language_1.proceduralLanguageMap), procedure_1.procedureMap), program_1.programMap), schema_1.schemaMap), select_1.selectMap), 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);
|
|
50
|
+
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({}, alias_1.aliasMap), 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), 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);
|
package/dist/syntax/trigger.js
CHANGED
|
@@ -22,7 +22,7 @@ exports.triggerMap = {
|
|
|
22
22
|
"name",
|
|
23
23
|
]),
|
|
24
24
|
print("event")
|
|
25
|
-
],
|
|
25
|
+
], print.spaced(["forEachRowKw"]), true), print(["condition"]), true), [
|
|
26
26
|
print("body"),
|
|
27
27
|
], false));
|
|
28
28
|
},
|
package/dist/syntax/truncate.js
CHANGED
|
@@ -1,6 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.truncateMap = void 0;
|
|
4
|
+
var print_utils_1 = require("../print_utils");
|
|
4
5
|
exports.truncateMap = {
|
|
5
|
-
truncate_stmt: function (print) {
|
|
6
|
+
truncate_stmt: function (print) {
|
|
7
|
+
return (0, print_utils_1.group)([
|
|
8
|
+
print.spaced(["truncateKw", "tableKw"]),
|
|
9
|
+
(0, print_utils_1.indent)([
|
|
10
|
+
print_utils_1.line,
|
|
11
|
+
print.separated(print_utils_1.line, [
|
|
12
|
+
"tables",
|
|
13
|
+
"restartOrContinueKw",
|
|
14
|
+
"cascadeOrRestrictKw",
|
|
15
|
+
]),
|
|
16
|
+
]),
|
|
17
|
+
]);
|
|
18
|
+
},
|
|
6
19
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "prettier-plugin-sql-cst",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.2",
|
|
4
4
|
"description": "Prettier plugin for SQL",
|
|
5
5
|
"author": "Rene Saarsoo <nene@triin.net>",
|
|
6
6
|
"license": "GPL-3.0-or-later",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
],
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"prettier": "^3.0.3",
|
|
35
|
-
"sql-parser-cst": "^0.
|
|
35
|
+
"sql-parser-cst": "^0.22.1"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@types/jest": "^29.2.5",
|