Module: DmIsReflective::MysqlAdapter

Includes:
DataMapper
Defined in:
lib/dm-is-reflective/adapters/mysql_adapter.rb

Instance Method Summary collapse

Instance Method Details

#indices(storage) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/dm-is-reflective/adapters/mysql_adapter.rb', line 9

def indices storage
  sql = <<-SQL
    SELECT column_name, index_name, non_unique
    FROM   `information_schema`.`statistics`
    WHERE  table_schema = ? AND table_name = ?
  SQL

  select(Ext::String.compress_lines(sql),
    reflective_table_schema, storage).group_by(&:column_name).
      inject({}) do |r, (column, idxs)|
        primary = idxs.find{ |i| i.index_name == 'PRIMARY' }
        primary.index_name = :"#{storage}_pkey" if primary
        key                = !!primary
        idx_uni, idx_com = idxs.partition{ |i| i.non_unique == 0 }.map{ |i|
          if i.empty?
            nil
          elsif i.size == 1
            i.first.index_name.to_sym
          else
            i.map{ |ii| ii.index_name.to_sym }
          end
        }

        r[column.to_sym] = reflective_indices_hash(key, idx_uni, idx_com)
        r
      end
end

#storagesObject



5
6
7
# File 'lib/dm-is-reflective/adapters/mysql_adapter.rb', line 5

def storages
  select('SHOW TABLES')
end