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

@hokaccha/sql-formatter

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@hokaccha/sql-formatter

Format whitespace in a SQL query to make it more readable

  • 1.4.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

SQL Formatter

Forked from zeroturnaround/sql-formatter but with improvements and ported Typescript.

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.

SQL formatter supports the following dialects:

It does not support:

  • Stored procedures.
  • Changing of the delimiter type to something else than ;.

Install

Get the latest version from NPM:

npm install @hokaccha/sql-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 * FROM tbl", {
  language: "spark",        // Defaults to "sql" (see the above list of supported dialects)
  indent: "    ",           // Defaults to two spaces
  keywordCase: "upper",     // Defaults to preserve ("upper" | "lower" | "preserve")
  linesBetweenQueries: 2,   // Defaults to 1
});

Placeholders replacement

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

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

Both result in:

SELECT
  *
FROM
  tbl
WHERE
  foo = 'bar'

License

MIT

Keywords

FAQs

Package last updated on 19 Apr 2022

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