initial commit, attempting to get test deploy working
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / SQLMaker / PostgreSQL.pm
1 package
2   DBIx::Class::SQLMaker::PostgreSQL;
3
4 use strict;
5 use warnings;
6 use base qw( DBIx::Class::SQLMaker );
7
8 sub new {
9   my $self = shift;
10   my %opts = (ref $_[0] eq 'HASH') ? %{$_[0]} : @_;
11
12   $self->next::method(\%opts);
13 }
14
15 sub _assemble_binds {
16   my $self = shift;
17    return map { @{ (delete $self->{"${_}_bind"}) || [] } }
18    (qw/select from where with_recursive group having order limit/);
19 }
20
21 sub _parse_rs_attrs {
22   my $self = shift;
23   my ($rs_attrs) = @_;
24
25   my ($cb_sql, @cb_bind) = $self->_with_recursive($rs_attrs);
26   push @{$self->{with_recursive_bind}}, @cb_bind;
27
28   my $sql = $self->next::method(@_);
29
30   return "$cb_sql $sql";
31 }
32
33 # with_recursive =>{
34 #   -columns => [ ... ],
35 #   -nrt     => $blargh->search....
36 #   -rt      => $blargh->search...
37 #   -union_all 1|0
38 sub _with_recursive {
39   my ($self, $attrs) = @_;
40
41   my $sql = '';
42   my @bind;
43
44   if ( ref($attrs) eq 'HASH' ) {
45     if ( $attrs->{'with_recursive'} ) {
46       my $with_recursive = $attrs->{'with_recursive'};
47       my @fields = @{$with_recursive->{'-columns'}};
48       my $nrt    = $with_recursive->{'-nrt'};
49       my $rt     = $with_recursive->{'-rt'};
50       my $union  = $with_recursive->{'-union_all'};
51 #      my ($wr, @wb) = $self->_recurse_where( $attrs->{'with_recursive'} );
52       my ($with_nrt_sql, @with_nrt_bind) = $nrt->as_query;
53       my ($with_rt_sql, @with_rt_bind)   = $rt->as_query;
54       push @bind, @with_nrt_bind;
55       push @bind, @with_rt_bind;
56       $sql .= $self->_sqlcase(' with recursive ') . ' temp_wr_query ' . '(' .
57               join(', ', @fields) . ') ' . $self->_sqlcase('as') . ' ( ';
58       $sql .= $with_nrt_sql;
59       $sql .= $self->_sqlcase(' union all ');
60       $sql .= $with_rt_sql;
61       $sql .= ' ) ';
62
63       return ($sql, @bind);
64     }
65   }
66
67   return wantarray ? ($sql, @bind) : $sql;
68
69 }
70 1;