Registry / database / cl-sql-formatter

cl-sql-formatter

JSON →
library4.0.11jsnpmunverified

SQL Formatter is a JavaScript library for pretty-printing SQL queries. It supports many dialects: Standard SQL, MariaDB, MySQL, PostgreSQL, DB2, PL/SQL (Oracle), N1QL (Couchbase), Redshift (Amazon), Spark, and T-SQL. Version 4.0.11 is the latest stable release. It is actively maintained, with releases on npm. Key differentiators: broad dialect support, placeholders replacement, and a CLI tool. The library ships TypeScript types and is ESM-first. It does not support stored procedures or custom delimiters.

npm install cl-sql-formatter
INSTALL
IMPORT
SIG · CL-SQL-FORMATTER
C
cl-sql-formatter
databasejavascriptv4.0.11
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

format
import { format } from 'sql-formatter'
const format = require('sql-formatter').format
ESM-only package; require() is not supported. Use dynamic import if in CJS.
Formatter
import { Formatter } from 'sql-formatter'
import Formatter from 'sql-formatter'
Formatter is a named export, not default.
FormatOptions
import type { FormatOptions } from 'sql-formatter'
import { FormatOptions } from 'sql-formatter'
Use import type for TypeScript type imports to avoid runtime overhead.

Formats a SQL query with PostgreSQL dialect, 4-space indent, uppercase keywords, placeholders replacement, and double line spacing.

import { format } from 'sql-formatter'; const sql = 'SELECT a, b, c FROM tbl WHERE foo = @foo'; const formatted = format(sql, { language: 'postgresql', indent: ' ', uppercase: true, linesBetweenQueries: 2, params: { foo: "'bar'" }, }); console.log(formatted); // Output: // SELECT // a, // b, // c // FROM // tbl // WHERE // foo = 'bar'
Debug
Known issues
breakingv4.0.0 changed default casing to lowercase (uppercase: false). Previously it was uppercase. Use uppercase: true to restore old behavior.
fix
Add `uppercase: true` to options object.
affects: >=4.0.0
breakingv4.0.0 dropped support for CommonJS via require(). The package is now ESM-only.
fix
Use dynamic import: const { format } = await import('sql-formatter').
affects: >=4.0.0
breakingv4.0.0 removed the default export. Only named exports are available.
fix
Import as named: import { format } from 'sql-formatter'.
affects: >=4.0.0
gotchaParameter placeholders with @ (named) or ? (indexed) are only replaced when the params option is provided. Otherwise, they remain as-is.
fix
Always pass params if you expect placeholder replacement.
affects: *
gotchaThe library does not validate SQL syntax; malformed queries may produce unexpected formatting or no changes.
fix
Ensure input SQL is syntactically correct before formatting.
affects: *
Errors
Common errors & fixes
Error [ERR_REQUIRE_ESM]: require() of ES Module
Using require() to import an ESM-only package.
fix
Use import or dynamic import: const { format } = await import('sql-formatter')
TypeError: (0 , _sqlFormatter.format) is not a function
Default import used incorrectly; import { format } instead of import format.
fix
Correct import: import { format } from 'sql-formatter'
Module not found: Can't resolve 'sql-formatter' in '/path/to/project'
Package not installed or import path incorrect.
fix
Run npm install sql-formatter
Upgrade
Version history
4.0.11latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
10 hits · last 30 days
node
8
OpenAI (training)
1
Resources
cl-sql-formatter — npm install cl-sql-formatter · libregistry