The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

DBIx::Custom::Where - Where clause

SYNOPSYS

    my $where = DBIx::Custom::Where->new;
    my $string_where = "$where";

ATTRIBUTES

clause

    my $clause = $where->clause;
    $where = $where->clause(
        ['and',
            'title = :title', 
            ['or', 'date < :date', 'date > :date']
        ]
    );

Where clause. Above one is expanded to the following SQL by to_string If all parameter names is exists.

    "where ( title = :title and ( date < :date or date > :date ) )"

param

    my $param = $where->param;
    $where = $where->param({
        title => 'Perl',
        date => ['2010-11-11', '2011-03-05'],
    });

dbi

    my $dbi = $where->dbi;
    $where = $where->dbi($dbi);

DBIx::Custom object.

METHODS

DBIx::Custom::Where inherits all methods from Object::Simple and implements the following new ones.

if EXPERIMENTAL

    my $if = $where->if($condition);
    $where->if($condition);

if is default of map method if option.

map EXPERIMENTAL

Mapping parameter key and value. param is converted based on, so this method must be called after param is set. Set if if you need before map method call.

    $where->map(
        'id' => 'book.id',
        'author' => ['book.author' => sub { '%' . $_[0] . '%' }],
        'price' => [
            'book.price', {if => sub { length $_[0] }
        ]
    );

The followin parameter

    {
        id => 1,
        auhtor => 'Ken',
        price => 1000
    }

is converted to

    {
        'book.id' => 1,
        'book.author' => '%Ken%',
        'book.price' => 1000
    }

The following option is available.

  • if

    By default, if parameter key is exists, mapping is done.

        if => 'exists';

    In case defined is specified, if the value is defined, mapping is done.

        if => 'defined';

    In case length is specified, the value is defined and the length is bigger than 0, mappting is done.

        if => 'length';

    You can also subroutine like sub { defined $_[0] } for mappging.

        if => sub { defined $_[0] }

to_string

    $where->to_string;

Convert where clause to string.

double quote is override to execute to_string method.

    my $string_where = "$where";