sql-formatter icon indicating copy to clipboard operation
sql-formatter copied to clipboard

[NFR] Uppercase keywords

Open quasipickle opened this issue 9 years ago • 8 comments

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?

quasipickle avatar Oct 26 '15 21:10 quasipickle

:+1:

michalklabnik avatar Nov 18 '15 14:11 michalklabnik

👍

morphiaz avatar Nov 18 '15 15:11 morphiaz

Cool!

SmetDenis avatar Nov 18 '15 15:11 SmetDenis

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);
}

quasipickle avatar Nov 18 '15 21:11 quasipickle

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

jdorn avatar Nov 22 '15 16:11 jdorn

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

quasipickle avatar Nov 24 '15 20:11 quasipickle

👍 awesome

zobzn avatar Mar 03 '16 08:03 zobzn

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.

acicali avatar Aug 09 '16 05:08 acicali