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.
Key facts
Objective fields from the source. Values we can't verify are shown as “Unknown” rather than guessed.
| Field | Value |
|---|---|
| Repository | sql-formatter-org/sql-formatter |
| Owner | sql-formatter-org |
| Primary language | TypeScript |
| License | MIT — OSI-approved |
| Stars | 2.9k |
| Forks | 449 |
| Open issues | 76 |
| Latest release | v15.8.2 (2026-06-21) |
| Last updated | 2026-06-30 |
| Source | https://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.
Get the sql-formatter source
Clone the repository and explore it locally.
git clone https://github.com/sql-formatter-org/sql-formatter.gitcd sql-formatter# follow the project's README for install & configurationNeed it deployed, integrated, or customized instead? DEV.co ships production installs.
Best use cases
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.
| Signal | Assessment |
|---|---|
| Maintenance | Active |
| Documentation | Strong |
| License clarity | Clear |
| Deployment complexity | Low |
| DEV.co fit | Strong |
| Assessment confidence | High |
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.
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.coRelated 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 ...'?
Can I use this in a browser without a build step?
Does this support stored procedures?
How do I exclude sections of SQL from formatting?
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.