Rose::DB::Object::QueryBuilder is a Perl module that can build SQL queries on behalf of Rose::DB::Object::Manager.
SYNOPSIS
use Rose::DB::Object::QueryBuilder qw(build_select);
# Build simple query
$sql = build_select
(
dbh => $dbh,
select => 'COUNT(*)',
tables => [ 'articles' ],
columns => { articles => [ qw(id category type title date) ] },
query =>
[
category => [ 'sports', 'science' ],
type => 'news',
title => { like => [ '%million%',
'%resident%' ] },
],
query_is_sql => 1);
$sth = $dbh->prepare($sql);
$dbh->execute;
$count = $sth->fetchrow_array;
...
# Return query with placeholders, plus bind values
($sql, $bind) = build_select
(
dbh => $dbh,
tables => [ 'articles' ],
columns => { articles => [ qw(id category type title date) ] },
query =>
[
category => [ 'sports', 'science' ],
type => 'news',
title => { like => [ '%million%',
'%resident%' ] },
],
query_is_sql => 1,
sort_by => 'title DESC, category',
limit => 5);
$sth = $dbh->prepare($sql);
$dbh->execute(@$bind);
while($row = $sth->fetchrow_hashref) { ... }
...
# Coerce query values into the right format
($sql, $bind) = build_select
(
db => $db,
tables => [ 'articles' ],
columns => { articles => [ qw(id category type title date) ] },
classes => { articles => 'Article' },
query =>
[
type => 'news',
date => { lt => 'now' },
date => { gt => DateTime->new(...) },
],
sort_by => 'title DESC, category',
limit => 5);
$sth = $dbh->prepare($sql);
$dbh->execute(@$bind);
Product's homepage
Requirements:
· Perl