alekseyl / niceql Goto Github PK
View Code? Open in Web Editor NEWniceql gem repo. Nice, colorized SQL formatting in ruby.
License: MIT License
niceql gem repo. Nice, colorized SQL formatting in ruby.
License: MIT License
Some of us are stuck using older Ruby versions (in my case, 2.2.4p230) for legacy apps. I was excited to download and try this gem, but when starting up the rails console, it immediately failed with this error:
/home/maurice/.rvm/gems/ruby-2.2.4@my_project_name/gems/bundler-1.13.6/lib/bundler/runtime.rb:91:in `require': /home/maurice/.rvm/gems/ruby-2.2.4@insureio/gems/niceql-0.1.23/lib/niceql.rb:85: syntax error, unexpected '.' (SyntaxError)
...ine..-1] : original_sql_query&.lines
That looks to be failing due to the lack of the safe navigation operator introduced in Ruby 2.3. It would be greatly appreciated if you could either more clearly document the dependencies, or make the gem backward-compatible with older rubies.
sql request:
"SELECT \"webinars\".* FROM \"webinars\" WHERE \"webinars\".\"deleted_at\" IS NULL AND \"webinars\".\"lesson_id\" IN (SELECT \"lessons\".\"id\" FROM \"lessons\" WHERE \"lessons\".\"deleted_at\" IS NULL AND \"lessons\".\"topic_id\" IN (SELECT \"topics\".\"id\" FROM \"topics\" WHERE \"topics\".\"deleted_at\" IS NULL AND \"topics\".\"course_id\" IN (903, 973, 912, 927, 972, 957, 940, 938, 891, 951, 944, 913, 888, 897, 871))) AND (start_date > '2022-11-06 21:00:00')"
Hello, i'm wondering what is the officially supported ruby version? Nothing is specified in the .gemspec
, but there is a single use of &.
in niceql.rb, which means it cannot support anything below 2.3.0
.
Replacing the &.
would probably be all that is needed for supporting lower versions. (In that case, adding the lower version to travis would help avoiding this mistake again).
Hello, the prettifier is not colorizing ActiveRecord log output because false
is being passed into the Prettifier.prettify_sql
call in AbstractAdapterLogPrettifier
.
I've tried this with passing true
and it doesn't seem to break my Rails log, so I'm not sure if this is intentional or not.
Thanks
I'm considering using niceql
to smarten up some of my migration files, but have encountered an issue with comment --
and whitespace handling.
Example input:
--Insightful remark
SELECT * FROM Customers;
--Useless comment
SELECT * FROM Orders ;
Passing to prettify_sql
currently produces:
--Insightful remark SELECT *
FROM Customers; --Useless comment
SELECT *
FROM Orders ;
It would be nice if whitespace and comments could be left unmodified.
Newlines and extra whitespace are collapsed into single spaces within sql string literals. When running INSERT or UPDATE statements through Niceql - as with the pg_adapter_with_nicesql
option - can lead to data corruption.
Example:
[2] pry(main)> Niceql::Prettifier.prettify_sql("select 'foo\nbar baz'")
=> "select \e[0;36;49m'foo bar baz'\e[0m"
I think the bug is likely here: https://github.com/alekseyl/niceql/blob/master/lib/niceql.rb#L129
I apologize that I don't have time to contribute a bug fix PR.
Without a fix, I don't think pg_adapter_with_nicesql
can be used safely even in development.
Hello,
it seems the abstract log
method from ActiveRecord changed signature to allow async usage:
/activerecord-7.0.0/lib/active_record/connection_adapters/abstract_adapter.rb:755
Resulting in an error when trying to destroy something:
> User.destroy_all
User Load (0.6ms)
SELECT "users".*
FROM "users"
TRANSACTION (0.1ms)
BEGIN
TRANSACTION (0.1ms)
ROLLBACK
ArgumentError: wrong number of arguments (given 6, expected 1..5)
from /Users/bob/.asdf/installs/ruby/3.0.3/lib/ruby/gems/3.0.0/gems/activerecord-7.0.0/lib/active_record/connection_adapters/abstract_adapter.rb:755:in `log'
Hello again @alekseyl
I'm getting a NilClass error with 0.2.0 when parsing out the error logs. It's basically swallowing the real log output so I've had to roll back to 1.0.25 for now.
I was able to trace it to this here where it's getting the line at index 3 but it's only a 3 item array.It does correctly detect that I'm using postgres.
Hopefully an easy solution for you but I'm not sure what format is being expected here.
From: /Users/jhirn/.asdf/installs/ruby/2.7.2/lib/ruby/gems/2.7.0/gems/niceql-0.2.0/lib/niceql.rb:84 Niceql::Prettifier.prettify_pg_err:
79: return err if err[/LINE \d+/].nil?
80: err_line_num = err[/LINE \d+/][5..-1].to_i
81:
82: #
83: binding.pry
=> 84: start_sql_line = err.lines[3][/(HINT|DETAIL)/] ? 4 : 3
85: err_body = start_sql_line < err.lines.length ? err.lines[start_sql_line..-1] : original_sql_query&.lines
86:
87:
88: # this means original query is missing so it's nothing to prettify
89: return err unless err_body
[1] pry(Niceql::Prettifier)> err
=> "PG::UndefinedTable: ERROR: missing FROM-clause entry for table \"product_type\"\nLINE 1: ...t_id\" = $13 AND \"products\".\"carrier_id\" = $14 AND \"product_t...\n ^\n"
[2] pry(Niceql::Prettifier)> ap err.lines
[
[0] "PG::UndefinedTable: ERROR: missing FROM-clause entry for table \"product_type\"\n",
[1] "LINE 1: ...t_id\" = $13 AND \"products\".\"carrier_id\" = $14 AND \"product_t...\n",
[2] " ^\n"
]
=> nil
I'm considering using niceql
to smarten up some of my migration files, but have encountered an issue with comment --
and whitespace handling.
Example input:
--Insightful remark
SELECT * FROM Customers;
--Useless comment
SELECT * FROM Orders ;
It would be nice if whitespace and comments could be left unmodified and separate queries beautified as expected.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.