views:

55

answers:

3

I would like to use a delimited text file (xml/csv etc) as a replacement for a database within Ruby on Rails. Solutions?

(This is a class project requirement, I would much rather use a database if I had the choice.)

I'm fine serializing the data and sending it to the text file myself.

+2  A: 

Have you thought of using SQLite? It is much better solution.

  • It uses a single file.
  • It is way faster than doing the serialization yourself.
  • It is zero configuration. Very simple to use.
  • You get ACID compliance, transactions sub selects etc etc.
Byron Whitlock
The human readable text file is a requirement for the project.
Chris
A: 

MySQL has a way to store tables in CSV. It has some pretty serious limitations, but it sounds like your requirements demand something with some pretty serious limitations anyway.

I've never set up a Rails project that way, and I don't know what it would take, but it seems like it might be possible.

HSQLDB seems to work by storing data on disk as a SQL script that creates your database. It records changes in memory and a log file, and when you shut down it recreates a single SQL script again. I've not used this one myself.

HSQLDB doesn't appear to be one of the supported databases in Rails. I don't know what it would take to add support for a new database.

Ken
+4  A: 

The best way is probably to take the ActiveModel API and build your methods that parse your files in the appropriate ways.

Here's a good presentation about ActiveModel and ActiveRelation where he builds a custom model, which should have a lot of similar concepts (but different backend.) And also a good blog post by Yehuda about the ActiveModel API

Dan McNevin