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.

ocodo
  • 29,401
  • 18
  • 105
  • 117
Chris
  • 105
  • 8
  • Can you provide more details on the class project, either your Prof/Teacher has completely misunderstood the purpose of Rails or you are trying to use Rails to do a simple Ruby project that requires you to do file read/writes to store simple data. – ocodo Oct 07 '10 at 00:46

3 Answers3

4

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
  • 22,278
  • 5
  • 35
  • 28
2

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
  • 52,691
  • 28
  • 123
  • 168
0

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
  • 31
  • 2