1 package # hide from PAUSE
2 DBIx::Class::SQLMaker::PostgreSQL;
6 use base qw( DBIx::Class::SQLMaker );
10 my %opts = (ref $_[0] eq 'HASH') ? %{$_[0]} : @_;
11 push @{$opts{special_ops}}, {
12 regex => qr/^with_recursive$/i,
13 handler => '_with_recursive',
16 $self->next::method(\%opts);
21 return map { @{ (delete $self->{"${_}_bind"}) || [] } }
22 (qw/select from where with_recursive group having order limit/);
27 warn "INSIDE RS ATTRS";
30 my ($cb_sql, @cb_bind) = $self->_with_recursive($rs_attrs);
31 push @{$self->{with_recursive_bind}}, @cb_bind;
33 my $sql = $self->next::method(@_);
35 return "$cb_sql $sql";
39 my ($self, $attrs) = @_;
41 warn "INSIDE WITH RECURSIVE";
45 if ( ref($attrs) eq 'HASH' ) {
46 if ( $attrs->{'with_recursive'} ) {
47 my $with_recursive = $attrs->{'with_recursive'};
48 my @fields = @{$with_recursive->{'-columns'}};
49 my $nrt = $with_recursive->{'-initial'};
50 my $rt = $with_recursive->{'-recursive'};
51 my $union = $with_recursive->{'-union_all'};
52 # my ($wr, @wb) = $self->_recurse_where( $attrs->{'with_recursive'} );
53 my ($with_nrt_sql, @with_nrt_bind) = $nrt->as_query;
54 my ($with_rt_sql, @with_rt_bind) = $rt->as_query;
55 push @bind, @with_nrt_bind;
56 push @bind, @with_rt_bind;
57 $sql .= $self->_sqlcase(' with recursive ') . ' temp_wr_query ' . '(' .
58 join(', ', @fields) . ') ' . $self->_sqlcase('as') . ' ( ';
59 $sql .= $with_nrt_sql;
60 $sql .= $self->_sqlcase(' union all ') if $union;
68 return wantarray ? ($sql, @bind) : $sql;