Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Looking for "elegant" Moose DB-aware classes or roles

by sundialsvc4 (Abbot)
on Nov 05, 2011 at 15:43 UTC ( [id://936160]=perlquestion: print w/replies, xml ) Need Help??

sundialsvc4 has asked for the wisdom of the Perl Monks concerning the following question:

I am designing a bunch of Moose classes that will correspond "more or less" to underlying database structures, sometimes in a single table and sometimes multiple tables.   I know about DBIx::Class and MooseX::Storage and I guess that what I’m looking for is something that is as elegant, one might say “as unobtrusive,” as these.   “So,” methinks, “someone out there has probably already done this.”   Hence my inquiry.

What I have in mind so-far is that, of course, we have DBIx::Schema objects auto-generated for the database, to handle the low-level plumbing of the SQL, but those objects are known to the Moose objects that I am now meditating upon.   (The objects would know about the schema-objects and would basically conceal the particulars of how they were used, and of exactly how the database representation was to be, and would use the Schema objects as appropriate to actually do that.)   I am considering that these objects (perhaps by means of a “role?”) know how to do load() and save() and maybe is_loaded() and is_dirty(), and in addition they are serializable (into e.g. an HTTP session store) if I want to persist them for a while without updating the database yet.   I will also need a generic implementation of “a list of things.”   (In other words, an elegant and clever base-class or mixin for the “many side” of a 1->M relationship.)

I would like for this system also to be appropriately “lazy.”   If I instantiate an object but never reference anything from “a different table not yet used,” the query against that other table would not occur – the query would occur only “on demand.”

So, yeah, the motivation for this inquiry is “laziness, which is a virtue.”   Has anyone out there done anything generic, and really cool, along these lines?   A role, perhaps?   Special attributes?   Something elegant that lets me “do more, write less ...” but obviously not attempting to do everything.

Replies are listed 'Best First'.
Re: Looking for "elegant" Moose DB-aware classes or roles
by stvn (Monsignor) on Nov 09, 2011 at 00:34 UTC
Re: Looking for "elegant" Moose DB-aware classes or roles
by Anonymous Monk on Nov 07, 2011 at 04:02 UTC
    Ping?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://936160]
Approved by graff
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2024-04-20 01:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found