Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

Re: Why use an OO -> SQL mapper module?

by duelafn (Vicar)
on Aug 11, 2011 at 19:26 UTC ( #919938=note: print w/replies, xml ) Need Help??

in reply to Why use an OO -> SQL mapper module?

"what benefit there is to replacing the conciseness of a SQL statement (which can be wrapped up into a method anyways, right?)"

Indeed - my take on it is that these ORMs are (at one level) just the generalization of those methods written (and tested) for you already.

You also end up with some nice tricks that other people found useful like DBIx::Class's ResultSets which are nice for building up a query over different chunks of code:

my $store = $schema->resultset('Items'); $store = restrict_to_department( $store, $department ) if $department; $store = restrict_to_seller( $store, $seller ) if $seller; print format_top_ten_items( $store ); # doesn't care whether $store is + restricted sub restrict_to_department { $_[0]->search({ '' => $_[1] }, { join => "departments +" }); }

I doubt hand-rolled code could be so concise (without re-implementing DBIx::Class). the restrict_to* subs are completely independent (don't even care whether the other feature exists). The database won't be hit until $store is iterated over within the call to format_top_ten_items. Of course - you do have the investment in learning the ORM (which is non-trivial) and, as always, the benefit to your application may vary. I was once a skeptic, but have decided that for most code (simple imports/exports being the most obvious exception), an ORM (DBIx::Class in particular) is worth the investment to learn and use.

Good Day,

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://919938]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (6)
As of 2018-05-22 09:21 GMT
Find Nodes?
    Voting Booth?