SQL Formatter
Forked from zeroturnaround/sql-formatter but with improvements and ported Typescript.
SQL Formatter is a JavaScript library for pretty-printing SQL queries.
It started as a port of a PHP Library, but has since considerably diverged.
SQL formatter supports the following dialects:
It does not support:
- Stored procedures.
- Changing of the delimiter type to something else than
;
.
Install
Get the latest version from NPM:
npm install @hokaccha/sql-formatter
Usage as library
import { format } from "sql-formatter";
console.log(format("SELECT * FROM tbl"));
This will output:
SELECT
*
FROM
tbl
You can also pass in configuration options:
format("SELECT * FROM tbl", {
language: "spark",
indent: " ",
keywordCase: "upper",
linesBetweenQueries: 2,
});
Placeholders replacement
format("SELECT * FROM tbl WHERE foo = @foo", {
params: {foo: "'bar'"}
}));
format("SELECT * FROM tbl WHERE foo = ?", {
params: ["'bar'"]
}));
Both result in:
SELECT
*
FROM
tbl
WHERE
foo = 'bar'
License
MIT