DBIx::Class really is the way to go here (if your DB design is sane; if your design is poor then DBIC will have an impedance mismatch). Pseudo code-
my %query = ( some => "default relevant to controller" ); my @stuff = $c->request->param("some_checkbox_list"); $query{foo} = { in => \@stuff } if @stuff; $query{something} = "tacos" if $something_taco_related; # a dozen more similar style, disparate variable loads. my %where = ( some => "dynamic", list => "of conditions" ); my $rs = $c->model("DBIC::SomeTable") ->search(\%query, { join => [ blah, blah ], %where }); $c->stash( some_stuff_rs => $rs );
DBIC (and by extension, SQL::Abstract) shines when dynamic data drives your queries as well as when you need ready access through relationships.
Sidebar not relevant to this particular thread but a previous one: it's somewhat poor etiquette to ask the same question in three places at once (e.g., Cat list, PM, Stack Overflow). You should generally do one at a time and wait a day to see what answers you get or at least mention and link to the cross-posted question.
In reply to Re: How treat query elegantly and more?
by Your Mother
in thread How treat query elegantly and more?
by xiaoyafeng
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |