GithubHelp home page GithubHelp logo

niceql's People

Contributors

alekseyl avatar maxlap avatar nicolasleger avatar nikolayrys avatar petergoldstein avatar quentindemetz avatar tdeo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

niceql's Issues

Allows Install On Older Ruby, But Actually Requires Ruby >=2.3

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.

hm strange behaviour

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')"

image

Officially supported ruby version

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).

Log output is not colorized

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

Handling of comments and whitespace

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.

Modifies whitespace within sql strings

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.

Logging incompatibility with ActiveRecord 7.0

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'

Undefined method [] for NilClass in prettify_pg_err

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

Support for beautifying multiple queries

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.