DB-CouchDB-Schema
view release on metacpan or search on metacpan
lib/DB/CouchDB.pm view on Meta::CPAN
=head2 create_doc
creates a doc in the database. The document will have an automatically assigned
id/name.
my $result = $db->create_doc($doc) #returns a DB::CouchDB::Result object
=cut
sub create_doc {
my $self = shift;
my $doc = shift;
my $jdoc = $self->json()->encode($doc);
return DB::CouchDB::Result->new(
$self->_call(POST => $self->_uri_db(), $jdoc)
);
}
=head2 temp_view
runs a temporary view.
my $results = $db->temp_view($view_object);
=cut
sub temp_view {
my $self = shift;
my $doc = shift;
my $jdoc = $self->json()->encode($doc);
return DB::CouchDB::Iter->new(
$self->_call(POST => $self->uri_db_temp_view(), $jdoc)
);
}
=head2 create_named_doc
creates a doc in the database, the document will have the id/name you specified
my $result = $db->create_named_doc($doc, $docname) #returns a DB::CouchDB::Result object
=cut
#TODO this really needs to have the same API as all the others. $name first then $doc
sub create_named_doc {
my $self = shift;
my $doc = shift;
my $name = shift;
my $jdoc = $self->json()->encode($doc);
return DB::CouchDB::Result->new($self->_call(PUT => $self->_uri_db_doc($name), $jdoc));
}
=head2 update_doc
Updates a doc in the database.
my $result = $db->update_doc($docname, $doc) #returns a DB::CouchDB::Result object
=cut
sub update_doc {
my $self = shift;
my $name = shift;
my $doc = shift;
my $jdoc = $self->json()->encode($doc);
return DB::CouchDB::Result->new($self->_call(PUT => $self->_uri_db_doc($name), $jdoc));
}
=head2 delete_doc
Deletes a doc in the database. you must supply a rev parameter to represent the
revision of the doc you are updating. If the revision is not the current revision
of the doc the update will fail.
my $result = $db->delete_doc($docname, $rev) #returns a DB::CouchDB::Result object
=cut
sub delete_doc {
my $self = shift;
my $doc = shift;
my $rev = shift;
my $uri = $self->_uri_db_doc($doc);
$uri->query('rev='.$rev);
return DB::CouchDB::Result->new($self->_call(DELETE => $uri));
}
=head2 get_doc
Gets a doc in the database.
my $result = $db->get_doc($docname) #returns a DB::CouchDB::Result object
=cut
sub get_doc {
my $self = shift;
my $doc = shift;
return DB::CouchDB::Result->new($self->_call(GET => $self->_uri_db_doc($doc)));
}
=head2 view
Returns a views results from the database.
my $rs = $db->view($viewname, \%view_args) #returns a DB::CouchDB::Iter object
=head3 A note about view args:
the view args allow you to constrain and/or window the results that the
view gives back. Some of the ones you will probably want to use are:
group => "true" #turn on the reduce portion of your view
key => '"keyname"' # only gives back results with a certain key
#only return results starting at startkey and goint up to endkey
startkey => '"startkey"',
endkey => '"endkey"'
count => $num #only returns $num rows
offset => $num #return starting from $num row
( run in 1.387 second using v1.01-cache-2.11-cpan-39bf76dae61 )