Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

sql-formatter-plus

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sql-formatter-plus

Formats whitespaces in a SQL query to make it more readable

  • 1.1.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
11K
decreased by-8.8%
Maintainers
1
Weekly downloads
 
Created
Source

SQL Formatter Plus

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

Fixes:

  • Fixed formatting issue with unicode characters
  • Fixed comment formatting for non-unix line endings
  • Fixed null reference on input tokenization

New Features:

  • Convert keywords to uppercase with the uppercase config option

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.

Install

Get the latest version from NPM:

npm install sql-formatter

Usage

import sqlFormatter from 'sql-formatter-plus';

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

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.

License

MIT

Keywords

FAQs

Package last updated on 21 Oct 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc