Skip to content

Instantly share code, notes, and snippets.

@adelevie
Created October 26, 2010 04:59
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save adelevie/646353 to your computer and use it in GitHub Desktop.
Save adelevie/646353 to your computer and use it in GitHub Desktop.
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