Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using ruby with databases, but without rails

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?

like image 420
user61734 Avatar asked Feb 11 '10 04:02

user61734


People also ask

Can Ruby connect to database?

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.

Can you use ActiveRecord without rails?

ActiveRecord is commonly used with the Ruby-on-Rails framework but you can use it with Sinatra or without any web framework if desired.

Does Ruby on Rails have a database?

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.

Which database is used with Ruby?

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.


1 Answers

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

like image 108
Alison R. Avatar answered Oct 02 '22 17:10

Alison R.