method
indexes
v4.2.1 -
Show latest stable
- Class:
ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter
indexes(table_name, name = nil)public
Returns an array of indexes for the given table.
# File activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb, line 425
def indexes(table_name, name = nil) #:nodoc:
indexes = []
current_index = nil
execute_and_free("SHOW KEYS FROM #{quote_table_name(table_name)}", 'SCHEMA') do |result|
each_hash(result) do |row|
if current_index != row[:Key_name]
next if row[:Key_name] == 'PRIMARY' # skip the primary key
current_index = row[:Key_name]
mysql_index_type = row[:Index_type].downcase.to_sym
index_type = INDEX_TYPES.include?(mysql_index_type) ? mysql_index_type : nil
index_using = INDEX_USINGS.include?(mysql_index_type) ? mysql_index_type : nil
indexes << IndexDefinition.new(row[:Table], row[:Key_name], row[:Non_unique].to_i == 0, [], [], nil, nil, index_type, index_using)
end
indexes.last.columns << row[:Column_name]
indexes.last.lengths << row[:Sub_part]
end
end
indexes
end Related methods
- Instance methods
- _quote
- add_index
- begin_db_transaction
- begin_isolated_db_transaction
- bulk_change_table
- case_insensitive_comparison
- case_sensitive_comparison
- case_sensitive_modifier
- change_column
- change_column_default
- change_column_null
- charset
- clear_cache!
- collation
- columns
- commit_db_transaction
- create_database
- create_table
- current_database
- disable_referential_integrity
- drop_database
- drop_table
- each_hash
- empty_insert_statement_value
- error_number
- exec_rollback_db_transaction
- execute
- execute_and_free
- foreign_keys
- index_algorithms
- indexes
- join_to_update
- native_database_types
- new_column
- pk_and_sequence_for
- primary_key
- quote_column_name
- quote_table_name
- quoted_false
- quoted_true
- recreate_database
- rename_column
- rename_index
- rename_table
- schema_creation
- show_variable
- strict_mode?
- supports_bulk_alter?
- supports_foreign_keys?
- supports_index_sort_order?
- supports_indexes_in_create?
- supports_migrations?
- supports_primary_key?
- supports_transaction_isolation?
- supports_views?
- table_exists?
- tables
- truncate
- type_to_sql
- unquoted_false
- unquoted_true
- update_sql
- valid_type?
- Class methods
- emulate_booleans
- new
- Protected methods
-
add_column_sql -
add_index_length -
add_index_sql -
add_timestamps_sql -
change_column_sql -
initialize_type_map -
quoted_columns_for_index -
register_integer_type -
remove_column_sql -
remove_columns_sql -
remove_index_sql -
remove_timestamps_sql -
rename_column_sql -
subquery_for -
translate_exception - Private methods
-
configure_connection -
extract_foreign_key_action -
mariadb? -
supports_rename_index? -
version