Skip to content

@kyriacos /dbdocs.rb forked from adelevie/dbdocs.rb
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
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
Something went wrong with that request. Please try again.