JSPM

  • Created
  • Published
  • Downloads 1519385
  • Score
    100M100P100Q204226F
  • License MIT

Formats whitespaces in a SQL query to make it more readable

Package Exports

  • sql-formatter

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (sql-formatter) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

SQL Formatter

Build Status Coverage Status

SQL Formatter is a whitespace formatter for different query languages.

See the demo.

Installation

To install the newest version from NPM:

npm install --save sql-formatter

The SQL Formatter source code is written in ES2015 but we precompile both CommonJS and UMD builds to ES5 so they work in any modern browser.

If you don't use a module bundler then you can drop a file from /dist directory as a <script> tag on the page. The UMD builds make SQL Formatter available as a window.sqlFormatter global variable.

Example usage

First we need to import our CommonJS module and then we can use it for formatting standard SQL query.

import sqlFormatter from "sql-formatter";

const formattedStandardSql = sqlFormatter.format("sql", "SELECT * FROM table1");

The value of formattedStandardSql will look like this:

SELECT
  *
FROM
  table1

Supported languages

Standard SQL

sqlFormatter.format("sql", "SELECT * FROM table1 WHERE foo = bar");

N1QL

sqlFormatter.format("n1ql", "SELECT fname, email FROM tutorial USE KEYS ['dave', 'ian'];");

Contribute

TODO

Influence

SQL Formatter core logic is influenced by a PHP version of SQL Formatter by Jeremy Dorn.

License

MIT