Method: Arql::Commands::VD.table_info

Defined in:
lib/arql/commands/vd.rb

.table_info(table_name) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/arql/commands/vd.rb', line 22

def table_info(table_name)
  t = []
  t << ['PK', 'Name', 'SQL Type', 'Ruby Type', 'Limit', 'Precision', 'Scale', 'Default', 'Nullable', 'Comment']
  connection = ::ActiveRecord::Base.connection
  connection.columns(table_name).each do |column|
    pk = if [connection.primary_key(table_name)].flatten.include?(column.name)
           'Y'
         else
           ''
         end
    t << [pk, column.name, column.sql_type,
          column..type, column..limit || '',
          column..precision || '', column..scale || '', column.default || '',
          column.null, column.comment || '']
  end
  t
end