--- On Thu, 6/17/10, Stevan Little <stevan.lit...@iinteractive.com> wrote:

> From: Stevan Little <stevan.lit...@iinteractive.com>
> Subject: Re: A MooseX ORM, an attempt
> To: "Dexter Tad-y" <dexter...@yahoo.com>
> Cc: moose@perl.org, "Rodrigo" <rodrigol...@gmail.com>
> Date: Thursday, June 17, 2010, 10:26 PM
> 
> On Jun 17, 2010, at 5:55 AM, Dexter Tad-y wrote:
> > 
> >> 
> >> As a wishlist (or more like me rambling here), I'd
> like to
> >> see a place to
> >> plug in SQL
> >> result-sets directly, say:
> >> 
> >> package Person;
> >> ...
> >> result_set 'underage' => (
> >>     sql => "select * from
> person where
> >> age<18"
> >> );
> >> 
> >> That way difficult queries (ie: outer joins?) or
> often-used
> >> queries may be
> >> easily
> >> implemented, and special composite (joint) objects
> may
> >> exist.
> > 
> > 
> > What you are describing sounds like a Repository 
> > (http://martinfowler.com/eaaCatalog/repository.html), or
> maybe a plain PhraseBook-style object. DataMapper's
> philosophy encourages encapsulation of the session
> (connection). But you can still write classes with access to
> the session object so that you may encapsulate often used
> queries.
> 
> Actually I really like Rodrigos idea and I think perhaps
> you might be misunderstanding it because the example is
> quite simple. So it would be possible to do what he is
> asking by doing this (forgive me if the API is a little off,
> this is pseudo-DataMapper code :))
> 
> package Person;
> ...
> sub underage {
>     my ($self, $session) = @_;
>     $session->objects( $self )->filter('age
> < ?', 18);
> }
> 

Actually you are correct. And the above code works. The session just needs to 
be passed, which should be ok if indeed the Person class requires knowledge of 
the persistence of other persons. I think though that the underage filter 
should probably belong somewhere else, like some 
Verifier/Police/Gatekeeper/etc.   

> Then Person->underage($session) would return a resultset
> of all underage persons. But what Rodrigo is asking for
> seems like a special wrapper for this, perhaps something
> like this:
> 
> resultset 'underage' => (
>     where => [ 'age < ?', 18 ]
> );
> 
> So the underage method would still expect a $session arg,
> but would automatically generate the code to do that. Then
> to return to Rodrigos example, if you had a really insane
> complex mess of joins and other SQL insanity to return a set
> of Person objects, then you could use the example he
> provided and $session would simply do the right thing.
> 
> Anyway, thats just how I read it, I may be totally wrong
> :)
> 
> - Stevan
> 
> 
> 

The above sugar should be trivial, but then again, if someone is doing joins, I 
am skeptical about the Person class needing to know about that. But that's just 
me.

:)

> 
> 
> 
> 



Reply via email to