I've some huge text files to process and make sense out of the data. Part of the task is to save t开发者_JAVA技巧his 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?
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
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.
You're after ActiveRecord, which supplies the database connectivity. A quick google search suggested this might be a good place to start.
for mysql, check out the mysql2 gem
#>> gem install mysql2
require 'mysql2'
client = Mysql2::Client.new(:host => "localhost", :username => "root")
精彩评论