Using ActiveRecord to determine database structure

K

Karla

Hi Folks,

for a project i have to write a program that determines automatically
the stucture of a given database. This means, i have to find out which
tables a database has, which attributes those tables have, which type
those attributes have and also the table constraints.

For this purpose i wanted to use ActiveRecord because as far as i know
it is capable of doing all this things.
I did the "Rolling with Ruby on Rails" tutorial so i know that the
scaffolding mechanism can be used to determine a table's structure.
When looking into the ActiveRecord sources i found a method named
"structure_dump" in
connection_adapters/abstract/schema_statements.rb, i guess i can use
that to find out of which tables a database consists.

Since i'm very new to Ruby i have a lot of problems to implement those
things. What i already achieved is to connect to a database with
ActiveRecord like this

ActiveRecord::Base.establish_connection(
:host => "localhost" ,
:adapter => "mysql",
:database => "test" ,
:username => "user" ,
:password => "password" ,
:socket => "/var/run/mysqld/mysqld.sock"
)

My question is if somebody kindly provide me with some sort of small
example of how to determine a Database's description with ActiveRecord.
This would be very nice.

With kind regards,
Karla
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,219
Latest member
KristieKoh

Latest Threads

Top