SQL Formatter Plus
A fork of SQL Formatter with some extra bug fixes and features.
Fixes:
- Fixed formatting issue with unicode characters
- Fixed comment formatting for non-unix line endings
- Fixed null reference on input tokenization
- Fixed indentation of multiple statements
New Features:
- Convert keywords to uppercase with the
uppercase
config option - Configurable number of line breaks between queries with the
linesBetweenQueries
config option
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. It supports Standard SQL, Couchbase N1QL, IBM DB2 and Oracle PL/SQL dialects.
Install
Get the latest version from NPM:
npm install sql-formatter
Usage
; console;
This will output:
SELECT *FROM table1
You can also pass in configuration options:
sqlFormatter;
Currently just four SQL dialects are supported:
- sql - Standard SQL
- n1ql - Couchbase N1QL
- db2 - IBM DB2
- pl/sql - Oracle PL/SQL
Placeholders replacement
// Named placeholderssqlFormatter); // Indexed placeholderssqlFormatter);
Both result in:
SELECT *FROM tblWHERE 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 <script>
tag.
This makes SQL Formatter available as a global variable window.sqlFormatter
.
Contributing
# run linter and tests npm run check
...and you're ready to poke us with a pull request.