Last active
February 2, 2017 10:30
-
-
Save ddrscott/f2dfe6576558eee7c160d1093930012d to your computer and use it in GitHub Desktop.
SQL pretty print using ruby and python
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 'coderay' | |
require 'open3' | |
# # Dependencies | |
# `coderay` is a ruby gem. | |
# Install it with: | |
# ``` | |
# $ gem install coderay | |
# ``` | |
# | |
# `sqlformat` is a python program | |
# make sure it's installed and available in your path. | |
# ``` | |
# $ pip install --upgrade sqlparse | |
# $ export PATH=$PATH:~/Library/Python/3.5/bin | |
# ``` | |
sql = ARGF.read | |
out, _status = Open3.capture2('sqlformat -k upper -i lower --reindent_aligned -', :stdin_data=>sql) | |
puts CodeRay.scan(out, :sql).terminal |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment