SQL::OOP::Where - WHERE factory class
use SQL::OOP::Where; my $where = SQL::OOP::Where->new(); my $cond1 = $where->cmp($operator, $field, $value); my $cond2 = $where->is_null('some_field'); my $cond3 = $where->is_not_null('some_field'); my $cond4 = $where->between('some_field', 1, 2); my $cond5 = $where->in('some_field', [1, 2, 3]); my $sql = $cond1->to_string; my @bind = $cond1->bind; # combine conditions my $cond7 = $where->or($cond1, $cond2); $cond7->append($cond3); my $cond8 = $where->and($cond7, $where->and($cond4, $cond5)); my $sql = $cond8->to_string; my @bind = $cond8->bind; # SQL::Abstract style my $seed = [a => 'b', c => 'd']; my $cond10 = $where->and_abstract($seed); # default operator is '=' my $cond11 = $where->and_abstract($seed, "LIKE"); my $cond12 = $where->or_abstract($seed); # default operator is '=' my $cond13 = $where->or_abstract($seed, "LIKE"); my $sql = $cond13->to_string; my @bind = $cond13->bind;
SQL::OOP::Where is a Factory Class for WHERE clause elements. All methods of this returns SQL::OOP::Base or SQL::OOP::Array.
Returns SQL::OOP::Where instance. This class instance is just for convenience. All methods in this class also can be called as Class method.
my $util = SQL::OOP::Where->new;
Generates 1 operator expression.
my $where = SQL::OOP::Where->new; $where->cmp('=', 'col1', 'value') # "col1" = ? $where->cmp('=', ['table', 'col1'], 'value') # "table"."col1" = ? $where->cmp('=', $subquery, $subquery)
Generates 1 operator expression with sub query in value.
Generates IN clause
my $where = SQL::OOP::Where->new; $where->in('col1', ['candidate1', 'candidate2']) # "col1" IN (?, ?) $where->in(['table', 'col1'], ['c1', 'c2']) # "table"."col1" IN (?, ?)
Generates NOT IN clause
my $where = SQL::OOP::Where->new; $where->not_in('col1', ['val1', 'val2']) # "col1" NOT IN (?, ?) $where->not_in(['tbl', 'col1'], ['v1', 'v2']) # "tbl"."col1" NOT IN (?, ?)
Generates BETWEEN clause
my $where = SQL::OOP::Where->new; $where->between('col1', 5, 10]) # "col1" BETWEEN ? AND ? $where->between(['table', 'col1'], 5, 10) # "table"."col1" BETWEEN ? AND ?
Generates IS NOT NULL clause
my $where = SQL::OOP::Where->new; $where->is_not_null('col1') # "col1" IS NOT NULL $where->is_not_null(['table', 'col1']) # "table"."col1" IS NOT NULL
Generates IS NULL clause
my $where = SQL::OOP::Where->new; $where->is_null('col1') # "col1" IS NULL $where->is_null(['table', 'col1']) # "table"."col1" IS NULL
Generates OR expression in SQL::OOP::Array
Generates OR expression in SQL::OOP::Array by hash
Generates OR expression in SQL::OOP::Array by key-value array
Generates AND expression in SQL::OOP::Array
Generates AND expression in SQL::OOP::Array by hash
Generates AND expression in SQL::OOP::Array by key-value array
To install SQL::OOP, copy and paste the appropriate command in to your terminal.
cpanm
cpanm SQL::OOP
CPAN shell
perl -MCPAN -e shell install SQL::OOP
For more information on module installation, please visit the detailed CPAN module installation guide.