AnyEvent-CouchDB
view release on metacpan or search on metacpan
my $last_row = $docs->{rows}->[$end_idx];
$startkey = $last_row->{key};
delete $docs->{rows}->[$end_idx] if $end_idx == $count;
last if ($oldend eq $startkey);
$oldend = $startkey;
return $docs;
}
}
sub all_view {
my ($self, $view, $count, $firstkey, $lastkey, $firstdocid) = @_;
$count ||= 10;
$firstkey ||= undef;
$lastkey ||= undef;
$firstdocid ||= undef;
$is_key_reduced ||= 0;
my $startkey = $firstkey;
my $startkey_docid = $firstdocid;
my $endkey = undef;
my $next = 1;
my $db = $self->{db};
iterator {
last unless ($next);
my $options = sub {
return {
%{
($startkey_docid)
? {
count => $count,
skip => 1,
startkey => $startkey,
startkey_docid => $startkey_docid
}
: { count => $count, startkey => $startkey }
},
%{ ($lastkey) ? { endkey => $lastkey } : {} }
};
}
->();
my $docs = $db->view($view, $options)->recv;
my $total_rows = $docs->{total_rows};
my $offset = $docs->{offset};
my $viewrows = $docs->{rows};
my $first_row = $viewrows->[0];
$startkey = $first_row->{key};
my $last_row = $viewrows->[ $#{$viewrows} ];
$endkey = $last_row->{key};
$startkey_docid = $last_row->{id};
$startkey = $endkey;
if ( defined $endkey && $endkey eq $lastkey
|| ($offset + $count) >= $total_rows
|| !$startkey_docid)
{
$next = 0;
$startkey_docid = undef;
$startkey = undef;
}
return {
rows => $viewrows,
next_startkey => $startkey,
next_startkey_docid => $startkey_docid,
rows_per_loop => $count,
total_rows => $total_rows
};
}
}
sub key_reduced_view {
my $self = shift;
my $iterator = $self->all_view(@_);
iterator {
lib/AnyEvent/CouchDB.pm view on Meta::CPAN
=item key=keyvalue
This lets you pick out one document with the specified key value.
=item startkey=keyvalue
This makes it so that lists start with a key value that is greater than or
equal to the specified key value.
=item startkey_docid=docid
This makes it so that lists start with a document with the specified docid.
=item endkey=keyvalue
This makes it so that lists end with a key value that is less than or
equal to the specified key value.
=item count=max_rows_to_return
This limits the number of results to the specified number or less.
If count is set to 0, you won't get any rows, but you I<will> get
lib/AnyEvent/CouchDB.pm view on Meta::CPAN
=item descending=boolean
Views are sorted by their keys in ascending order. However, if you set
C<descending> to C<true>, they'll come back in descending order.
=item skip=rows_to_skip
The skip option should only be used with small values, as skipping a large
range of documents this way is inefficient (it scans the index from the
startkey and then skips N elements, but still needs to read all the index
values to do that). For efficient paging use startkey and/or startkey_docid.
=back
You may also put subroutine references in the C<success> and C<error> keys of
this hashref, and they will be called upon success or failure of the request.
=head2 Documents Are Plain Hashrefs
( run in 1.070 second using v1.01-cache-2.11-cpan-de7293f3b23 )