incubator-couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael Hendricks <mich...@ndrix.org>
Subject Re: Net::CouchDb and views
Date Mon, 23 Feb 2009 20:06:32 GMT
On Mon, Feb 23, 2009 at 12:06:29PM +0100, Wout Mertens wrote:
> I'm trying to convert a Perl script from RDBMS to CouchDB and thus I
> turned to Net::CouchDb (btw, why CouchDb and not CouchDB?). It
> doesn't  currently seem to have an easy interface for reading views,
> so you have to use the call() function which does a plain REST call.
>
> The most difficult part to find out was how to handle the results from a 
> call, since they're a pointer to a hash and the rows member is a pointer 
> to an array of hashes. It would be nice if that could be abstracted away, 
> for example behind an iterator interface.

Net::CouchDb on CPAN hasn't been updated in a long time.  There's a
complete rewrite of that module named Net::CouchDB hosted on GitHub.
It will eventually replace that module.
http://github.com/mndrix/net-couchdb

With that module, your specific use case would be something like:

    my $results = $design->view('all');
    my %images;
    while ( my $row = $view->next ) {
        $images{ $row->{id} } = $row->document;
    }

include_docs isn't supported yet, but patches are welcome.  I've cc'd
the module's Google Group.


> The images/all view is a simple
>    function(doc) { doc.imgvmxpath && doc.imgname && emit(null, null);
}
> which selects all documents that have those 2 keys in them.
>
> I thought that emitting (null,null) and instead using the include_docs  
> option would keep the size of the view results to a minimum.
> Is that thinking correct? Does this incur overhead in different ways?

Yes, I think that's the best way to get the information you want out
of CouchDB.

-- 
Michael


Mime
View raw message