-
Notifications
You must be signed in to change notification settings - Fork 9
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
Test with multiple DB engines #35
Conversation
30f7c94
to
d722897
Compare
@@ -15,7 +15,13 @@ def self.truncate! | |||
scope :created_before, ->(date = 1.month.ago) { where(arel_table[:created_at].lt(date)) } | |||
|
|||
def self.namespaced(namespace) | |||
where(arel_table[:key].matches("#{namespace}:%")) | |||
case ActiveRecord::Base.connection.adapter_name | |||
when 'PostgreSQL' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: In most cases, ActiveRecord::Base.connection.adapter_name
will return 'PostgreSQL'
. But there are cases where this might no be true, even if PostgreSQL is used.
There are so much factors, when this value could look different e.g. non pg
database driver, wrapper for pg
driver or even database adapter naming in database.yml
could alter AR.adapter_name
due to unspoken conventions of ActiveRecord.
And in general, even huge PG fans still can't agree on how to capitalize PostgreSQL name.
I would recommend to go with this as a method to detect PG adapters.
ActiveRecord::Base.connection.adapter_name =~ /postg/
case ActiveRecord::Base.connection.adapter_name | ||
when 'PostgreSQL' | ||
ifx = Arel::Nodes::InfixOperation.new('IN', Arel::Nodes.build_quoted(namespace), arel_table[:key]) | ||
where(Arel::Nodes::NamedFunction.new('POSITION', [ifx]).eq(1)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue: I might be mistaken, I don't have big exposure with MySQL and MariaDB.
But this AREL query could be used for MariaDB/MySQL case as well.
Seems like IN
/POSITION
is supported by both. I couldn't find mentions about IN
in documentation, but I found comments in various pages where people mention that it works.
Sqlite doesn't seem to support POSITION
, though.
Fixes #33