jdorn / sql-formatter

A lightweight php class for formatting sql statements. Handles automatic indentation and syntax highlighting.
http://jdorn.github.com/sql-formatter/
MIT License
3.89k stars 187 forks source link

[NFR] Uppercase keywords #84

Open quasipickle opened 8 years ago

quasipickle commented 8 years ago

I have patched my local copy to automatically uppercase any reserved keywords. So a submitted query like:

select * from blah as b

Gets formatted into

SELECT
  *
FROM
  blah AS b

Is there any interest in me making a full pull request of this functionality?

michalklabnik commented 8 years ago

:+1:

morphiaz commented 8 years ago

👍

SmetDenis commented 8 years ago

Cool!

quasipickle commented 8 years ago

Until I hear back from @jdorn, here's my changes:

Line 144:

public static $uppercase = true;

Line 692:

if(self::$uppercase && in_array($token[self::TOKEN_TYPE],array(self::TOKEN_TYPE_RESERVED,self::TOKEN_TYPE_RESERVED_NEWLINE,self::TOKEN_TYPE_RESERVED_TOPLEVEL))){
   $highlighted = strtoupper($highlighted);
}
jdorn commented 8 years ago

That looks fine if you want to create a pull request. Just make sure self::$uppercase defaults to false to keep it backwards compatible.

quasipickle commented 8 years ago

Request made: https://github.com/jdorn/sql-formatter/pull/86

zobzn commented 8 years ago

👍 awesome

acicali commented 7 years ago

Just wanted to add my 2 cents here...

Why not just add CSS classes instead of inline styles? Then not only could this be accomplished in CSS, but changing colors could be done easily without modifying the codebase. I'd also like to add backticks to the queries... classes would solve that as well.