Sign in to PrePAN

SQL::QueryBuilder::OO Object oriented SQL query builder



use SQL::QueryBuilder::OO;
$sql = sqlQueryBase::select(qw(id title description), {name => 'author'})
    ->innerJoin('users', 'userId')   # -> INNER JOIN `users` USING(`userId`)
    ->leftJoin({'comments' => 'c'}, sqlCondition::EQ('userId', 'c.from')) # -> LEFT JOIN `comments` AS `c` ON(`userId` = `c`.`from`)
    ->orderBy({'timestamp' => 'DESC'});
$dbh->do($sql, undef, $sql->gatherBoundArgs());


This module provides for an object oriented way to create complex SQL queries while maintaining code readability. It supports conditions construction and bound query parameters.

The project is actually a port of PHP classes to construct queries used in one of my proprietary projects (which may explain the excessive use of the scope resolution operator (::) in the module’s sytax).

The 0.1 version's man-page can be reviewed on my blog. The tarball is available here.


BTW, there's also SQL::Abtract on CPAN. How would you compare it with your module?
SQL::Abstract (and other modules I compared) construct conditions in a hard-to-read fashion using lists and lists-of-lists. This one aims for readable code.
I would support an SQL::Abstract::OO project that used OO-style sugar as a wrapper around SQL::Abstract. But an entirely new system for generating SQL queries would have no traction in Perl infrastructure that was already using SQL::Abstract-compatible frameworks.

Please sign up to post a review.