Registry / devops / psqlformat

psqlformat

JSON →
library1.33.0jsnpmunverified

PostgreSQL SQL syntax beautifier wrapping the Perl-based pgFormatter. v1.33.0 (released 2023-01-15) provides a CLI and JavaScript API for formatting SQL files, with options for indentation, keyword casing, comma placement, and comment removal. Key differentiators: specifically targets PostgreSQL dialect, supports extensive formatting rules (keywordCase, functionCase, typeCase), and offers both library and CLI usage. Requires Perl runtime. Actively maintained with monthly releases.

devops
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.

Package ships ES module by default (since v1.0.0). CJS require() will work if using bundler that handles ESM, but direct require may fail.

import psqlformat from 'psqlformat'

Named export for formatting a single SQL string. Only available in ESM environment.

import { format } from 'psqlformat'

Reads a file and formats its SQL content. Returns a Promise<string>.

import { formatFromFile } from 'psqlformat'

Demonstrates formatting a SQL string with custom options (2 spaces, lowercase keywords) using the ESM module.

import { format } from 'psqlformat'; const sql = process.env.SQL ?? 'SELECT id, name FROM users WHERE id = 1'; const formatted = await format(sql, { spaces: 2, keywordCase: 'lowercase' }); console.log(formatted); // Output: // select id, // name // from users // where id = 1
Debug
Known footguns
gotchaRequires Perl to be installed and available on PATH. Without Perl, formatting operations will fail with a spawn error.
breakingIn version 1.0.0, the package switched from CommonJS to ESM-only. Calling require('psqlformat') will throw ERR_REQUIRE_ESM.
deprecatedThe CLI option '--commaStart' is deprecated in favor of '--commaEnd' with false. It will be removed in a future version.
gotchaFormatting large files may block the event loop because the underlying Perl process is synchronous. Consider using formatFromFile with streaming for large files.
Upgrade
Version history

Breaking-change detection hasn't run for this library yet.

Audit
Security & dependencies

CVE tracking and dependency tree are planned for a later release.

Agent activity
8 hits · last 30 days
gptbot
3
mj12bot
1
ahrefsbot
1
Resources