Skip to content

xianyulli/sql-formatter-plus

 
 

Repository files navigation

@tencent/flink-sql-format

A fork of SQL Formatter with some extra bug fixes and features.

Install

Get the latest version from NPM:

npm install @tencent/flink-sql-format

Usage

import sqlFormatter from '@tencent/flink-sql-format';

console.log(sqlFormatter.format('SELECT * FROM table1'));

This will output:

SELECT
  *
FROM
  table1

You can also pass in configuration options:

sqlFormatter.format('SELECT *', {
  language: 'n1ql', // Defaults to "sql"
  indent: '    ', // Defaults to two spaces,
  uppercase: true, // Defaults to false
  linesBetweenQueries: 2 // Defaults to 1
});

Placeholders replacement

// Named placeholders
sqlFormatter.format("SELECT * FROM tbl WHERE foo = @foo", {
  params: {foo: "'bar'"}
}));

// Indexed placeholders
sqlFormatter.format("SELECT * FROM tbl WHERE foo = ?", {
  params: ["'bar'"]
}));

Both result in:

SELECT
  *
FROM
  tbl
WHERE
  foo = 'bar'

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.

Contributing

# run linter and tests
npm run check

...and you're ready to poke us with a pull request.

License

MIT

About

A whitespace formatter for different query languages

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 95.4%
  • HTML 4.6%