SQL::Composer::Select - SELECT statement
SYNOPSIS
my $expr =
SQL::Composer::Select->new( from => 'table' , columns => [ 'a' , 'b' ]);
my $sql = $expr ->to_sql;
my @bind = $expr ->to_bind;
$expr ->from_rows([[ 'c' , 'd' ]]);
|
DESCRIPTION
Builds SELECT
statement and converts (from_rows()
) received arrayref data to hashref with appropriate column names as keys and joins as nested values.
Select column with AS
my $expr = SQL::Composer::Select->new(
from => 'table' ,
columns => [{ -col => 'foo' => -as => 'bar' }]
);
my $sql = $expr ->to_sql;
my @bind = $expr ->to_bind;
$expr ->from_rows([[ 'c' ]]);
|
Select column with raw SQL
my $expr =
SQL::Composer::Select->new( from => 'table' , columns => [\ 'COUNT(*)' ]);
my $sql = $expr ->to_sql;
my @bind = $expr ->to_bind;
$expr ->from_rows([[ 'c' ]]);
|
Select with WHERE
For more details see SQL::Composer::Expression.
my $expr = SQL::Composer::Select->new(
from => 'table' ,
columns => [ 'a' , 'b' ],
where => [ a => 'b' ]
);
my $sql = $expr ->to_sql;
my @bind = $expr ->to_bind;
|
GROUP BY
my $expr = SQL::Composer::Select->new(
from => 'table' ,
columns => [ 'a' , 'b' ],
group_by => 'a'
);
my $sql = $expr ->to_sql;
my @bind = $expr ->to_bind;
|
ORDER BY
my $expr = SQL::Composer::Select->new(
from => 'table' ,
columns => [ 'a' , 'b' ],
order_by => 'foo'
);
my $sql = $expr ->to_sql;
my @bind = $expr ->to_bind;
|
ORDER BY
with sorting order
my $expr = SQL::Composer::Select->new(
from => 'table' ,
columns => [ 'a' , 'b' ],
order_by => [ foo => 'desc' , bar => 'asc' ]
);
my $sql = $expr ->to_sql;
my @bind = $expr ->to_bind;
|
LIMIT
and OFFSET
my $expr = SQL::Composer::Select->new(
from => 'table' ,
columns => [ 'a' , 'b' ],
limit => 5,
offset => 10
);
my $sql = $expr ->to_sql;
my @bind = $expr ->to_bind;
|
JOIN
For more details see SQL::Composer::Join.
my $expr = SQL::Composer::Select->new(
from => 'table' ,
columns => [ 'a' ],
join => [
{
source => 'table2' ,
columns => [ 'b' ],
on => [ a => '1' ],
join => [
{
source => 'table3' ,
columns => [ 'c' ],
on => [ b => '2' ]
}
]
}
]
);
my $sql = $expr ->to_sql;
my @bind = $expr ->to_bind;
$expr ->from_rows([[ 'c' , 'd' , 'e' ]]);
|
FOR UPDATE
my $expr = SQL::Composer::Select->new(
from => 'table' ,
columns => [ 'a' , 'b' ],
for_update => 1
);
my $sql = $expr ->to_sql;
my @bind = $expr ->to_bind;
};
|