Sha256: 2938d73a47602215561629732bdfaecab812a15b6461279f6fcbb0d303a0b1f2

Contents?: true

Size: 734 Bytes

Versions: 8

Compression:

Stored size: 734 Bytes

Contents

# encoding: utf-8
require 'mysql'

class Mysql
  def summary
    self.list_tables.each do |tbl|
      next if tbl =~ /^tws/
      puts "+" * 160
      puts "%80s" % tbl
      puts "+" * 160
      columns = self.query("select * from #{tbl}").fetch_hash.keys
      columns.in_chunks_of(6).each do |chunk|
        puts "%-25s " * chunk.size % chunk
      end
      puts "\n\n"
    end
  end
end



class Array
  def chunks(number_of_chunks)
    chunks_of( (self.size/number_of_chunks.to_f).ceil )
  end
  def in_chunks_of(chunk_size)
    nchunks = (self.size/chunk_size.to_f).ceil
    chunks = Array.new(nchunks) { [] }
    self.each_with_index do |item,index|
      chunks[ index/chunk_size ] << item
    end
    return chunks
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
metamri-0.2.26 lib/metamri/mysql_tools.rb
metamri-0.2.25 lib/metamri/mysql_tools.rb
metamri-0.2.24 lib/metamri/mysql_tools.rb
metamri-0.2.22 lib/metamri/mysql_tools.rb
metamri-0.2.21 lib/metamri/mysql_tools.rb
metamri-0.2.20 lib/metamri/mysql_tools.rb
metamri-0.2.19 lib/metamri/mysql_tools.rb
metamri-0.2.18 lib/metamri/mysql_tools.rb