Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

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

by duelafn (Priest)
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({ 'department.name' => $_[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,
    Dean


Comment on Re: Why use an OO -> SQL mapper module?
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://919938]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (9)
As of 2014-07-28 12:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (197 votes), past polls