├── .babelrc
├── .editorconfig
├── .eslintignore
├── .eslintrc
├── .gitattributes
├── .gitignore
├── .prettierignore
├── .prettierrc
├── .travis.yml
├── LICENSE
├── README.md
├── index.html
├── package-lock.json
├── package.json
├── src
├── core
│ ├── Formatter.js
│ ├── Indentation.js
│ ├── InlineBlock.js
│ ├── Params.js
│ ├── Tokenizer.js
│ └── tokenTypes.js
├── languages
│ ├── Db2Formatter.js
│ ├── N1qlFormatter.js
│ ├── PlSqlFormatter.js
│ └── StandardSqlFormatter.js
└── sqlFormatter.js
├── test
├── Db2FormatterTest.js
├── N1qlFormatterTest.js
├── PlSqlFormatterTest.js
├── StandardSqlFormatterTest.js
├── behavesLikeSqlFormatter.js
└── sqlFormatterTest.js
└── webpack.config.js
/.babelrc:
--------------------------------------------------------------------------------
1 | {
2 | "presets": ["@babel/env"],
3 | "plugins": ["add-module-exports"]
4 | }
5 |
--------------------------------------------------------------------------------
/.editorconfig:
--------------------------------------------------------------------------------
1 | root = true
2 |
3 | [*]
4 | charset = utf-8
5 | trim_trailing_whitespace = true
6 | insert_final_newline = true
7 | indent_style = space
8 | indent_size = 2
9 |
10 | [*.md]
11 | trim_trailing_whitespace = false
12 |
--------------------------------------------------------------------------------
/.eslintignore:
--------------------------------------------------------------------------------
1 | /lib
2 | /dist
3 | /coverage
4 |
--------------------------------------------------------------------------------
/.eslintrc:
--------------------------------------------------------------------------------
1 | {
2 | "extends": ["adpyke-es6", "prettier"],
3 | "parserOptions": {
4 | "sourceType": "module"
5 | },
6 | "env": {
7 | "jest": true,
8 | "browser": false,
9 | "node": true
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text auto
3 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | dist
2 | lib
3 | node_modules
4 | .DS_Store
5 | coverage
6 |
--------------------------------------------------------------------------------
/.prettierignore:
--------------------------------------------------------------------------------
1 | /lib
2 | /dist
3 | /coverage
4 |
--------------------------------------------------------------------------------
/.prettierrc:
--------------------------------------------------------------------------------
1 | {
2 | "singleQuote": true,
3 | "printWidth": 100,
4 | "tabWidth": 2
5 | }
6 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: node_js
2 | node_js: node
3 |
4 | install:
5 | - npm install
6 | - npm install coveralls
7 | script:
8 | - npm run check
9 | - npm run build
10 | after_script:
11 | - cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js
12 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2016-present ZeroTurnaround LLC
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # SQL Formatter Plus
2 |
3 | A fork of [SQL Formatter](https://github.com/zeroturnaround/sql-formatter) with some extra bug fixes and features.
4 |
5 | Fixes:
6 |
7 | - Fixed formatting issue with unicode characters
8 | - Fixed comment formatting for non-unix line endings
9 | - Fixed null reference on input tokenization
10 | - Fixed indentation of multiple statements
11 |
12 | New Features:
13 |
14 | - Convert keywords to uppercase with the `uppercase` config option
15 | - Configurable number of line breaks between queries with the `linesBetweenQueries` config option
16 |
17 | **SQL Formatter** is a JavaScript library for pretty-printing SQL queries.
18 | It started as a port of a [PHP Library][], but has since considerably diverged.
19 | It supports [Standard SQL][], [Couchbase N1QL][], [IBM DB2][] and [Oracle PL/SQL][] dialects.
20 |
21 | [Try the demo.](https://kufii.github.io/sql-formatter-plus//)
22 |
23 | ## Install
24 |
25 | Get the latest version from NPM:
26 |
27 | ```shell
28 | npm install sql-formatter
29 | ```
30 |
31 | ## Usage
32 |
33 | ```javascript
34 | import sqlFormatter from 'sql-formatter-plus';
35 |
36 | console.log(sqlFormatter.format('SELECT * FROM table1'));
37 | ```
38 |
39 | This will output:
40 |
41 | ```sql
42 | SELECT
43 | *
44 | FROM
45 | table1
46 | ```
47 |
48 | You can also pass in configuration options:
49 |
50 | ```javascript
51 | sqlFormatter.format('SELECT *', {
52 | language: 'n1ql', // Defaults to "sql"
53 | indent: ' ', // Defaults to two spaces,
54 | uppercase: true, // Defaults to false
55 | linesBetweenQueries: 2 // Defaults to 1
56 | });
57 | ```
58 |
59 | Currently just four SQL dialects are supported:
60 |
61 | - **sql** - [Standard SQL][]
62 | - **n1ql** - [Couchbase N1QL][]
63 | - **db2** - [IBM DB2][]
64 | - **pl/sql** - [Oracle PL/SQL][]
65 |
66 | ### Placeholders replacement
67 |
68 | ```javascript
69 | // Named placeholders
70 | sqlFormatter.format("SELECT * FROM tbl WHERE foo = @foo", {
71 | params: {foo: "'bar'"}
72 | }));
73 |
74 | // Indexed placeholders
75 | sqlFormatter.format("SELECT * FROM tbl WHERE foo = ?", {
76 | params: ["'bar'"]
77 | }));
78 | ```
79 |
80 | Both result in:
81 |
82 | ```sql
83 | SELECT
84 | *
85 | FROM
86 | tbl
87 | WHERE
88 | foo = 'bar'
89 | ```
90 |
91 | ## Usage without NPM
92 |
93 | 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 `
133 |
154 |