1.0.16 • Published 1 year ago

bravo-formatter v1.0.16

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year 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

1 year ago

1.0.15

1 year ago

1.0.14

1 year ago

1.0.13

1 year ago

1.0.12

1 year ago

1.0.11

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

0.0.20

2 years ago

0.0.21

2 years ago

0.0.22

2 years ago

0.0.23

2 years ago

0.0.24

2 years ago

0.0.25

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

0.0.15

2 years ago

0.0.16

2 years ago

0.0.17

2 years ago

0.0.18

2 years ago

0.0.19

2 years ago

1.0.10

2 years ago

0.0.14

2 years ago

0.0.11

2 years ago

0.0.12

2 years ago

0.0.13

2 years ago

0.0.10

2 years ago

0.0.9

2 years ago

0.0.8

2 years ago

0.0.7

3 years ago

0.0.6

3 years ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago

1.0.0

3 years ago