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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |