NAME

DBIx::Custom::Where - Where clause

SYNOPSYS

# Create DBIx::Custom::Where object
my $where = $dbi->where;

# Clause
$where->clause(['and', 'title like :title', 'price = :price']);
$where->clause(['and', ':title{like}', ':price{=}']);

# Stringify where clause
my $where_clause = "$where";
my $where_clause = $where->to_string;
  # -> where title like :title and price = :price

# Only price condition
$where->clause(['and', ':title{like}', ':price{=}']);
$where->param({price => 1900});
  # -> where price = :price

# Only title condition
$where->clause(['and', ':title{like}', ':price{=}']);
$where->param({title => 'Perl'});
  # -> where title like :title

# Nothing
$where->clause(['and', ':title{like}', ':price{=}']);
$where->param({});
  # => Nothing

# or condition
$where->clause(['or', ':title{like}', ':price{=}']);
  # -> where title = :title or price like :price

# More than one parameter
$where->clause(['and', ':price{>}', ':price{<}']);
$where->param({price => [1000, 2000]});
  # -> where price > :price and price < :price

# Only first condition
$where->clause(['and', ':price{>}', ':price{<}']);
$where->param({price => [1000, $dbi->not_exists]});
  # -> where price > :price

# Only second condition
$where->clause(['and', ':price{>}', ':price{<}']);
$where->param({price => [$dbi->not_exists, 2000]});
  # -> where price < :price

# More complex condition
$where->clause(
  [
    'and',
    ':price{=}',
    ['or', ':title{=}', ':title{=}', ':title{=}']
  ]
);
  # -> pirce = :price and (title = :title or title = :title or tilte = :title)

# Using Full-qualified column name
$where->clause(['and', ':book.title{like}', ':book.price{=}']);
  # -> book.title like :book.title and book.price = :book.price

ATTRIBUTES

clause

my $clause = $where->clause;
$where = $where->clause(
  ['and',
    ':title{=}', 
    ['or', ':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.

join

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

join information. This values is addd to select method join option values.

$where->join(['left join author on book.author = authro.id']);

METHODS

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

to_string

$where->to_string;

Convert where clause to string.

double quote is override to execute to_string method.

my $string_where = "$where";