module Sequel::Plugins::Sharding::DatasetMethods

Public Instance Methods

row_proc() click to toggle source

If a row proc exists on the dataset, replace it with one that calls the previous #row_proc, but calls set_server on the output of that #row_proc, ensuring that objects retrieved by a specific shard know which shard they are tied to.

Calls superclass method
# File lib/sequel/plugins/sharding.rb, line 110
def row_proc
  rp = super
  if rp
    case server = db.pool.send(:pick_server, opts[:server])
    when nil, :default, :read_only
      # nothing
    else
      old_rp = rp
      rp = proc{|r| old_rp.call(r).set_server(server)}
    end
  end
  rp 
end