Sha256: 19f40e85927ec3a0035fdd4027e56ebc26ade2c93cc788fc7ae24c8f0c7addd9

Contents?: true

Size: 647 Bytes

Versions: 1

Compression:

Stored size: 647 Bytes

Contents

module ArelMysqlIndexHint
  module ArelVisitorsMySQL
    def visit_Arel_Table(o, a)
      sql = super

      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 {|hint_type, index|
        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

1 entries across 1 versions & 1 rubygems

Version Path
arel-mysql-index-hint-0.2.1 lib/arel-mysql-index-hint/arel-visitors-mysql.rb