Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

prettier-plugin-sql-cst

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

prettier-plugin-sql-cst - npm Package Compare versions

Comparing version 0.1.1 to 0.2.0

dist/syntax/alter_table.js

42

dist/index.js

@@ -7,4 +7,3 @@ "use strict";

var utils_1 = require("./utils");
var comments_1 = require("./comments");
var aliasAs_1 = require("./aliasAs");
var transformCst_1 = require("./transform/transformCst");
var options_1 = require("./options");

@@ -14,21 +13,28 @@ Object.defineProperty(exports, "options", { enumerable: true, get: function () { return options_1.options; } });

{
extensions: [".sql"],
name: "SQL",
parsers: ["sql-parser-cst"],
extensions: [".sql", ".sqlite"],
name: "SQLite SQL",
parsers: ["sql-parser-cst-sqlite"],
},
{
extensions: [".bigquery"],
name: "BigQuery SQL",
parsers: ["sql-parser-cst-bigquery"],
},
];
var createParser = function (dialect) { return ({
parse: function (text, parsers, options) {
return (0, transformCst_1.transformCst)((0, sql_parser_cst_1.parse)(text, {
dialect: dialect,
includeRange: true,
includeComments: true,
filename: options.filepath,
}), options);
},
astFormat: "sql-cst",
locStart: function (node) { var _a; return (_a = node.range) === null || _a === void 0 ? void 0 : _a[0]; },
locEnd: function (node) { var _a; return (_a = node.range) === null || _a === void 0 ? void 0 : _a[1]; },
}); };
exports.parsers = {
"sql-parser-cst": {
parse: function (text, parsers, options) {
return (0, comments_1.moveCommentsToRoot)((0, aliasAs_1.processAliasAs)((0, sql_parser_cst_1.parse)(text, {
dialect: "sqlite",
includeRange: true,
includeComments: true,
filename: options.filepath,
}), options));
},
astFormat: "sql-cst",
locStart: function (node) { var _a; return (_a = node.range) === null || _a === void 0 ? void 0 : _a[0]; },
locEnd: function (node) { var _a; return (_a = node.range) === null || _a === void 0 ? void 0 : _a[1]; },
},
"sql-parser-cst-sqlite": createParser("sqlite"),
"sql-parser-cst-bigquery": createParser("bigquery"),
};

@@ -35,0 +41,0 @@ exports.printers = {

@@ -5,3 +5,3 @@ "use strict";

var utils_1 = require("./utils");
var syntax_1 = require("./syntax");
var transformMap_1 = require("./syntax/transformMap");
var print_utils_1 = require("./print_utils");

@@ -62,3 +62,3 @@ function printSql(path, options, oldPrint) {

}
var fn = syntax_1.transformMap[node.type];
var fn = transformMap_1.transformMap[node.type];
if (!fn) {

@@ -65,0 +65,0 @@ throw new Error("Unexpected node type: ".concat(node.type));

@@ -47,2 +47,3 @@ "use strict";

member_expr: function (print) { return [print("object"), ".", print("property")]; },
bigquery_quoted_member_expr: function (print) { return ["`", print("expr"), "`"]; },
func_call: function (print) {

@@ -49,0 +50,0 @@ var fnCall = print(["name", "args"]);

"use strict";
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
return t;
};
return __assign.apply(this, arguments);
}
return to.concat(ar || Array.prototype.slice.call(from));
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.transformMap = void 0;
var alias_1 = require("./alias");
var base_1 = require("./base");
var constraint_1 = require("./constraint");
var create_table_1 = require("./create_table");
var data_type_1 = require("./data_type");
var delete_1 = require("./delete");
var expr_1 = require("./expr");
var frame_1 = require("./frame");
var insert_1 = require("./insert");
var proc_clause_1 = require("./proc_clause");
var program_1 = require("./program");
var select_1 = require("./select");
var update_1 = require("./update");
exports.transformMap = __assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign({}, alias_1.aliasMap), base_1.baseMap), constraint_1.constraintMap), create_table_1.createTableMap), data_type_1.dataTypeMap), delete_1.deleteMap), expr_1.exprMap), frame_1.frameMap), insert_1.insertMap), proc_clause_1.procClauseMap), program_1.programMap), select_1.selectMap), update_1.updateMap);
exports.indexMap = void 0;
var print_utils_1 = require("../print_utils");
exports.indexMap = {
create_index_stmt: function (print, node) {
return (0, print_utils_1.join)(print_utils_1.hardline, __spreadArray([
print.spaced([
"createKw",
"indexTypeKw",
"indexKw",
"ifNotExistsKw",
"name",
"onKw",
"table",
"columns",
])
], (node.clauses.length > 0 ? [(0, print_utils_1.join)(print_utils_1.hardline, print("clauses"))] : []), true));
},
drop_index_stmt: function (print) {
return print.spaced(["dropKw", "indexKw", "ifExistsKw", "indexes"]);
},
};

@@ -15,3 +15,3 @@ "use strict";

else if (i < all.length - 1 || node.type !== "empty") {
return [";", print_utils_1.hardline, print(childPath)];
return [";", print_utils_1.hardline, print_utils_1.hardline, print(childPath)];
}

@@ -18,0 +18,0 @@ else {

@@ -31,2 +31,4 @@ "use strict";

},
except_columns: function (print) { return print.spaced(["expr", "exceptKw", "columns"]); },
replace_columns: function (print) { return print.spaced(["expr", "replaceKw", "columns"]); },
from_clause: function (print) {

@@ -33,0 +35,0 @@ return (0, print_utils_1.group)([print("fromKw"), (0, print_utils_1.indent)([print_utils_1.line, print("expr")])]);

{
"name": "prettier-plugin-sql-cst",
"version": "0.1.1",
"version": "0.2.0",
"description": "Prettier plugin for SQL",

@@ -5,0 +5,0 @@ "author": "Rene Saarsoo <nene@triin.net>",

@@ -56,9 +56,7 @@ # Prettier plugin SQL-CST [![npm version](https://img.shields.io/npm/v/prettier-plugin-sql-cst)](https://www.npmjs.com/package/prettier-plugin-sql-cst) ![build status](https://github.com/nene/prettier-plugin-sql-cst/actions/workflows/build.yml/badge.svg)

The standard Prettier options apply. There's also one SQL-specific option:
The standard Prettier options [printWidth][], [tabWidth][], [useTabs][] apply.
There are also some SQL-specific options:
| API Option | Default | Description |
| ---------------- | :--------: | ------------------------------------------------------ |
| `printWidth` | `80` | [Same as in Prettier][prettier-print-width] |
| `tabWidth` | `2` | [Same as in Prettier][prettier-tab-width] |
| `useTabs` | `false` | [Same as in Prettier][prettier-use-tabs] |
| `sqlKeywordCase` | `preserve` | Converts SQL keywords to `upper` or `lower` case. |

@@ -69,3 +67,4 @@ | `sqlAliasAs` | `preserve` | Uses AS keyword in aliases either `always` or `never`. |

Currently this plugin only supports subset of **SQLite** syntax.
Currently this plugin supports most of **SQLite** syntax.
(It also supports some **BigQuery**, but only the syntax that's subset of SQLite.)
Formatting of the following SQL statements is fully implemented:

@@ -77,3 +76,5 @@

- DELETE
- CREATE TABLE
- CREATE / DROP / ALTER TABLE
- CREATE / DROP VIEW
- CREATE / DROP INDEX

@@ -97,6 +98,6 @@ Unlike Prettier for JavaScript, this plugin currently preserves all the syntax elements.

[prettier]: https://prettier.io/
[prettier-print-width]: https://prettier.io/docs/en/options.html#print-width
[prettier-tab-width]: https://prettier.io/docs/en/options.html#tab-width
[prettier-use-tabs]: https://prettier.io/docs/en/options.html#tabs
[printWidth]: https://prettier.io/docs/en/options.html#print-width
[tabWidth]: https://prettier.io/docs/en/options.html#tab-width
[useTabs]: https://prettier.io/docs/en/options.html#tabs
[sql-parser-cst]: https://github.com/nene/sql-parser-cst
[wadler-prettier]: http://homepages.inf.ed.ac.uk/wadler/papers/prettier/prettier.pdf
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc