Skip to content

Commit

Permalink
added { -or => xxx } syntax for where cluase
Browse files Browse the repository at this point in the history
  • Loading branch information
xaicron committed Jun 4, 2012
1 parent f090eca commit ea5f2f3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/SQL/Format.pm
Expand Up @@ -188,8 +188,11 @@ sub _where {
my $ret = join ' AND ', map {
my $org_key = $_;
my $no_paren = 0;
my ($k, $v) = (_quote($org_key), $val->{$_});
if (ref $v eq 'ARRAY') {
my ($k, $v) = (_quote($org_key), $val->{$org_key});
if (uc $org_key eq '-OR') {
$k = $self->_where($v, $bind);
}
elsif (ref $v eq 'ARRAY') {
if (
ref $v->[0]
or (($v->[0]||'') eq '-and')
Expand Down
20 changes: 20 additions & 0 deletions lib/SQL/Format/Spec.pod
Expand Up @@ -237,6 +237,26 @@ For example:
WHERE (`id` > ?) OR (`id` < ?)
[qw/10 20/]

=head2 where special key -or

# single
WHERE %w
+{ -or => { a => 1, b => 2 } }
WHERE ((`a` = ?) AND (`b` = ?))
[qw/1 2/]

# multi
WHERE %w
+{ -or => [ { a => 1, b => 2 }, { c => 3, d => 4 } ] }
WHERE (((`a` = ?) AND (`b` = ?)) OR ((`c` = ?) AND (`d` = ?)))
[qw/1 2 3 4/]

# multi complex
WHERE %w
+{ -or => [ { a => 1, b => 2 }, { c => 3, d => 4 } ], foo => 'bar' }
WHERE (((`a` = ?) AND (`b` = ?)) OR ((`c` = ?) AND (`d` = ?))) AND (`foo` = ?)
[qw/1 2 3 4 bar/]

=head2 where multiple

# basic
Expand Down

0 comments on commit ea5f2f3

Please sign in to comment.