++ed by:
STAUGAARD XIAOCANG AZJADFTRE FUKAI

4 PAUSE users
7 non-PAUSE users.

Yuki Kimoto

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.

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}.

{ and } is reserved. If you use these charactors, you must escape them using '\'. Note that '\' is already perl escaped charactor, so you must write '\\'.

    'select * from books \\{ something statement \\}'

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_param

Insert parameter tag.

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

update_param

Updata parameter tag.

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