[Dbix-class] SQL functions in WHERE clause
Brandon Black
blblack at gmail.com
Fri Apr 13 15:09:16 GMT 2007
On 4/13/07, Ivan Fomichev <ifomichev at gmail.com> wrote:
> Hello, Lee,
>
> 2007/4/13, Lee Standen <nom at standen.id.au>:
> > Or, you could take the other tact, and argue that it should be something
> > which is handled on the Perl side...
> >
> > my $rs = $schema->resultset('Patient')->search({
> > -and => [
> > first_name => { like => 'J%' },
> > birth_date => { '>' => time - 20 * SECONDS_IN_YEAR }
> > ]
> > });
> >
> > Yes, while it's POSSIBLE to do that in an SQL statement, I prefer to
> > think as DBIx::Class not as an SQL abstractor, but as a data object
> > extractor, which means anything that requires me to use SQL specific
> > commands is bad :)
> >
I also don't like putting any complex SQL in my DBIC statements, but I
prefer to solve it the other way around: push this stuff down to the
actual DB, by creating views or stored procedures. I don't know if
this case is simple enough to qualify (especially if the birth_date
cutoff in years is variable based on user input), but you see what I
mean in general. The "do it in perl" option isn't bad either, and
might especially be nice in this instance where (a) its simple, and
(b) it doesn't involve perl-side row filtering, so its not like you're
increasing DB load by doing it in perl.
-- Brandon
More information about the Dbix-class
mailing list