Last active
August 29, 2015 14:19
-
-
Save ducky-hong/8cec75dcf0da551f1b1a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Octopus | |
module Querying | |
def find_by_sql(sql, binds = []) | |
p sql | |
p binds | |
if binds.present? | |
key = 'user_id' | |
v = binds.collect { |x| [x.first.name, x.second] }.to_h[key] | |
shard = if v.to_i >= 100 | |
:new_contact_1 | |
else | |
:new_contact_0 | |
end | |
elsif sql.is_a?(Arel::SelectManager) | |
puts 'select' | |
end | |
if shard | |
Octopus.using(shard) { super } | |
else | |
super | |
end | |
end | |
end | |
end | |
ActiveRecord::Base.extend(Octopus::Querying) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment