Skip to content

Commit

Permalink
Merge branch 'master' of github.com:zeroturnaround/sql-formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
Uku Pattak committed Sep 15, 2016
2 parents 9bea08c + 0f92e37 commit b3509cc
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@ 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. This makes SQL Formatter available as a `window.SqlFormatter` global variable.
If you don't use a module bundler then you can drop a file from `/dist` directory as a `<script>` tag on the page. This makes 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.

```js
import SqlFormatter from "sql-formatter";
import sqlFormatter from "sql-formatter";

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

The value of `formattedStandardSql` will look like this:
Expand All @@ -44,21 +44,26 @@ FROM
### [Standard SQL](https://en.wikipedia.org/wiki/SQL:2011)

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

### [N1QL](http://www.couchbase.com/n1ql)

```js
new SqlFormatter().format("n1ql", "SELECT fname, email FROM tutorial USE KEYS ['dave', 'ian'];");
sqlFormatter.format("SELECT fname, email FROM tutorial USE KEYS ['dave', 'ian'];", {language: "n1ql"});
```

## Optional configuration

Example below has default values.

```js
new SqlFormatter({
const cfg = {
language: "sql" // Specific query language
indent: " " // Value that is used for creating indentation levels
});
};

sqlFormatter.format("SELECT *", cfg);
```

## Contribute
Expand Down

0 comments on commit b3509cc

Please sign in to comment.