ArangoDB
view release on metacpan or search on metacpan
lib/ArangoDB/Collection.pm view on Meta::CPAN
package ArangoDB::Collection;
use strict;
use warnings;
use utf8;
use 5.008001;
use JSON ();
use Carp qw(croak);
use Scalar::Util qw(weaken);
use Class::Accessor::Lite ( ro => [qw/id status/], );
use ArangoDB::Constants qw(:api :status);
use ArangoDB::Document;
use ArangoDB::Edge;
use ArangoDB::Index::Primary;
use ArangoDB::Index::Hash;
use ArangoDB::Index::SkipList;
use ArangoDB::Index::Geo;
use ArangoDB::Index::CapConstraint;
use ArangoDB::Cursor;
use ArangoDB::ClientException;
use overload
q{""} => sub { shift->id },
fallback => 1;
my $JSON = JSON->new->utf8;
=pod
=head1 NAME
ArangoDB::Collection - An ArangoDB collection
=head1 DESCRIPTION
A instance of ArangoDB collection.
=head1 METHODS FOR COLLECTION HANDLING
=head2 new($connection, $collection_info)
Constructor.
=cut
sub new {
my ( $class, $db, $raw_collection ) = @_;
my $self = bless { db => $db, connection => $db->{connection}, }, $class;
weaken( $self->{db} );
weaken( $self->{connection} );
for my $key (qw/id name status/) {
$self->{$key} = $raw_collection->{$key};
}
$self->{_api_path} = API_COLLECTION . '/' . $self->{id};
return $self;
}
=pod
=head2 id()
Returns identifer of the collection.
=head2 status()
Returns status of the collection.
=cut
=pod
=head2 name([$name])
Returns name of collection.
If $name is set, rename the collection.
=cut
sub name {
my ( $self, $name ) = @_;
if ($name) { #rename
$self->_put_to_this( 'rename', { name => $name } );
$self->{name} = $name;
}
return $self->{name};
}
=pod
=head2 count()
Returns number of documents in the collection.
=cut
sub count {
my $self = shift;
my $res = $self->_get_from_this('count');
return $res->{count};
}
=pod
=head2 drop()
Drop the collection.
=cut
sub drop {
( run in 1.786 second using v1.01-cache-2.11-cpan-39bf76dae61 )