$ show darold/pgFormatter
pgFormatter is a mature, widely-used SQL formatter specifically designed for PostgreSQL. It operates as a command-line tool, a CGI web service, and a library, providing consistent formatting of SQL statements according to configurable rules (keyword case, indentation, comma placement, line width, etc.). The core formatting logic resides in the self-contained Perl module `lib/pgFormatter/Beautify.pm`, which parses SQL tokens and reformats them based on a comprehensive set of rules. The project includes a vast regression test suite derived from PostgreSQL's own regression tests, ensuring high syntax coverage and correctness across DDL, DML, procedural code, and edge cases. It also offers pre-commit hook integration and Docker deployment for CI/CD pipelines. The codebase is well-structured, actively maintained, and demonstrates strong engineering practices with isolated modules and extensive test coverage.
The LLM identified 5 files worth highlighting for reuse:
The core formatting engine that tokenizes and reformats SQL statements. It is a self-contained Perl module implementing a tokenizer and a state-machine-based formatter that respects PostgreSQL syntax, keywords, operators, and comments. It handles complex constructs like CTEs, window functions, subqueries, and procedural code. The module is decoupled from I/O and can be reused in any Perl project requiring SQL formatting or analysis.
A reusable CLI module that wraps the formatter, handling argument parsing (via Getopt::Long), file input/output, and pipeline support. It is cleanly separated from formatting logic, making it a good pattern for any Perl tool that needs a robust command-line interface with options like file list, stdin, output file, and formatting flags.
Provides a CGI interface to the formatter, accepting SQL via POST or GET parameters and returning formatted output. It handles error responses and content-type negotiation. This module is a reusable pattern for wrapping a command-line tool as a lightweight web service, suitable for embedding in internal dashboards or textarea-based tools.
The main executable script that bootstraps the formatter. It is a well-structured Perl script that initializes the library, delegates to CLI or CGI modules based on invocation context, and sets up signal handling. It serves as a canonical example of a modular command-line tool entry point in Perl.
A declarative pre-commit hook configuration that integrates pgFormatter into git workflows. This is a reusable pattern for any formatter/linter, demonstrating how to expose a tool as a pre-commit hook with file filtering and in-place modification.