Smalltalk Simple Image-based Persistence
In an enlightening blog post, Ramon Leon explains that most applications are designed for small businesses with small amounts of data. Therefore most applications will never have to scale (i.e. become the next Twitter), so a relational database is overkill. However, persisting by simply saving the image is slow and error-prone.
Based on these ideas, he suggests a simple (one class) framework which saves only your model. The idea is to use it as long as you can get away with, which may be forever.
I packaged the code from the post, added a few tests, and put it on SqueakSource as SimplePersistence.
It’s really easy to give your application persistence (see SPFileDatabase’s class comment). The three steps are:
- Subclass SPFileDatabase
- On the class-sode of the subclass, implement
- #repositories – returns a collection of objects to be saved
- #restoreRepositories: – gets passed back the collection.
That’s it! Now, whenever you want to save, call class>>saveRepository or class>>takeSnapshot (background save).
You are aware of his SandstoneDb? It provides just a little bit more.
[...] was notified about a posting about simple persistence in Smalltalk. The original posting was more than 2 years old. It was said, that in most cases only [...]
Yes, I read about it in the Seaside book. It seems cool, but I’m hesitant to derive my model classes from framework classes. What do you think?
I think your fear is unfounded. You needn’t derive all your models from my framework, just the aggregate roots that need queried, and I can’t think of a single case where such a class would or should ever derive from anything other than Object anyway.
I think you need to change the line
1. Subclass SMFileDatabase
to
1. Subclass SPFileDatabase
@Paul DeBruicker Thanks Paul, I updated the post.
[...] Ramon Leon, Simple Image Based Persistence in Squeak (January 14, 2008); and Sean DeNigris, Smalltalk Simple Image-based Persistence (May 30, [...]