import sqlmaker work from the dq branch
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / SQLMaker / Converter / Oracle.pm
1 package DBIx::Class::SQLMaker::Converter::Oracle;
2
3 use Data::Query::ExprHelpers;
4 use Moo;
5 use namespace::clean;
6
7 extends 'DBIx::Class::SQLMaker::Converter';
8
9 around _where_hashpair_to_dq => sub {
10   my ($orig, $self) = (shift, shift);
11   my ($k, $v, $logic) = @_;
12   if (ref($v) eq 'HASH' and (keys %$v == 1) and lc((keys %$v)[0]) eq '-prior') {
13     my $rhs = $self->_expr_to_dq((values %$v)[0]);
14     return $self->_op_to_dq(
15       $self->{cmp}, $self->_ident_to_dq($k), $self->_op_to_dq(PRIOR => $rhs)
16     );
17   } else {
18     return $self->$orig(@_);
19   }
20 };
21
22 around _apply_to_dq => sub {
23   my ($orig, $self) = (shift, shift);
24   my ($op, $v) = @_;
25   if ($op eq 'PRIOR') {
26     return $self->_op_to_dq(PRIOR => $self->_expr_to_dq($v));
27   } else {
28     return $self->$orig(@_);
29   }
30 };
31
32 around _insert_to_dq => sub {
33   my ($orig, $self) = (shift, shift);
34   my (undef, undef, $options) = @_;
35   my $dq = $self->$orig(@_);
36   my $ret_count = @{$dq->{returning}};
37   @{$options->{returning_container}} = (undef) x $ret_count;
38   my $into = [
39     map {
40       my $r_dq = $dq->{returning}[$_];
41       no warnings 'once';
42 ::Dwarn($r_dq);
43       local $SQL::Abstract::Converter::Cur_Col_Meta = (
44         is_Identifier($r_dq)
45           ? join('.', @{$r_dq->{elements}})
46           : ((is_Literal($r_dq) and !ref($r_dq->{literal})
47                and $r_dq->{literal} =~ /^\w+$/)
48               ? $r_dq->{literal}
49               : undef)
50       );
51       $self->_value_to_dq(\($options->{returning_container}[$_]));
52     } 0..$ret_count-1
53   ];
54   +{ %$dq, 'Data::Query::Renderer::SQL::Dialect::ReturnInto.into' => $into };
55 };
56
57 1;