Created
October 26, 2010 04:59
-
-
Save adelevie/646353 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'sinatra' | |
require 'active_record' | |
ActiveRecord::Base.establish_connection( | |
:adapter => 'mysql', | |
:encoding => 'utf8', | |
:database => 'foo', | |
:username => 'bar', | |
:password => 'baz', | |
:host => 'localhost' | |
) | |
class Table | |
attr_accessor :name | |
def columns | |
ActiveRecord::Base.connection.execute("show fields from #{@name};") | |
end | |
end | |
def yes_no_to_null(x) | |
case x | |
when "YES" | |
"NULL" | |
when "NO" | |
"NOT NULL" | |
end | |
end | |
get '/' do | |
@tables = Array.new | |
ActiveRecord::Base.connection.execute('show tables;').each do |t| | |
table = Table.new | |
table.name = t[0] | |
@tables << table | |
end | |
erb :index | |
end | |
__END__ | |
@@ index | |
<% @tables.each do |table| %> | |
<h3><u><%= table.name %></u></h3> | |
<% table.columns.each do |column| %> | |
<p>-<strong><%= column[0] %></strong> <i><%= column[1] %></i> <%= yes_no_to_null(column[2]) %></p> | |
<% end %> | |
<br /> | |
<% end %> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment