niceql gem repo. Nice, colorized SQL formatting in ruby.
niceql gem repo. Nice, colorized SQL formatting in ruby.
ATTENTION: After ver 0.5.0 the ActiveRecord integration is provided via standalone gem: rails_sql_prettifier!
This is a small, nice, simple and zero dependency solution for SQL prettifying for Ruby. It can be used in an irb console without any dependencies ( run bin/console and look for examples ).
Any reasonable suggestions are welcome.
before:
after:
Add this line to your application's Gemfile:
gem 'niceql'And then execute:
$ bundle
# if you are using rails, you may want to install niceql config:
rails g niceql:install Or install it yourself as:
$ gem install niceql… # puts colorized and formatted corresponding SQL query
Model.scope.niceql
# only formatting without colorization, you can run output of to_niceql as a SQL query in connection.execute
Model.scope.to_niceql
# prettify PG errors if scope runs with any
Model.scope_with_err.exec_niceql …If your console support more colors or different schemes, or if you prefer different colorization, then you can override ColorizeString methods. Current colors are selected with dark and white console themes in mind, so a niceql colorization works good for dark, and good enough for white.
Right now gem detects only uppercased form of verbs with simple indentation and parsing options.
Bug reports and pull requests are welcome on GitHub at https://github.com/alekseyl/niceql.
The gem is available as open source under the terms of the MIT License.
No open issues yet, or sync has not completed.