![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
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.
Please pay attention: even though issue https://github.com/alekseyl/niceql/issues/16 is resolved still potentially UPDATE or INSERT request might corrupt your data, please don't patch pg_adapter on production!
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
Niceql.configure do |c|
# Setting pg_adapter_with_nicesql to true will force formatting SQL queries
# before execution. Formatted SQL will lead to much better SQL-query debugging and much more clearer error messages
# if you are using Postgresql as a data source.
#
# Adjusting pg_adapter in production is strongly discouraged!
#
# If you need to debug SQL queries in production use exec_niceql
# default: false
# uncomment next string to enable in development
# c.pg_adapter_with_nicesql = Rails.env.development?
# uncomment next string if you want to log prettified SQL inside ActiveRecord logging.
# default: false
# c.prettify_active_record_log_output = true
# Error prettifying is also configurable
# default: defined? ::ActiveRecord::Base && ActiveRecord::Base.configurations[Rails.env]['adapter'] == 'postgresql'
# c.prettify_pg_errors = defined? ::ActiveRecord::Base && ActiveRecord::Base.configurations[Rails.env]['adapter'] == 'postgresql'
# spaces count for one indentation
c.indentation_base = 2
# setting open_bracket_is_newliner to true will start opening brackets '(' with nested subqueries from new line
# i.e. SELECT * FROM ( SELECT * FROM tags ) tags; will transform to:
# SELECT *
# FROM
# (
# SELECT * FROM tags
# ) tags;
# when open_bracket_is_newliner is false:
# SELECT *
# FROM (
# SELECT * FROM tags
# ) tags;
# default: false
c.open_bracket_is_newliner = false
end
# 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
puts Niceql::Prettifier.prettify_sql("SELECT * FROM ( VALUES(1), (2) ) AS tmp")
#=> SELECT *
#=> FROM ( VALUES(1), (2) ) AS tmp
puts Niceql::Prettifier.prettify_multiple("SELECT * FROM ( VALUES(1), (2) ) AS tmp; SELECT * FROM table")
#=> SELECT *
#=> FROM ( VALUES(1), (2) ) AS tmp;
#=>
#=> SELECT *
#=> FROM table
puts Niceql::Prettifier.prettify_pg_err( pg_err_output, sql_query )
# to get real nice result you should execute prettified version (i.e. execute( prettified_sql ) !) of query on your DB!
# otherwise you will not get such a nice output
raw_sql = <<~SQL
SELECT err
FROM ( VALUES(1), (2) )
ORDER BY 1
SQL
puts Niceql::Prettifier.prettify_pg_err(<<~ERR, raw_sql )
ERROR: VALUES in FROM must have an alias
LINE 2: FROM ( VALUES(1), (2) )
^
HINT: For example, FROM (VALUES ...) [AS] foo.
ERR
# ERROR: VALUES in FROM must have an alias
# LINE 2: FROM ( VALUES(1), (2) )
# ^
# HINT: For example, FROM (VALUES ...) [AS] foo.
# SELECT err
# FROM ( VALUES(1), (2) )
# ^
# ORDER BY 1
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.
FAQs
Unknown package
We found that niceql demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.