You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by Wout Mertens <wm...@cisco.com> on 2009/02/23 12:06:29 UTC
Net::CouchDb and views
Hi all,
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.
Anyway, this is what I have right now:
my $answer = $dbh->call('GET','_view/images/all?
include_docs=true');
if ($answer) {
%images = ();
for my $i (@{$answer->{rows}}) {
$images{$i->{id}} = $i->{doc};
}
}
Is this currently the best way to do it?
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?
Thanks,
Wout.
Re: Net::CouchDb and views
Posted by Michael Hendricks <mi...@ndrix.org>.
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
Re: Net::CouchDb and views
Posted by James Marca <jm...@translab.its.uci.edu>.
On Tue, Feb 24, 2009 at 08:54:54AM +1300, lenz wrote:
> 1+ for DB::CouchDB even though POST views are not implemented. i use a fair
> mix of DB::CouchDB and direct REST calls
yeah, +1 from me to for using DB-CouchDB-Schema, but you have to hack
the usage of LWP::UserAgent->new() if you're testing out using admin
accounts on your couchdb server (like I am).
James
--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
Re: Net::CouchDb and views
Posted by lenz <no...@googlemail.com>.
1+ for DB::CouchDB even though POST views are not implemented. i use a fair
mix of DB::CouchDB and direct REST calls
cheers
lenz
On Tue, Feb 24, 2009 at 5:13 AM, Jeremy Wall <jw...@google.com> wrote:
> On Mon, Feb 23, 2009 at 5:06 AM, Wout Mertens <wm...@cisco.com> wrote:
> > Hi all,
> >
> > 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.
>
> I do this in DB::CouchDB::Schema. (shameless plug).
>
> >
> > Anyway, this is what I have right now:
> > my $answer = $dbh->call('GET','_view/images/all?include_docs=true');
> > if ($answer) {
> > %images = ();
> > for my $i (@{$answer->{rows}}) {
> > $images{$i->{id}} = $i->{doc};
> > }
> > }
> >
> > Is this currently the best way to do it?
> >
> > 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?
> >
> > Thanks,
> >
> > Wout.
> >
>
--
iWantMyName.com
painless domain registration (finally)
Re: Net::CouchDb and views
Posted by Jeremy Wall <jw...@google.com>.
On Mon, Feb 23, 2009 at 5:06 AM, Wout Mertens <wm...@cisco.com> wrote:
> Hi all,
>
> 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.
I do this in DB::CouchDB::Schema. (shameless plug).
>
> Anyway, this is what I have right now:
> my $answer = $dbh->call('GET','_view/images/all?include_docs=true');
> if ($answer) {
> %images = ();
> for my $i (@{$answer->{rows}}) {
> $images{$i->{id}} = $i->{doc};
> }
> }
>
> Is this currently the best way to do it?
>
> 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?
>
> Thanks,
>
> Wout.
>