JSPM

snowsql-formatter

1.1.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1045
  • Score
    100M100P100Q105579F
  • License MIT

Formats whitespace in a SQL query to make it more readable

Package Exports

  • snowsql-formatter

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (snowsql-formatter) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

SnowSQL Formatter

A fork of sql-formatter-plus with some Snowflake specific syntaxes.

New Features:

  • Recognize JSON references

SQL Formatter is a JavaScript library for pretty-printing SQL queries. It started as a port of a PHP Library, but has since considerably diverged. It supports Standard SQL, Couchbase N1QL, IBM DB2 and Oracle PL/SQL dialects.

Try the demo of the source of this fork.

Install

Get the latest version from NPM:

npm install snowsql-formatter

Usage

import sqlFormatter from 'snowsql-formatter';

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
});

Currently just four SQL dialects are supported:

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.

Next Steps

  • Add a snowsql dialect
  • Add support for SnowSQL specific keywords and constructs

License

MIT