prettier-plugin-sql-cst 0.4.0 → 0.5.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 +5 -4
- package/dist/syntax/analyze.js +6 -0
- package/dist/syntax/explain.js +12 -0
- package/dist/syntax/procedural_language.js +12 -0
- package/dist/syntax/sqlite.js +25 -0
- package/dist/syntax/transaction.js +21 -0
- package/dist/syntax/transformMap.js +7 -1
- package/dist/syntax/trigger.js +39 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -61,7 +61,7 @@ Install it as any other Prettier plugin:
|
|
|
61
61
|
npm install --save-dev prettier prettier-plugin-sql-cst
|
|
62
62
|
```
|
|
63
63
|
|
|
64
|
-
Then use it on SQL files
|
|
64
|
+
Then use it on SQL files through Prettier command line tool or Prettier extension
|
|
65
65
|
for your editor of choice.
|
|
66
66
|
|
|
67
67
|
## Choosing an SQL dialect
|
|
@@ -100,8 +100,9 @@ There are also some SQL-specific options:
|
|
|
100
100
|
|
|
101
101
|
## Limitations and development status
|
|
102
102
|
|
|
103
|
-
Currently this plugin supports
|
|
104
|
-
|
|
103
|
+
Currently this plugin supports full **SQLite** syntax.
|
|
104
|
+
It also supports most of the **BigQuery** syntax.
|
|
105
|
+
Specifically the formatting of the following BigQuery SQL statements is fully implemented:
|
|
105
106
|
|
|
106
107
|
- SELECT
|
|
107
108
|
- UPDATE
|
|
@@ -110,7 +111,7 @@ Formatting of the following SQL statements is fully implemented:
|
|
|
110
111
|
- TRUNCATE
|
|
111
112
|
- CREATE / DROP / ALTER TABLE
|
|
112
113
|
- CREATE / DROP VIEW
|
|
113
|
-
-
|
|
114
|
+
- transactions (BEGIN, COMMIT, ROLLBACK)
|
|
114
115
|
|
|
115
116
|
[prettier]: https://prettier.io/
|
|
116
117
|
[printWidth]: https://prettier.io/docs/en/options.html#print-width
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.explainMap = void 0;
|
|
4
|
+
var print_utils_1 = require("../print_utils");
|
|
5
|
+
exports.explainMap = {
|
|
6
|
+
explain_stmt: function (print) {
|
|
7
|
+
return (0, print_utils_1.group)([
|
|
8
|
+
print.spaced(["explainKw", "queryPlanKw"]),
|
|
9
|
+
(0, print_utils_1.indent)([print_utils_1.line, print("statement")]),
|
|
10
|
+
]);
|
|
11
|
+
},
|
|
12
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.proceduralLanguageMap = void 0;
|
|
4
|
+
var print_utils_1 = require("../print_utils");
|
|
5
|
+
exports.proceduralLanguageMap = {
|
|
6
|
+
block_stmt: function (print) { return [
|
|
7
|
+
print("beginKw"),
|
|
8
|
+
(0, print_utils_1.indent)([print_utils_1.hardline, (0, print_utils_1.stripTrailingHardline)(print("program"))]),
|
|
9
|
+
print_utils_1.hardline,
|
|
10
|
+
print("endKw"),
|
|
11
|
+
]; },
|
|
12
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.sqliteMap = void 0;
|
|
4
|
+
var print_utils_1 = require("../print_utils");
|
|
5
|
+
exports.sqliteMap = {
|
|
6
|
+
attach_database_stmt: function (print) {
|
|
7
|
+
return print.spaced(["attachKw", "databaseKw", "file", "asKw", "schema"]);
|
|
8
|
+
},
|
|
9
|
+
detach_database_stmt: function (print) {
|
|
10
|
+
return print.spaced(["detachKw", "databaseKw", "schema"]);
|
|
11
|
+
},
|
|
12
|
+
vacuum_stmt: function (print) {
|
|
13
|
+
return print.spaced(["vacuumKw", "schema", "intoKw", "file"]);
|
|
14
|
+
},
|
|
15
|
+
reindex_stmt: function (print) { return print.spaced(["reindexKw", "table"]); },
|
|
16
|
+
pragma_stmt: function (print) { return print.spaced(["pragmaKw", "pragma"]); },
|
|
17
|
+
pragma_assignment: function (print) { return (0, print_utils_1.join)(" = ", print(["name", "value"])); },
|
|
18
|
+
pragma_func_call: function (print) { return print(["name", "args"]); },
|
|
19
|
+
create_virtual_table_stmt: function (print) {
|
|
20
|
+
return (0, print_utils_1.join)(print_utils_1.hardline, [
|
|
21
|
+
print.spaced(["createVirtualTableKw", "ifNotExistsKw", "name"]),
|
|
22
|
+
print.spaced(["usingKw", "module"]),
|
|
23
|
+
]);
|
|
24
|
+
},
|
|
25
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.transactionMap = void 0;
|
|
4
|
+
exports.transactionMap = {
|
|
5
|
+
start_transaction_stmt: function (print) {
|
|
6
|
+
return print.spaced(["startKw", "behaviorKw", "transactionKw"]);
|
|
7
|
+
},
|
|
8
|
+
commit_transaction_stmt: function (print) {
|
|
9
|
+
return print.spaced(["commitKw", "transactionKw"]);
|
|
10
|
+
},
|
|
11
|
+
rollback_transaction_stmt: function (print) {
|
|
12
|
+
return print.spaced(["rollbackKw", "transactionKw", "savepoint"]);
|
|
13
|
+
},
|
|
14
|
+
rollback_to_savepoint: function (print) {
|
|
15
|
+
return print.spaced(["toKw", "savepointKw", "savepoint"]);
|
|
16
|
+
},
|
|
17
|
+
savepoint_stmt: function (print) { return print.spaced(["savepointKw", "savepoint"]); },
|
|
18
|
+
release_savepoint_stmt: function (print) {
|
|
19
|
+
return print.spaced(["releaseKw", "savepointKw", "savepoint"]);
|
|
20
|
+
},
|
|
21
|
+
};
|
|
@@ -14,6 +14,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
14
14
|
exports.transformMap = void 0;
|
|
15
15
|
var alias_1 = require("./alias");
|
|
16
16
|
var alter_table_1 = require("./alter_table");
|
|
17
|
+
var analyze_1 = require("./analyze");
|
|
17
18
|
var base_1 = require("./base");
|
|
18
19
|
var bigquery_1 = require("./bigquery");
|
|
19
20
|
var constraint_1 = require("./constraint");
|
|
@@ -21,14 +22,19 @@ var create_table_1 = require("./create_table");
|
|
|
21
22
|
var data_type_1 = require("./data_type");
|
|
22
23
|
var delete_1 = require("./delete");
|
|
23
24
|
var drop_table_1 = require("./drop_table");
|
|
25
|
+
var explain_1 = require("./explain");
|
|
24
26
|
var expr_1 = require("./expr");
|
|
25
27
|
var frame_1 = require("./frame");
|
|
26
28
|
var index_1 = require("./index");
|
|
27
29
|
var insert_1 = require("./insert");
|
|
30
|
+
var procedural_language_1 = require("./procedural_language");
|
|
28
31
|
var proc_clause_1 = require("./proc_clause");
|
|
29
32
|
var program_1 = require("./program");
|
|
30
33
|
var select_1 = require("./select");
|
|
34
|
+
var sqlite_1 = require("./sqlite");
|
|
35
|
+
var transaction_1 = require("./transaction");
|
|
36
|
+
var trigger_1 = require("./trigger");
|
|
31
37
|
var truncate_1 = require("./truncate");
|
|
32
38
|
var update_1 = require("./update");
|
|
33
39
|
var view_1 = require("./view");
|
|
34
|
-
exports.transformMap = __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), base_1.baseMap), bigquery_1.bigqueryMap), constraint_1.constraintMap), create_table_1.createTableMap), data_type_1.dataTypeMap), delete_1.deleteMap), drop_table_1.dropTableMap), expr_1.exprMap), frame_1.frameMap), index_1.indexMap), insert_1.insertMap), proc_clause_1.procClauseMap), program_1.programMap), select_1.selectMap), truncate_1.truncateMap), update_1.updateMap), view_1.viewMap);
|
|
40
|
+
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({}, alias_1.aliasMap), alter_table_1.alterTableMap), analyze_1.analyzeMap), base_1.baseMap), bigquery_1.bigqueryMap), constraint_1.constraintMap), create_table_1.createTableMap), data_type_1.dataTypeMap), delete_1.deleteMap), drop_table_1.dropTableMap), explain_1.explainMap), expr_1.exprMap), frame_1.frameMap), index_1.indexMap), insert_1.insertMap), proc_clause_1.procClauseMap), procedural_language_1.proceduralLanguageMap), program_1.programMap), select_1.selectMap), sqlite_1.sqliteMap), transaction_1.transactionMap), trigger_1.triggerMap), truncate_1.truncateMap), update_1.updateMap), view_1.viewMap);
|
|
@@ -0,0 +1,39 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.triggerMap = void 0;
|
|
13
|
+
var print_utils_1 = require("../print_utils");
|
|
14
|
+
exports.triggerMap = {
|
|
15
|
+
create_trigger_stmt: function (print, node) {
|
|
16
|
+
return (0, print_utils_1.join)(print_utils_1.hardline, __spreadArray(__spreadArray(__spreadArray([
|
|
17
|
+
print.spaced([
|
|
18
|
+
"createKw",
|
|
19
|
+
"temporaryKw",
|
|
20
|
+
"triggerKw",
|
|
21
|
+
"ifNotExistsKw",
|
|
22
|
+
"name",
|
|
23
|
+
]),
|
|
24
|
+
(0, print_utils_1.group)([print("event"), (0, print_utils_1.indent)([print_utils_1.line, print.spaced(["onKw", "table"])])])
|
|
25
|
+
], (node.forEachRowKw ? [print.spaced(["forEachRowKw"])] : []), true), (node.condition ? [print(["condition"])] : []), true), [
|
|
26
|
+
print("body"),
|
|
27
|
+
], false));
|
|
28
|
+
},
|
|
29
|
+
trigger_event: function (print, node) { return [
|
|
30
|
+
print.spaced(["timeKw", "eventKw", "ofKw"]),
|
|
31
|
+
node.columns ? (0, print_utils_1.indent)([print_utils_1.line, print("columns")]) : [],
|
|
32
|
+
]; },
|
|
33
|
+
trigger_condition: function (print) {
|
|
34
|
+
return (0, print_utils_1.group)([print("whenKw"), (0, print_utils_1.indent)([print_utils_1.line, print("expr")])]);
|
|
35
|
+
},
|
|
36
|
+
drop_trigger_stmt: function (print) {
|
|
37
|
+
return print.spaced(["dropTriggerKw", "ifExistsKw", "trigger"]);
|
|
38
|
+
},
|
|
39
|
+
};
|