NAME
DBIx::Custom::QueryBuilder - Query builder
SYNOPSIS
my $builder = DBIx::Custom::QueryBuilder->new;
my $source = "select from table {= k1} && {<> k2} || {like k3}";
my $param = {k1 => 1, k2 => 2, k3 => 3};
my $query = $sql_builder->build_query($source);
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('{');
String of tag start. Default to '{'
tag_end
my $tag_end = $builder->tag_start;
$builder = $builder->tag_start('}');
String of tag end. Default to '}'
tag_syntax
my $tag_syntax = $builder->tag_syntax;
$builder = $builder->tag_syntax($tag_syntax);
Tag syntax.
METHODS
This class is Object::Simple subclass. You can use all methods of Object::Simple
new
my $builder = DBIx::Custom::SQLBuilder->new;
my $builder = DBIx::Custom::SQLBuilder->new(%attrs);
my $builder = DBIx::Custom::SQLBuilder->new(\%attrs);
Create a instance.
build_query
my $query = $builder->build_query($source);
Build DBIx::Custom::Query object.
Example:
Source:
my $query = $builder->build_query(
"select * from table where {= title} && {like author} || {<= price}")
Query:
$qeury->sql : "select * from table where title = ? && author like ? price <= ?;"
$query->columns : ['title', 'author', 'price']
register_tag_processor
$builder = $builder->register_tag_processor($tag_processor);
Register tag processor.
$builder->register_tag_processor(
'?' => sub {
my $args = shift;
# Do something
# Expanded tag and column names
return ($expand, $columns);
}
);
Tag processor receive arguments in tags and must return expanded tag and column names.
Tags
{? 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 NAME3} -> (NAME1, NAME2, NAME3) values (?, ?, ?)
{update NAME1 NAME2 NAME3} -> set NAME1 = ?, NAME2 = ?, NAME3 = ?