[Dbix-class] [OT][ANNOUNCE] SQL Generation with SQL::DB

Mark Lawrence nomad at null.net
Thu Sep 6 15:06:22 GMT 2007


> comparison operators, and, or and not. (Not was the hardest, because 
> SQL::Abstract doesn't directly support it, but even then it was just a 
> couple of hours).

Did you mean "Nor was it the easiest"? And how readable is your code?
It is obvious to you at first glance what the query is? I'm curious,
could you please compare the two versions of the following SQL:

    WHERE lname LIKE '%son%' AND NOT ( age < 10 OR age > 20 )

with SQL::DB:

    where => $r->lname->like('%son%') & ! ($r->age < 10 | $r->age > 20 )

with SQL::Abstract:

    %where = (
        lname => {like => '%son%'},
        age   => [-and => {'>=', 10}, {'<=', 20}],
    );

Tell me which you would find easier to write, understand, and maintain? 

For an even closer approximation it is possible to do this:

    my $age   = $r->age;
    my $lname = $r->lname;
    where => $lname->like('%son%') & ! ($age < 10 | $age > 20 )

Thanks,
Mark.
-- 
Mark Lawrence



More information about the DBIx-Class mailing list