Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend niceql to Arel #19

Merged
merged 3 commits into from
Nov 1, 2021
Merged

Extend niceql to Arel #19

merged 3 commits into from
Nov 1, 2021

Conversation

NikolayRys
Copy link
Contributor

@NikolayRys NikolayRys commented Oct 7, 2021

In this PR I'm doing several things, and the primary one - I'm fixing the way how it is included in ActiveRecord. Currently, it has been missing Arel, which has to_sql methods too. Niceql would be a perfect addition there.

I have removed 2 and added 2 other classes to make the inclusion more comprehensive and consistent.

  1. Removed ActiveRecord:Base - it doesn't have to_sql method
development(main)> User.niceql
NameError: undefined local variable or method `to_sql' for #<Class:0x00007f836610cea8>
Did you mean?  to_s
from /Users/nikolay/.rvm/gems/ruby-2.7.2/gems/activerecord-6.0.4.1/lib/active_record/dynamic_matchers.rb:22:in `method_missing'
  1. Removed ActiveRecord::Associations::CollectionProxy because it uses the same implementation as Relation:
development(main)> Attendee.last.ad_clicks.method(:to_sql).source_location
=> ["/Users/nikolay/.rvm/gems/ruby-2.7.2/gems/activerecord-6.0.4.1/lib/active_record/relation.rb", 651]
  1. Added Arel::TreeManager: https://github.com/rails/rails/blob/main/activerecord/lib/arel/tree_manager.rb#L49
  2. Added Arel::Nodes::Node: https://github.com/rails/rails/blob/main/activerecord/lib/arel/nodes/node.rb#L39

Also, I think that extract_err_caret_line is meant to be a private method.

require 'byebug'

ActiveRecord::Base.logger = Logger.new(STDERR)

ActiveRecord::Base.establish_connection(
adapter: "sqlite3",
dbfile: ":memory:",
database: 'niceql_test'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you don't need to specify database here, otherwise, it creates a file and it's not in-memory anymore

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, indeed.

Copy link
Owner

@alekseyl alekseyl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks neat!

@alekseyl alekseyl merged commit 1d215c6 into alekseyl:master Nov 1, 2021
@NikolayRys NikolayRys deleted the active-record-inclusion branch November 1, 2021 16:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants