How to query SQL with Ruby?
June 10, 2007 4:19 PM   Subscribe

What's the best way (using the internet, and/or books) to learn how to query SQL databases with Ruby?
posted by anonymous to Computers & Internet (3 answers total) 1 user marked this as a favorite
The syntax of how to make a query will differ greatly depending on which adapter you're using to connect to the database (SQLite, MySQL, Postgres, etc.), at least in my experience. If you're using a framework like rails, the ruby syntax for queries wil be more standardized, so it's just a matter of learning that. So, generally my answer is to google for the ruby driver for the database you plan to use, and then google for docs on how to make queries with that driver.
posted by tmcw at 4:29 PM on June 10, 2007

The best way is to use the ActiveRecord gem bundled with Ruby on Rails. Any Ruby on Rails tutorial or book (I suggest Agile Web Development with Ruby on Rails) will be able to teach you the basics of ActiveRecord use. You can then just "drop" this functionality into your Ruby scripts.

I also have a very very very short wiki introduction to using it:

Using ActiveRecord in regular Ruby scripts
posted by Hates_ at 4:43 PM on June 10, 2007

I've just finished trying to learn how make a small ruby app that will query an Oracle DB. A couple pages I found helpful:

"Connecting Ruby to Oracle" from

Ruby on Rails With Oracle

Using those two pages I've managed to get things working (albeit in a very very minimal manner, with just one simple query).
posted by inigo2 at 2:08 PM on June 12, 2007

« Older Buying Macbook Pro in Canada   |   Bullet Theory (Not JFK related). Newer »
This thread is closed to new comments.