Skip to content

Commit

Permalink
Updated Database->view method to work with current version of couchdb
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan-Felix Wittmann authored and Jan-Felix Wittmann committed Mar 22, 2009
1 parent e4336e0 commit e1a22f3
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions lib/AnyEvent/CouchDB/Database.pm
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ sub query {
my ($self, $map_fun, $reduce_fun, $language, $options) = @_;
my ($cv, $cb) = cvcb($options);
$language ||= (ref($map_fun) eq 'CODE') ? 'text/perl' : 'javascript';
my $body = {
my $body = {
language => $language,
map => $code_to_string->($map_fun),
};
Expand All @@ -283,8 +283,20 @@ sub query {

sub view {
my ($self, $name, $options) = @_;
my ($cv, $cb) = cvcb($options);
http_get($self->uri."_view/".$name.$query->($options), $cb);
my ($cv, $cb) = cvcb($options);
my ($dname, $vname) = split('/', $name);
my $uri = $self->uri."/_design/".$dname."/_view/".$vname;
if ($options->{keys}) {
my $body = { keys => $options->{keys} };
http_request(
'POST' => $uri,
headers => { 'Content-Type' => 'application/json' },
body => encode_json($body),
$cb
);
} else {
http_get($uri.$query->($options), $cb);
}
$cv;
}

Expand Down

1 comment on commit e1a22f3

@beppu
Copy link

@beppu beppu commented on e1a22f3 Mar 22, 2009

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this patch. When they release CouchDB 0.9, I’ll upload a new version to CPAN that includes this patch.

Please sign in to comment.