AnyEvent-CouchDB
view release on metacpan or search on metacpan
eg/replicate.pl view on Meta::CPAN
my $l = AnyEvent::CouchDB::Stream->new(
url => $host_orig,
database => $db_orig,
on_change => sub {
my $change = shift;
say "document "
. $change->{id}
. " with sequence "
. $change->{seq}
. " have been updated";
$couchdb_orig->open_doc( $change->{id} )->cb(
sub {
my $data = $_[0]->recv;
$couchdb_dest->save_doc($data);
}
);
},
);
$cv->recv;
lib/AnyEvent/CouchDB/Database.pm view on Meta::CPAN
This method is used to request multiple CouchDB documents by their C<ids>, and
it returns a condvar.
=head3 $cv = $db->save_doc($doc, [ \%options ])
This method can be used to either create a new CouchDB document or update an
existing CouchDB document. It returns a condvar.
Note that upon success, C<$doc> will have its C<_id> and C<_rev> keys
updated. This allows you to save C<$doc> repeatedly using the same hashref.
=head3 $cv = $db->remove_doc($doc, [ \%options ])
This method is used to remove a document from the database, and it returns a
condvar.
=head3 $cv = $db->attach($doc, $attachment, \%options)
This method adds an attachment to a document, and it returns a condvar. Note
that the C<%options> are NOT optional for this method. You must provide a
lib/AnyEvent/CouchDB/Database.pm view on Meta::CPAN
This method is used to request a hashref that contains an index of all the
documents in the database. Note that you B<DO NOT> get the actual documents.
Instead, you get their C<id>s, so that you can fetch them later.
To get the documents in the result, set parameter C<include_docs> to 1 in
the C<\%options>.
=head3 $cv = $db->all_docs_by_seq([ \%options ])
This method is similar to the C<all_docs> method, but instead of using document ids
as a key, it uses update sequence of the document instead. (The update_seq is an
integer that is incremented every time the database is updated. You can get the
current update_seq of a database by calling C<info>.)
This method returns a condvar.
=head3 $cv = $db->query($map, [ $reduce ], [ $language ], [ \%options ])
This method lets you send ad-hoc queries to CouchDB. You have to at least give
it a map function. If you pass in a string, it'll assume the function is
written in JavaScript (unless you tell it otherwise). If you pass in a
coderef, it will be turned into a string, and you had better have a Perl-based
lib/AnyEvent/CouchDB/Stream.pm view on Meta::CPAN
AnyEvent::CouchDB::Stream - Watch changes from a CouchDB database.
=head1 SYNOPSIS
use AnyEvent::CouchDB::Stream;
my $listener = AnyEvent::CouchDB::Stream->new(
url => 'http://localhost:5984',
database => 'test',
on_change => sub {
my $change = shift;
warn "document $change->{_id} updated";
},
on_keepalive => sub {
warn "ping\n";
},
timeout => 1,
);
=head1 DESCRIPTION
AnyEvent::CouchDB::Stream is an interface to the CouchDB B<changes> database API.
( run in 0.766 second using v1.01-cache-2.11-cpan-0a6323c29d9 )