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.

Example:

$builder->register_tag_processor(
    '?' => sub {
        my $column = shift;
        
        return ['?', [$column]];
    }
);

See also DBIx::Custom::QueryBuilder::TagProcessors to know tag processor.

Tags

The following tags is available.

?

Placeholder tag.

{? NAME}    ->   ?

=

Equal tag.

{= NAME}    ->   NAME = ?

<>

Not equal tag.

{<> NAME}   ->   NAME <> ?

<

Lower than tag

{< NAME}    ->   NAME < ?

>

Greater than tag

{> NAME}    ->   NAME > ?

>=

Greater than or equal tag

{>= NAME}   ->   NAME >= ?

<=

Lower than or equal tag

{<= NAME}   ->   NAME <= ?

like

Like tag

{like NAME}   ->   NAME like ?

in

In tag.

{in NAME COUNT}   ->   NAME in [?, ?, ..]

insert

Insert tag.

{insert NAME1 NAME2}   ->   (NAME1, NAME2) values (?, ?)

update

Updata tag.

{update NAME1 NAME2}   ->   set NAME1 = ?, NAME2 = ?