Socket
Socket
Sign inDemoInstall

@sqltools/formatter

Package Overview
Dependencies
0
Maintainers
2
Versions
13
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sqltools/formatter

Formats SQL queries. Part of SQLTools


Version published
Maintainers
2
Weekly downloads
1,410,465
decreased by-6.33%

Weekly downloads

Package description

What is @sqltools/formatter?

The @sqltools/formatter package is a library for formatting SQL queries. It provides a way to beautify SQL code, making it more readable and maintainable. It supports various SQL dialects and allows customization of the formatting options.

What are @sqltools/formatter's main functionalities?

SQL Formatting

This feature allows you to format SQL queries. The code sample demonstrates how to format a simple SQL SELECT query using the package.

const { format } = require('@sqltools/formatter');
const query = 'SELECT * FROM table WHERE id = 1';
const formattedQuery = format(query, { language: 'sql' });
console.log(formattedQuery);

Customizing Formatting Options

This feature allows you to customize the formatting options such as indentation, case, and line breaks. The code sample shows how to format a query with custom options for indentation and uppercase keywords.

const { format } = require('@sqltools/formatter');
const options = {
  language: 'sql',
  indent: '    ',
  uppercase: true
};
const query = 'select * from table where id = 1';
const formattedQuery = format(query, options);
console.log(formattedQuery);

Other packages similar to @sqltools/formatter

Readme

Source

SQLTools Formatter

GitHub

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

This package is part of vscode-sqltools extension.

→ Try it online using our playground.

Install

Get the latest version from NPM/Yarn:

npm install @sqltools/formatter
#
yarn add @sqltools/formatter

Usage

import sqlFormatter from '@sqltools/formatter';

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

Will output:

SELECT *
FROM table1

You can also pass in configuration options:

sqlFormatter.format('SELECT *', {
  language: 'sql',
  indent: '\t', // Defaults to two spaces
});

Options

optiondescriptiontypedefault
languageQuery language, default is Standard SQLsql, n1ql, db2, pl/sqlsql
indentCharacters used for indentationstring (2 spaces)
reservedWordCaseHow to change the case of reserved wordsupper, lower, nullnull (no change)
linesBetweenQueriesHow many line breaks between queriesnumber or 'preserve'1
paramsCollection of params for placeholder replacementobject for name params, array for indexed placeholders

Changelog

v1.2.4
  • Support PostgreSQL c-style escape strings in formatter. #935 - thanks to @sivaramasubramanian.
  • Support PostgreSQL @@ operator in formatter. #936 - thanks to @remlse.
v1.2.3
v1.2.2
  • Add playground link and options to README.md
  • Emitting declarations files for usage with Typescript.
v1.2.1
  • Fixes JSON operators not inserting spaces. Issue #605
  • Fixes Grant type queries. Issue #460
v1.2.1
  • (Almost) first public version

Keywords

FAQs

Last updated on 16 Oct 2022

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc