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



53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/switchman/active_record/statement_cache.rb', line 53

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

#primary_value_indexObject



67
68
69
70
71
72
# File 'lib/switchman/active_record/statement_cache.rb', line 67

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