On May 29, 2010, at 10:37 AM, Shawn H Corey wrote:
Hi,
Is the a standard methodology for persistent objects in Moose using
SQL? I'm writing a small web spider and I want my sites to be
persistent objects.
Personally I would recommend using KiokuDB. This is the most
straightforward way to persist Moose object as it is specifically made
to do *exactly* that. KiokuDB seems magical and crazy (object graph
persistence engine, wtf?) but it is really pretty straightforward and
we have used it extensively at $work on all our major client
applications with great success. It is built on solid research and
just like Moose is shuns the idea of "magic" being a good foundation
upon which to build a useful set of tools.
The only drawback to KiokuDB is that since it stores the object graph
rather then trying to map the object to a set of SQL tables, your data
is not stored in a relational/tabular way and so not (easily)
queryable using those tools. Of course this can also be seen as a
benefit as well (I know I see it that way), since you are not
constrained in your OO design by the limitations and infamous
impedance mismatch that comes with ORMs. And of course KiokuDB does
have it's own set of tools as well, just look in KiokuDB::Cmd (this
has load, dump (for the whole DB or just one entry), edit, fcsk and a
garbage collector) and there is KiokuDB::Navigator which provides a
web based view of your KiokuDB.
Two abilities would be useful:
1. Deferred loading: objects are not loaded unless they're needed.
KiokuDB can handle this using the KiokuDB::Lazy trait for your
attributes. Additionally if you use the KiokuDB::Set to store any
collections then that (IIRC) is automatically lazy.
2. Save on exit if dirty: no need to save if they haven't been
changed.
KiokuDB doesn't do this automatically, but you could easily shim a
layer over KiokDB to do just this (see KiokuX::Model as an example of
subclassing KiokuDB itself).
Since it's a small application, I plan to use SQLite for my database.
You can use SQLite as a backend store using KiokuDB::Backend::DBI.
Now, if you really *must* store your Moose objects in a relational
schema (and *really* ask yourself if you *actually* need to do so) you
really have 2 choices, Fey::ORM or DBIx::Class. Of course that isn't
really storing Moose objects but instead storing Fey::ORM/DBIx::Class
objects.
- Stevan