npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

bravo-formatter

v1.0.16

Published

Format whitespace in a SQL query to make it more readable

Downloads

343

Readme

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方式调用