# Direct database access

**URL:** <https://www.ruby-forum.com/t/direct-database-access/105535>\
**Category:** Rails\
**Created:** [May 30, 2007, 9:37pm UTC](https://www.ruby-forum.com/t/direct-database-access/105535 "2007-05-30T21:37:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![addywaddy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ea5d25/32.png) [@addywaddy](https://www.ruby-forum.com/u/addywaddy)\
**Post date:** [May 30, 2007, 9:37pm UTC](https://www.ruby-forum.com/t/direct-database-access/105535/1 "2007-05-30T21:37:00Z")

</div>

Hi

I would like to write an app that makes some use of ActiveRecord for  
persisting a few domain objects but also extensive direct database  
access for doing things like creating new tables, adding columns /  
indexes. Essentially I’m looking to replicate many of the features in a  
tool like phpmyadmin for mysql, in a ruby app.

I have two questions:

1. Is this creating and or modifying of tables, fields, indexes etc  
something I Should do using Ruby DBI? Can ActiveRecord do any of this  
stuff?

2. If I do need to use DBI is there anywhere I can borrow features from  
ActiveRecord such as getting the database connection from ActiveRecord  
but executing custom SQL against them. Or accessing database tables  
using ActiveRecord which may be renamed or have fields added or removed  
at run time?

My thanks in advance

Adam

---

<div class="post-metadata">

**Author:** ![addywaddy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ea5d25/32.png) [@addywaddy](https://www.ruby-forum.com/u/addywaddy)\
**Post date:** [May 30, 2007, 11:11pm UTC](https://www.ruby-forum.com/t/direct-database-access/105535/2 "2007-05-30T23:11:38Z")

</div>

Adam Griffiths wrote:

> I would like to write an app that makes some use of ActiveRecord for  
> persisting a few domain objects but also extensive direct database  
> access for doing things like creating new tables, adding columns /  
> indexes. Essentially I’m looking to replicate many of the features in a  
> tool like phpmyadmin for mysql, in a ruby app.

ActiveRecord has some schema editing abilities already due to it’s  
migration facility. Take a look at that as much of the differences  
between the various database systems have already been abstracted for  
you.

Eric
