Hi monks,

Maybe it's slightly OT. The website I'm building in Catalyst has many query pages. I create a query sub to handle these all. Now I noticed this sub is more and more longer, and the structure of the code is much similar:

#pseudo code my @calauses; my $dbh = $c->model("TEST_DBI")->dbh() my $sth; if ($query_name = a){ ...... # build query statement and where clauses; ...... } elsif( $query_name == b) { ..... #ditto ..... } .... .... else{ #do nothing } $sth->prepare($statement) ........ #forward to view .......

Any idea to make it more short and elegant? As in my brain, a database class including query method might be solve this problem. But where it be put? In model or in Controller? or even create a plugin?(though I don't even know how to create a plugin). Since I seldom(almost zero) read real(production) website code in Catalyst, there is no another idea in the brain. I hope monks could enlighten me!

Besides, would any monks tell me what advantage DBIx::Class(ORM) has? I had used it firstly as monks recommand, quickly I found it has high learning curve, and is hard to use in many join context.

now I switched to DBI, but I hope monks could point its advantage out and let me know spending much time to learning it is worthwhile.

Thanks!

UPDATE:

Thank Your Mother, SQL::Abstract is really what I want.





I am trying to improve my English skills, if you see a mistake please feel free to reply or /msg me a correction


In reply to How treat query elegantly and more? by xiaoyafeng

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.