DEV.co
Open-Source Databases · sql-formatter-org

sql-formatter

SQL Formatter is a JavaScript library that pretty-prints SQL queries across 18+ database dialects. It supports formatting via npm library, CLI tool, and editor integrations (VSCode, Vim, Prettier), with configurable indentation, keyword casing, and placeholder replacement.

Source: GitHub — github.com/sql-formatter-org/sql-formatter
2.9k
GitHub stars
449
Forks
TypeScript
Primary language
MIT
License (OSI-approved)

Key facts

Objective fields from the source. Values we can't verify are shown as “Unknown” rather than guessed.

FieldValue
Repositorysql-formatter-org/sql-formatter
Ownersql-formatter-org
Primary languageTypeScript
LicenseMIT — OSI-approved
Stars2.9k
Forks449
Open issues76
Latest releasev15.8.2 (2026-06-21)
Last updated2026-06-30
Sourcehttps://github.com/sql-formatter-org/sql-formatter

What sql-formatter is

TypeScript-based formatter with dialect-specific parsing for BigQuery, PostgreSQL, MySQL, Snowflake, and others. Provides both programmatic API and CLI interface with JSON configuration, disable comments for selective formatting, and prepared statement parameter replacement.

Quickstart

Get the sql-formatter source

Clone the repository and explore it locally.

terminalbash
git clone https://github.com/sql-formatter-org/sql-formatter.gitcd sql-formatter# follow the project's README for install & configuration

Need it deployed, integrated, or customized instead? DEV.co ships production installs.

Best use cases

Multi-dialect SQL formatting in development tools

Teams using multiple database systems (Postgres, MySQL, Snowflake, etc.) can enforce consistent SQL formatting standards across codebases without manual rewrites per dialect.

Build-time SQL code quality gates

Integrate into CI/CD pipelines or pre-commit hooks to automatically format SQL migrations, queries in ORM definitions, or raw SQL files with configurable style rules.

Editor and IDE integration for SQL development

VSCode, Vim, and Prettier plugin availability enables real-time SQL formatting for developers, reducing formatting overhead in code review processes.

Implementation considerations

  • Verify your target SQL dialect is in the supported list (18 dialects documented); unsupported dialects will fail parsing and require dialect parameter specification.
  • For webpack/bundler compatibility, ensure Babel is configured to support ES2022 class properties syntax; older build setups may need `@babel/plugin-proposal-class-properties`.
  • Decide on formatting scope: library integration for programmatic use vs. CLI for batch processing vs. editor plugin for developer experience; each has different setup overhead.
  • When using placeholder replacement (params option), paramTypes must match your prepared statement style (?`, :name, $1, etc.); mismatches will fail silently or format incorrectly.
  • Configure `.sql-formatter.json` in project root for consistent multi-team formatting; autocompletion via JSON Schema is available for VSCode and Zed.

When to avoid it — and what to weigh

  • Stored procedure formatting required — Library explicitly does not support stored procedures; projects relying on PL/SQL, T-SQL procedures, or other procedural SQL blocks will need an alternative.
  • Custom delimiter requirements — If your SQL uses non-semicolon delimiters (rare but possible in some legacy systems), this formatter cannot be configured for that use case.
  • Templating syntax is critical to parsing — While workarounds exist via paramTypes option, complex templating (Jinja, Handlebars) embedded in SQL will require preprocessing; not a first-class feature.
  • Server-side formatting with zero JavaScript footprint — This is a Node.js/JavaScript library; if your architecture cannot introduce a JS runtime dependency, a native binary formatter (Go, Rust) may be better.

License & commercial use

MIT License. Permissive OSI-approved license allowing unrestricted commercial use, modification, and distribution with minimal attribution requirements.

MIT license permits commercial use in proprietary products, SaaS, and internal tools without licensing restrictions. No obligation to release derivative works. Safe for commercial adoption.

DEV.co evaluation signals

Editorial assessment — not user reviews. Directional, with an explicit confidence level.

SignalAssessment
MaintenanceActive
DocumentationStrong
License clarityClear
Deployment complexityLow
DEV.co fitStrong
Assessment confidenceHigh
Security considerations

No hardcoded secrets or authentication logic. Primary consideration: placeholder replacement (params option) must sanitize values externally; library performs string substitution without parameterized query construction—ensure inputs are pre-escaped for target database. No known CVE data provided in source.

Alternatives to consider

Prettier (with @prettier/plugin-sql)

Unified code formatting across JavaScript/TypeScript and SQL; integrates into existing Prettier workflows. Trade-off: fewer SQL dialects, less granular SQL-specific controls.

SQLFluff (Python)

More comprehensive linting + formatting, stored procedure support, native binary distribution. Trade-off: Python dependency, slower for JS-first stacks, steeper configuration learning curve.

Database-native tools (pgFormatter for Postgres, mysql-shell for MySQL)

Authoritative dialect support and zero dependency overhead. Trade-off: single-dialect, no cross-database portability, requires tool-specific CLI knowledge.

Software development agency

Build on sql-formatter with DEV.co software developers

SQL Formatter integrates into your build pipeline, CI/CD, and IDE in minutes. MIT licensed, 2800+ GitHub stars, and actively maintained. Start formatting now.

Talk to DEV.co

Related open-source tools

Surfaced by semantic similarity across the DEV.co open-source index.

Related on DEV.co

Explore the category and the services that help you build with it.

sql-formatter FAQ

Why does my SQL throw 'Parse error: Unexpected ... at line ...'?
Most common cause: SQL dialect not specified. Either pass `{ language: 'mysql' }` (or appropriate dialect) to `format()`, or set dialect in `.sql-formatter.json` config file. Check supported dialects: bigquery, clickhouse, db2, duckdb, hive, mariadb, mysql, n1ql, plsql, postgresql, redshift, singlestoredb, snowflake, spark, sql, sqlite, tidb, transactsql, trino.
Can I use this in a browser without a build step?
Yes. Clone the repo, run `npm install`, and grab a file from `/dist` directory. Use in a `<script>` tag; SQL Formatter becomes available as global `window.sqlFormatter`. For npm: use a bundler (Webpack, Vite, esbuild) or modern import syntax in frameworks.
Does this support stored procedures?
No. Library explicitly does not format stored procedures, PL/SQL blocks, or procedural code. It handles SELECT, INSERT, UPDATE, DELETE, and other SQL statement types only. If procedural code is required, evaluate alternatives like SQLFluff.
How do I exclude sections of SQL from formatting?
Wrap the section with disable/enable comments: `/* sql-formatter-disable */ ... /* sql-formatter-enable */`. Code between these comments is not parsed or formatted, useful for workarounds if certain SQL crashes the formatter.

Custom software development services

DEV.co helps companies turn open-source tools like sql-formatter into production software. Our software development services cover the full lifecycle — architecture, web development, integration, and maintenance — delivered by software developers and web developers who ship. Engage our software development agency to implement or customize it for your open-source databases stack.

Standardize SQL formatting across your team

SQL Formatter integrates into your build pipeline, CI/CD, and IDE in minutes. MIT licensed, 2800+ GitHub stars, and actively maintained. Start formatting now.