6

I've some huge text files to process and make sense out of the data. Part of the task is to save this data into a database. I want to use Ruby, with postgres or mysql, postgres being the first choice. What libraries should I include? There is no model, its going to be plain SQL statements. How to do this without rails?

4 Answers 4

4

For PostgreSQL, you want ruby-pg. It supplies your basic database connection with the ability to query it. The documentation is sparse, but there are plenty of code samples in the source tree. Here's a fairly straightforward one:

https://bitbucket.org/ged/ruby-pg/src/e4465a9779faed39825213d140df6b1531bb1e68/spec/pg/result_spec.rb?at=default

Edit: The MySQL site lists a few options for connecting to MySQL.

http://dev.mysql.com/downloads/ruby.html

Sign up to request clarification or add additional context in comments.

2 Comments

The link is dead, do you have an alternative?
@JohnMerlino They appear to have changed their tests around. But I updated the link to a comparable example.
4

Sequel - sequel.rubyforge.org - is great as well. Using the core library (not the Sequel::Model ORM) you can write SQL like queries/statements using Ruby syntax.

Comments

0

You're after ActiveRecord, which supplies the database connectivity. A quick google search suggested this might be a good place to start.

3 Comments

Nope, I dont want to use ORM (activerecord is ORM, right?) I want to write my own SQL statements, like the way we do with mysql_query, mysql_connect etc in PHP.
Yes, ActiveRecord is an ORM, and is overkill for executing plain SQL statements.
still and orm but its light and faaast datamapper.org/getting-started.html - datamapper. its also easy to use outside rails
0

for mysql, check out the mysql2 gem

#>> gem install mysql2
require 'mysql2'

client = Mysql2::Client.new(:host => "localhost", :username => "root")

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.