Module: Switchman::ActiveRecord::StatementCache::BindMap

Defined in:
lib/switchman/active_record/statement_cache.rb

Instance Method Summary collapse

Instance Method Details

#bind(values, current_shard, target_shard) ⇒ Object

performs id transposition here instead of query_methods.rb



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/switchman/active_record/statement_cache.rb', line 28

def bind(values, current_shard, target_shard)
  bvs = @bind_values.map { |pair| pair.dup }
  @indexes.each_with_index do |offset,i|
    bv = bvs[offset]
    if bv[1].sharded
      bv[1] = Shard.relative_id_for(values[i], current_shard, target_shard || current_shard)
    else
      bv[1] = values[i]
    end
  end
  bvs
end

#primary_value_indexObject



41
42
43
44
45
# File 'lib/switchman/active_record/statement_cache.rb', line 41

def primary_value_index
  if primary_bv_index = @bind_values.index{|col, sub| sub.primary}
    @indexes.index(primary_bv_index)
  end
end