Formats whitespace in a SQL query to make it more readable
npm install sql-formatter-plusuppercase config option
linesBetweenQueries config option
shell
npm install sql-formatter
`
Usage
`javascript
import sqlFormatter from 'sql-formatter-plus';
console.log(sqlFormatter.format('SELECT * FROM table1'));
`
This will output:
`sql
SELECT
*
FROM
table1
`
You can also pass in configuration options:
`javascript
sqlFormatter.format('SELECT *', {
language: 'n1ql', // Defaults to "sql"
indent: ' ', // Defaults to two spaces,
uppercase: true, // Defaults to false
linesBetweenQueries: 2 // Defaults to 1
});
`
Currently just four SQL dialects are supported:
- sql - [Standard SQL][]
- n1ql - [Couchbase N1QL][]
- db2 - [IBM DB2][]
- pl/sql - [Oracle PL/SQL][]
$3
`javascript
// Named placeholders
sqlFormatter.format("SELECT * FROM tbl WHERE foo = @foo", {
params: {foo: "'bar'"}
}));
// Indexed placeholders
sqlFormatter.format("SELECT * FROM tbl WHERE foo = ?", {
params: ["'bar'"]
}));
`
Both result in:
`sql
SELECT
*
FROM
tbl
WHERE
foo = 'bar'
`
Usage without NPM
If you don't use a module bundler, clone the repository, run npm install and grab a file from /dist directory to use inside a