Sha256: 82b41e193df2ff07e1d3c9da425b3420122ae5dde63e08f132c9340fbb4326bb

Contents?: true

Size: 576 Bytes

Versions: 1

Compression:

Stored size: 576 Bytes

Contents

module ActiveRecordSlave
  module InstanceMethods

    # Database Adapter method #select is called for every select call
    # Replace #select with one that calls the slave connection instead
    def select_with_slave_reader(sql, name = nil)
      # Only read from slave when not in a transaction and when this is not already the slave connection
      if (open_transactions == 0) && !(name && name.starts_with?('Slave: '))
        Slave.connection.select(sql, "Slave: #{name || 'SQL'}")
      else
        select_without_slave_reader(sql, name)
      end
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
active_record_slave-0.1.0 lib/active_record_slave/instance_methods.rb