[Dbix-class] Does DBIx::Class support postgresql arrays and ANY
syntax?
Adam Witney
awitney at sgul.ac.uk
Wed Feb 18 11:44:22 GMT 2009
On 18 Feb 2009, at 11:18, Joel Bernstein wrote:
> 2009/2/18 Joel Bernstein <joel at fysh.org>:
>> Why do you feel that is a hack? It seems equivalent to your
>> original query..
>> $rs->search({ 1 => \'sql literal here', })
>> It's a perfectly common idiom so I'm not too sure why you feel it's
>> hacky?
>
> I suppose you meant, it feels like a hack to use a SQL literal to
> mimic the original query, and does DBIC have a more logical way to
> achieve it?
>
Yes, thats what i meant.
I did manage to write my own special operator using SQL::Abstract
(1.49_02) which would handle the ANY keyword, but i couldn't see how i
could include this such that the DBIx::Class generated code could use
it, like so:
my $sql = SQL::Abstract->new(special_ops => [
{regex => qr/^any$/i,
handler => sub {
my ($self, $field, $op, $arg) = @_;
$arg = [$arg] if not ref $arg;
my $label = $self->_quote($field);
my ($placeholder) = $self->_convert('?');
my $sql = $placeholder . " = " . $self-
>_sqlcase('any') . "($label) ";
my @bind = $self->_bindtype($field, @$arg);
return ($sql, @bind);
}
},
]);
my %where = (
'my_array_col' => { -any => '1' }
);
my($stmt, @bind) = $sql->where(\%where);
can I define this special_ops within my DBIx::Class generated code?
thanks again for your help
adam
More information about the DBIx-Class
mailing list