wazzuteke has asked for the wisdom of the Perl Monks concerning the following question:

Hey all. So I've searched and searched but haven't been able to find out how to do select conditions as named columns using DBIx::Class. In an attempt to try and keep it simple, here is what I'm looking to do:
SELECT column_name, ( date_column >= NOW() ) as condition FROM some_ +table;
Where I am hunting to have the query return a boolean indicating whether or not 'date_column' is a date past right now. Simple enough it seems. That said, the ultimate question is: Any ideas of how to do this with DBIx::Class?

Can't seem to find anything in the docs, and have pecked at things like:
{ 'select' => { 'date_column' => { '>=', NOW(), } }, }
Which is somewhat similar to how to run within the WHERE tuple condition, yet generates a query like the following (which is not syntactically correct):
SELECT column_name, DATE_COLUMN( >= ( NOW() ) ) as condition
The best part? Even if it did generate the correct syntax, it also decided to uc() the column name. And, given I'm playing with MySQL, my column names are all case sensitive. Boo!

Any help would be appriciated... Even if it's pointing me to documation I missed or skimmed to fast.

Thanks!

---------
perl -le '$.=[qw(104 97 124 124 116 97)];*p=sub{[@{$_[0]},(45)x 2]};*d=sub{[(45)x 2,@{$_[0]}]};print map{chr}@{p(d($.))}'

Replies are listed 'Best First'.
Re: Conditions as named columns using DBIx::Class
by dragonchild (Archbishop) on Oct 31, 2008 at 19:33 UTC
    Under the hood, DBIx::Class uses SQL::Abstract for SQL generation. Check those docs. Alternately, head over to irc.perl.org #dbix-class - they're extremely responsive and you can usually get mst, castaway, or one of the other devs/power users to answer within minutes.

    My criteria for good software:
    1. Does it work?
    2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?
      Awesome, thanks for the IRC channel - I didn't know. And thanks, too, for the SQL::Abstract reference - I always forget to look there ;)

      ---------
      perl -le '$.=[qw(104 97 124 124 116 97)];*p=sub{[@{$_[0]},(45)x 2]};*d=sub{[(45)x 2,@{$_[0]}]};print map{chr}@{p(d($.))}'
Re: Conditions as named columns using DBIx::Class
by Narveson (Chaplain) on Oct 31, 2008 at 21:53 UTC

    Create and save a view with the calculated column you need.