Method: Sequel::SQLite::DatabaseMethods#indexes
- Defined in:
- lib/sequel/adapters/shared/sqlite.rb
#indexes(table, opts = OPTS) ⇒ Object
Use the index_list and index_info PRAGMAs to determine the indexes on the table.
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/sequel/adapters/shared/sqlite.rb', line 90 def indexes(table, opts=OPTS) m = output_identifier_meth im = input_identifier_meth indexes = {} table = table.value if table.is_a?(Sequel::SQL::Identifier) .with_sql("PRAGMA index_list(?)", im.call(table)).each do |r| if opts[:only_autocreated] # If specifically asked for only autocreated indexes, then return those an only those next unless r[:name].start_with?('sqlite_autoindex_') elsif r.has_key?(:origin) # If origin is set, then only exclude primary key indexes and partial indexes next if r[:origin] == 'pk' next if r[:partial].to_i == 1 else # When :origin key not present, assume any autoindex could be a primary key one and exclude it next if r[:name].start_with?('sqlite_autoindex_') end indexes[m.call(r[:name])] = {:unique=>r[:unique].to_i==1} end indexes.each do |k, v| v[:columns] = .with_sql("PRAGMA index_info(?)", im.call(k)).map(:name).map{|x| m.call(x)} end indexes end |