Skip to content

Instantly share code, notes, and snippets.

@ducky-hong
Last active August 29, 2015 14:19
Show Gist options
  • Save ducky-hong/8cec75dcf0da551f1b1a to your computer and use it in GitHub Desktop.
Save ducky-hong/8cec75dcf0da551f1b1a to your computer and use it in GitHub Desktop.
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