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



87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/switchman/active_record/statement_cache.rb', line 87

def bind(values, current_shard, target_shard)
  bas = @bound_attributes.dup
  @indexes.each_with_index do |offset,i|
    ba = bas[offset]
    if ba.is_a?(::ActiveRecord::Relation::QueryAttribute) && ba.value.sharded
      new_value = Shard.relative_id_for(values[i], current_shard, target_shard || current_shard)
    else
      new_value = values[i]
    end
    bas[offset] = ba.with_cast_value(new_value)
  end
  bas
end

#primary_value_indexObject



101
102
103
104
105
106
107
108
# File 'lib/switchman/active_record/statement_cache.rb', line 101

def primary_value_index
  primary_ba_index = @bound_attributes.index do |ba|
    ba.is_a?(::ActiveRecord::Relation::QueryAttribute) && ba.value.primary
  end
  if primary_ba_index
    @indexes.index(primary_ba_index)
  end
end