Sha256: db8beccd6b633a794ddba179d55a7be266d3ba0814392d6c09fd5bef858514d5

Contents?: true

Size: 1.07 KB

Versions: 5

Compression:

Stored size: 1.07 KB

Contents

require 'terminal-table'

module Arql::Commands
  module Table
    class << self
      def table_info(table_name)
        Terminal::Table.new do |t|
          t << ['PK', 'Name', 'SQL Type', 'Ruby Type', 'Limit', 'Precision', 'Scale', 'Default', 'Nullable', 'Comment']
          t << :separator
          connection = ::ActiveRecord::Base.connection
          connection.columns(table_name).each do |column|
            pk = if column.name == connection.primary_key(table_name)
                    'Y'
                  else
                    ''
                  end
            t << [pk, column.name, column.sql_type,
                  column.sql_type_metadata.type, column.sql_type_metadata.limit || '',
                  column.sql_type_metadata.precision || '', column.sql_type_metadata.scale || '', column.default || '',
                  column.null, column.comment || '']
          end
        end
      end

    end

    Pry.commands.block_command 'table' do |table_name|
      puts
      puts Table::table_info(table_name)
    end

    Pry.commands.alias_command 't', 'table'
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
arql-0.1.7 lib/arql/commands/table.rb
arql-0.1.6 lib/arql/commands/table.rb
arql-0.1.5 lib/arql/commands/table.rb
arql-0.1.4 lib/arql/commands/table.rb
arql-0.1.3 lib/arql/commands/table.rb