Ad

sql-formatter: Formats SQL statements

SqlFormatter automatically formats SQL statements with indentation and syntax highlighting, improving readability and debugging. It addresses the need for a lightweight, reliable SQL formatter without relying on large libraries.
Screenshot of jdorn/sql-formatter homepage

SqlFormatter is a PHP class designed for formatting SQL statements. It automatically adds indentation and line breaks, enhancing readability and making SQL code easier to debug. It addresses the common issue of debugging auto-generated SQL by providing a simple formatting solution. The class is inspired by solutions found on Stack Overflow and aims to be lightweight and easy to integrate.

This project distinguishes itself through its ability to correctly split SQL strings into multiple queries using a tokenization approach, overcoming limitations of regular expression-based splitting. It offers flexibility with options for syntax highlighting only, compression for command-line use, and comment removal. The class is designed to be lightweight and avoids relying on large external dependencies.

  • Formatting: Automatically indents and adds line breaks to SQL statements for enhanced readability.
  • Syntax Highlighting: Provides syntax highlighting for improved code clarity.
  • Compression: Removes comments and compresses whitespace, suitable for command-line use.
  • Comment Removal: Removes comments while preserving original whitespace formatting.
  • Query Splitting: Splits a SQL string into multiple queries, handling complex cases that regular expressions struggle with.
  • Flexibility: Offers options to format, highlight, compress, or remove comments independently.
  • Ease of Use: Provides simple static methods for formatting and highlighting SQL.

The project has been available since 2012 and shows consistent maintenance with recent commits in 2023. The documentation includes clear examples and explanations of the available features. Community engagement is limited but sufficient for basic usage. The stability of the code is indicated by its long history and continued usage.

SqlFormatter is beneficial for developers who work with SQL, especially for debugging, code review, and creating command-line scripts. It simplifies working with SQL by providing a reliable and versatile formatting solution. It offers a significant improvement over manual formatting or cumbersome third-party tools.

Languages:
Summarize:
Share:
Stars
3,856
Forks
184
Issues
36
Created
14 years ago
Commit
3 years ago
License
MIT
Archived
No
Updated 15 days ago

Similar Repositories