# top level special ops are illegal in general
puke "Illegal use of top-level '-$op'"
if List::Util::first { $op =~ $_->{regex} } @{$self->{special_ops}};
+ if (my $us = List::Util::first { $op =~ $_->{regex} } @{$self->{unary_ops}}) {
+ return { -op => [ $op, $v ] };
+ }
}
if ($k eq '-value' and my $m = our $Cur_Col_Meta) {
return +{ -bind => [ $m, $v ] };
if (my $us = List::Util::first { $vk =~ $_->{regex} } @{$self->{user_special_ops}}) {
return { -op => [ $vk, { -ident => $k }, $vv ] };
}
+ if (my $us = List::Util::first { $vk =~ $_->{regex} } @{$self->{unary_ops}}) {
+ return { -op => [
+ $self->{cmp},
+ { -ident => $k },
+ { -op => [ $vk, $vv ] }
+ ] };
+ }
if (ref($vv) eq 'ARRAY') {
my ($logic, @values) = (
(defined($vv->[0]) and $vv->[0] =~ /^-(and|or)$/i)
unless my ($k) = map $_->{-ident}, grep ref($_) eq 'HASH', $args[0];
return $self->${\($us->{handler})}($k, $op, $args[1]);
}
+ if (my $us = List::Util::first { $op =~ $_->{regex} } @{$self->{unary_ops}}) {
+ return $self->${\($us->{handler})}($op, $args[0]);
+ }
my $final_op = $op =~ /^(?:is|not)_/ ? join(' ', split '_', $op) : $op;
if (@args == 1 and $op !~ /^(and|or)$/) {
my ($expr_sql, @bind) = $self->_render_expr($args[0]);
}
},
+], unary_ops => [
+ # unary op from Mojo::Pg
+ {regex => qr/^json$/i,
+ handler => sub { '?', { json => $_[2] } }
+ },
]);
my @tests = (
bind => [],
},
+ #3
+ { where => { foo => { -json => { bar => 'baz' } } },
+ stmt => "WHERE foo = ?",
+ bind => [ { json => { bar => 'baz' } } ],
+ },
+
+ #4
+ { where => { foo => { '@>' => { -json => { bar => 'baz' } } } },
+ stmt => "WHERE foo @> ?",
+ bind => [ { json => { bar => 'baz' } } ],
+ },
+
);
for (@tests) {