1 package DBIx::Class::ResultSet;
11 my ($it_class, $db_class, $attrs) = @_;
12 #use Data::Dumper; warn Dumper(@_);
13 $it_class = ref $it_class if ref $it_class;
14 $attrs = { %{ $attrs || {} } };
15 my $cols = [ $db_class->_select_columns ];
19 cond => $attrs->{where},
23 bless ($new, $it_class);
24 $new->pager if ($attrs->{page});
30 my ($db_class, $attrs) = @{$self}{qw/class attrs/};
32 $attrs->{rows} = $self->pager->entries_per_page;
33 $attrs->{offset} = $self->pager->skipped;
35 return $self->{cursor}
36 ||= $db_class->storage->select($db_class->_table_name, $self->{cols},
37 $attrs->{where},$attrs);
41 my ($self, $min, $max) = @_;
42 my $attrs = { %{ $self->{attrs} || {} } };
43 $self->{class}->throw("Can't slice without where") unless $attrs->{where};
44 $attrs->{offset} = $min;
45 $attrs->{rows} = ($max ? ($max - $min + 1) : 1);
46 my $slice = $self->new($self->{class}, $attrs);
47 return (wantarray ? $slice->all : $slice);
52 my @row = $self->cursor->next;
54 return $self->{class}->_row_to_object($self->{cols}, \@row);
59 my $db_class = $self->{class};
60 my $attrs = { %{ $self->{attrs} } };
61 unless ($self->{count}) {
62 # offset and order by are not needed to count
63 delete $attrs->{$_} for qw/offset order_by/;
65 my @cols = 'COUNT(*)';
66 $self->{count} = $db_class->storage->select_single($db_class->_table_name, \@cols,
67 $self->{cond}, $attrs);
69 return 0 unless $self->{count};
70 return $self->{pager}->entries_on_this_page if ($self->{pager});
71 return ( $attrs->{rows} && $attrs->{rows} < $self->{count} )
78 return map { $self->{class}->_row_to_object($self->{cols}, $_); }
89 return $_[0]->reset->next;
94 $_->delete for $self->all;
98 *delete_all = \&delete; # Yeah, yeah, yeah ...
102 my $attrs = $self->{attrs};
103 delete $attrs->{offset};
104 my $rows_per_page = delete $attrs->{rows} || 10;
105 $self->{pager} ||= Data::Page->new(
106 $self->count, $rows_per_page, $attrs->{page} || 1);
107 $attrs->{rows} = $rows_per_page;
108 return $self->{pager};
112 my ($self, $page) = @_;
113 my $attrs = $self->{attrs};
114 $attrs->{page} = $page;
115 return $self->new($self->{class}, $attrs);