NAME
DBIx::Custom::QueryBuilder - Query builder
SYNOPSIS
my $builder = DBIx::Custom::QueryBuilder->new;
my $query = $builder->build_query(
"select from table {= k1} && {<> k2} || {like k3}"
);
ATTRIBUTES
tag_processors
my $tag_processors = $builder->tag_processors;
$builder = $builder->tag_processors(\%tag_processors);
Tag processors.
tag_start
my $tag_start = $builder->tag_start;
$builder = $builder->tag_start('{');
Tag start charactor. Default to '{'.
tag_end
my $tag_end = $builder->tag_start;
$builder = $builder->tag_start('}');
Tag end charactor. Default to '}'.
METHODS
DBIx::Custom::QueryBuilder inherits all methods from Object::Simple and implements the following new ones.
build_query
my $query = $builder->build_query($source);
Create a new DBIx::Custom::Query object from SQL source. SQL source contains tags, such as {= title}, {like author}.
Example:
SQL source
"select * from table where {= title} && {like author} || {<= price}"
Query
{
sql => "select * from table where title = ? && author like ? price <= ?;"
columns => ['title', 'author', 'price']
}
register_tag_processor
$builder->register_tag_processor(\%tag_processors);
$builder->register_tag_processor(%tag_processors);
Register tag processor.
Examples:
$builder->register_tag_processor(
'?' => sub {
my $column = shift;
return ['?', [$column]];
}
);
See DBIx::Custom::QueryBuilder::TagProcessors about tag processor.
Tags
You can use the following tags in SQL source.
[Tags] [Replaced]
{? NAME} -> ?
{= NAME} -> NAME = ?
{<> NAME} -> NAME <> ?
{< NAME} -> NAME < ?
{> NAME} -> NAME > ?
{>= NAME} -> NAME >= ?
{<= NAME} -> NAME <= ?
{like NAME} -> NAME like ?
{in NAME COUNT} -> NAME in [?, ?, ..]
{insert NAME1 NAME2} -> (NAME1, NAME2) values (?, ?)
{update NAME1 NAME2} -> set NAME1 = ?, NAME2 = ?