2017 © Pedro Peláez
 

library sql-query-formatter

A very lightweight PHP class that reformats unreadable and computer-generated SQL query statements to human-friendly, readable text.

image

nilportugues/sql-query-formatter

A very lightweight PHP class that reformats unreadable and computer-generated SQL query statements to human-friendly, readable text.

  • Sunday, March 6, 2016
  • by nilportugues
  • Repository
  • 3 Watchers
  • 18 Stars
  • 37,942 Installations
  • PHP
  • 9 Dependents
  • 0 Suggesters
  • 6 Forks
  • 2 Open issues
  • 7 Versions
  • 13 % Grown

The README.md

SQL Query Formatter

Build Status Coverage Status Scrutinizer Code Quality SensioLabsInsight Latest Stable Version Total Downloads License Donate, (*1)

A very lightweight PHP class that re-formats unreadable or computer-generated SQL query statements to human-friendly readable text., (*2)

, (*3)

1.Installation

The recommended way to install the SQL Query Formatter is through Composer. Run the following command to install it:, (*4)

php composer.phar require nilportugues/sql-query-formatter

, (*5)

2. Features

Human readable SQL formatting, (*6)

  • Human readable plain text. No colours, no highlighting. Plain text is good enough in most cases.

Data Binding Awareness, (*7)

  • SQL Query Formatter takes data binding seriously.
  • Placeholder syntax such as :variable or ? is taken into account and is preserved when formatting.

, (*8)

3. Usage

Sample code:, (*9)

<?php
use NilPortugues\Sql\QueryFormatter\Formatter;

$query = <<<SQL
SELECT user.user_id, user.username, (SELECT 
role.role_name FROM role WHERE (role.role_id = :v1) 
LIMIT :v2, :v3 ) AS user_role, (SELECT 
role.role_name FROM role WHERE (role.role_id = :v4)
LIMIT :v5, :v6 ) AS role FROM user WHERE (user.user_id = :v7)
SQL;

$formatter = new Formatter();
echo $formatter->format($query);

Real output:, (*10)

SELECT
    user.user_id,
    user.username,
    (
        SELECT
            role.role_name
        FROM
            role
        WHERE
            (role.role_id = :v1)
        LIMIT
            :v2,
            :v3
    ) AS user_role,
    (
        SELECT
            role.role_name
        FROM
            role
        WHERE
            (role.role_id = :v4)
        LIMIT
            :v5,
            :v6
    ) AS role
FROM
    user
WHERE
    (user.user_id = :v7)

, (*11)

4. Fully tested

Testing has been done using PHPUnit and Travis-CI. All code has been tested to be compatible from PHP 5.4 up to PHP 5.6 and HHVM (nightly release)., (*12)

To run the test suite, you need Composer:, (*13)

    php composer.phar install --dev
    bin/phpunit

, (*14)

5. Author

Nil Portugués Calderó, (*15)

, (*16)

6. Special Thanks

I would like to thank the following people:, (*17)

, (*18)

7. License

SQL Query Formatter is licensed under the MIT license., (*19)

Copyright (c) 2015 Nil Portugués Calderó

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

The Versions

06/03 2016

dev-master

9999999-dev http://nilportugues.com

A very lightweight PHP class that reformats unreadable and computer-generated SQL query statements to human-friendly, readable text.

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

sql parser query formatter mysql format tokenizer sql server reformat

03/11 2015

v1.2.2

1.2.2.0 http://nilportugues.com

A very lightweight PHP class that reformats unreadable and computer-generated SQL query statements to human-friendly, readable text.

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

sql parser query formatter mysql format tokenizer sql server reformat

03/11 2015

v1.2.1

1.2.1.0 http://nilportugues.com

A very lightweight PHP class that reformats unreadable and computer-generated SQL query statements to human-friendly, readable text.

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

sql parser query formatter mysql format tokenizer sql server reformat

10/04 2015

v1.2.0

1.2.0.0 http://nilportugues.com

A very lightweight PHP class that reformats unreadable and computer-generated SQL query statements to human-friendly, readable text.

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

sql parser query formatter mysql format tokenizer sql server reformat

26/12 2014
24/12 2014

dev-scrutinizer-patch-1

dev-scrutinizer-patch-1 http://nilportugues.com

A very lightweight PHP class that reformats unreadable and computer-generated SQL query statements to human-friendly, readable text.

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

sql parser query formatter mysql format tokenizer sql server reformat

27/06 2014