Registry / devops / prettier-sql

prettier-sql

JSON →
library5.1.1jsnpmunverified

Prettier SQL v5.1.1 is a JavaScript library for pretty-printing SQL queries. It supports 12 dialects including MySQL, PostgreSQL, BigQuery, and Spark. It started as a port of a PHP library but has diverged considerably. Released regularly via npm, it offers both programmatic and CLI usage. Key differentiators: extensive dialect support, uppercase/lowercase control, placeholder replacement, and zero runtime dependencies. Types are included.

npm install prettier-sql
INSTALL
IMPORT
SIG · PRETTIER-SQL
P
prettier-sql
devopsjavascriptv5.1.1
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 'prettier-sql'
const format = require('prettier-sql').format
ESM-only since v5; CommonJS require() still works but named imports are preferred.
default
import prettierSql from 'prettier-sql'
const prettierSql = require('prettier-sql')
Default export is an object with format method; avoid using default in ESM if you only need format.
formatDialect
import { format } from 'prettier-sql' // use language option in config
import { formatDialect } from 'prettier-sql'
No separate formatDialect export; pass dialect via config.language.

Formats a PostgreSQL query with uppercase keywords, two-space indentation, and one line between queries.

import { format } from 'prettier-sql'; const query = `SELECT id, name, age FROM users WHERE age > 18 ORDER BY name`; const formatted = format(query, { language: 'postgresql', uppercase: true, indent: ' ', linesBetweenQueries: 1, }); console.log(formatted); // Output: // SELECT // id, // name, // age // FROM // users // WHERE // age > 18 // ORDER BY // name
Debug
Known issues
breakingv5 drops support for Node < 14 and removes default export (use named { format }).
fix
Upgrade Node to >=14 and change import from default to named.
affects: >=5.0.0
deprecatedConfig option 'indent_width' is deprecated; use 'indent' with string value instead.
fix
Replace indent_width: 4 with indent: '    '
affects: >=4.0.0
gotchaPlaceholder params must be strings; passing numbers without quotes may cause unexpected replacements.
fix
Wrap numeric placeholders in quotes: params: { foo: "'42'" }
affects: *
gotchaCLI flag --language is case-sensitive; 'sql' works but 'SQL' throws error.
fix
Use lowercase dialect names: sql, mysql, postgresql, etc.
affects: *
gotchaFormatting may remove/reorder columns in SELECT DISTINCT ON (PostgreSQL) incorrectly.
fix
Upgrade to 5.1.0+ for improved handling of DISTINCT ON.
affects: <5.1.0
Errors
Common errors & fixes
SyntaxError: Unexpected token o in JSON at position 1
Passing a JavaScript object instead of JSON string to CLI --config
fix
Use --config config.json (file path) not --config '{ "key": "value" }'
TypeError: format is not a function
Importing default export in ESM instead of named export { format }
fix
Use import { format } from 'prettier-sql'
Error: Unknown dialect 'Standard SQL'
Using non-standard dialect name (e.g., 'Standard SQL' instead of 'sql')
fix
Use valid lowercase dialect: sql, mysql, postgresql, etc.
Module not found: Can't resolve 'prettier-sql' in '/path/to/project'
Package not installed or import path incorrect in bundler
fix
Run npm install prettier-sql and ensure import path matches package name.
Upgrade
Version history
5.1.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources
prettier-sql — npm install prettier-sql · libregistry