"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


In reply to Re: Why use an OO -> SQL mapper module? by duelafn
in thread Why use an OO -> SQL mapper module? by MyMonkName

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.