Method: Sequel::SqlAnywhere::DatabaseMethods#indexes

Defined in:
lib/sequel/adapters/shared/sqlanywhere.rb

#indexes(table, opts = OPTS) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/sequel/adapters/shared/sqlanywhere.rb', line 51

def indexes(table, opts = OPTS)
  m = output_identifier_meth
  im = input_identifier_meth
  table = table.value if table.is_a?(Sequel::SQL::Identifier)
  indexes = {}
  .
   from(Sequel[:dbo][:sysobjects].as(:z)).
   select{[
     z[:name].as(:table_name),
     i[:name].as(:index_name),
     si[:indextype].as(:type),
     si[:colnames].as(:columns)]}.
   join(Sequel[:dbo][:sysindexes].as(:i), :id=>:id).
   join(Sequel[:sys][:sysindexes].as(:si), :iname=> :name).
   where{{z[:type] => 'U', :table_name=>im.call(table)}}.
   each do |r|
    indexes[m.call(r[:index_name])] =
      {:unique=>(r[:type].downcase=='unique'),
       :columns=>r[:columns].split(',').map{|v| m.call(v.split(' ').first)}} unless r[:type].downcase == 'primary key'
  end
  indexes
end