Sha256: 1d6f77a25425e073072ba9c3831eba3d7be35a622708f77fbfd0cdae3ea9603f

Contents?: true

Size: 834 Bytes

Versions: 3

Compression:

Stored size: 834 Bytes

Contents

module ArelMysqlIndexHint
  module ArelVisitorsMySQL
    extend ActiveSupport::Concern

    included do
      alias_method_chain :visit_Arel_Table, :mysql_index_hint
    end

    def visit_Arel_Table_with_mysql_index_hint(o, a)
      sql = visit_Arel_Table_without_mysql_index_hint(o, a)

      if o.index_hint
        append_index_hint(sql, o.index_hint)
      else
        sql
      end
    end

    private

    def append_index_hint(sql, index_hint)
      index_hint_sql = index_hint.map {|index, hint_type|
        index = Array(index).map {|i| quote_table_name(i) }
        hint_type = hint_type.to_s.upcase
        "#{hint_type} INDEX (#{index.join(', ')})"
      }.join(", ")

      if sql.is_a?(String)
        sql + " " + index_hint_sql
      else
        sql << " " + index_hint_sql
        sql
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
arel-mysql-index-hint-0.1.4 lib/arel-mysql-index-hint/arel-visitors-mysql.rb
arel-mysql-index-hint-0.1.3 lib/arel-mysql-index-hint/arel-visitors-mysql.rb
arel-mysql-index-hint-0.1.2 lib/arel-mysql-index-hint/arel-visitors-mysql.rb