Created
February 13, 2018 22:24
-
-
Save ddrscott/62f5791b8fe1ddccf22b77b6d4a7bea6 to your computer and use it in GitHub Desktop.
Helper to beautify SQL statements. Works as file or pipe.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env ruby | |
| require 'open3' | |
| # # Dependencies | |
| # `sqlformat` and `pygmentize` are Python programs :/ | |
| # make sure it's installed and available in your path. | |
| # ``` | |
| # $ pip install --upgrade sqlparse | |
| # $ pip install --upgrade pygment | |
| # $ export PATH=$PATH:~/Library/Python/3.5/bin | |
| sql = ARGF.read.strip | |
| cmd = 'sqlformat -k upper -i lower --reindent_aligned -' + ($stdout.isatty ? '| pygmentize -g -l sql' : '') | |
| out, _status = Open3.capture2(cmd, stdin_data: sql) | |
| puts out |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is this what you are looking for?