1.0.16 • Published 7 days ago

bravo-formatter v1.0.16

Weekly downloads
-
License
MIT
Repository
-
Last release
7 days ago

SQL Formatter

based on SQL-Formatter, Bravo Formatter is a JavaScript library for pretty-printing SQL queries. It supports various SQL dialects: Hive、Clickhouse.

基于 SQL-Formatter 开发,目前长期维护 Hive、Clickhouse 语法,若不明确具体的语法可以不配置 language 参数。会采用兼容语法进行格式化

Install

Get the latest version from NPM:

npm install bravo-formatter

Also available with yarn:

yarn add bravo-formatter

Usage as library

import { format } from 'sql-formatter';

console.log(format('SELECT * FROM tbl'));

This will output:

SELECT
  *
FROM
  tbl

You can also pass in configuration options:

format('SELECT id, case when name = '1' then 1 else 2 end FROM tbl', {
  language: 'hive',
  tabWidth: 2,
  indentStyle: 'tabularLeft',
  tabulateAlias: true,
  keywordCase: 'upper',
});
SELECT    id,
          CASE
              WHEN name = '1' THEN 1
              WHEN name = '2' THEN 2
              ELSE 3
          END
FROM      tbl;

Configuration options

  • language the SQL dialect to use,格式化的语言.
  • tabWidth amount of indentation to use,配置缩进的空格数.
  • useTabs to use tabs for indentation, 使用 Tab 作为缩进.
  • keywordCase uppercases or lowercases keywords,关键词是否改为大写、小写.
  • indentStyle defines overall indentation style,格式化风格.
  • logicalOperatorNewline newline before or after boolean operator (AND, OR, XOR),连接词(AND、OR、XOR)是否换行展示.
  • tabulateAlias aligns column aliases vertically,是否开启别名对齐.
  • expressionWidth maximum number of characters in parenthesized expressions to be kept on single line,括号内表达式最大长度,超出则换行展示.
  • linesBetweenQueries how many newlines to insert between queries,多段 SQL 之间的空行数,默认为 1.
  • denseOperators packs operators densely without spaces,运算符中间是否保留空格,默认保留.
  • newlineBeforeSemicolon places semicolon on separate line,SQL 结尾分号是否启用新行展示.

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.

提供 commonjs 的接入方式,提取 dist 目录下的 sql-formatter.min.cjs 文件,通过<script src="XXX/sql-formatter.min.cjs">引入。window.sqlFormatter方式调用

1.0.16

7 days ago

1.0.15

8 days ago

1.0.14

29 days ago

1.0.13

2 months ago

1.0.12

2 months ago

1.0.11

4 months ago

1.0.2

9 months ago

1.0.1

9 months ago

0.0.20

9 months ago

0.0.21

9 months ago

0.0.22

9 months ago

0.0.23

9 months ago

0.0.24

9 months ago

0.0.25

9 months ago

1.0.9

7 months ago

1.0.8

7 months ago

1.0.7

7 months ago

1.0.6

8 months ago

1.0.5

8 months ago

1.0.4

8 months ago

1.0.3

8 months ago

0.0.15

10 months ago

0.0.16

10 months ago

0.0.17

10 months ago

0.0.18

9 months ago

0.0.19

9 months ago

1.0.10

7 months ago

0.0.14

11 months ago

0.0.11

11 months ago

0.0.12

11 months ago

0.0.13

11 months ago

0.0.10

1 year ago

0.0.9

1 year ago

0.0.8

1 year ago

0.0.7

1 year ago

0.0.6

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

2 years ago

1.0.0

2 years ago