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?
In Ruby we can connect to database using DBI module. DBI module provides Database Independent Interface to access the data source. So, using DBI, the underlying data source can be any database like Oracle, MySQL, Postgres etc, however the API remains the same.
ActiveRecord is commonly used with the Ruby-on-Rails framework but you can use it with Sinatra or without any web framework if desired.
Rails comes with built-in support for SQLite, which is a lightweight serverless database application. While a busy production environment may overload SQLite, it works well for development and testing. Rails defaults to using a SQLite database when creating a new project, but you can always change it later.
SQLite is a default Ruby database – it comes in the package with Ruby itself. So good news – its integration takes only several commands. Note: the Linux package of Ruby comes with SQLite, so you can use commands to manage it.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With