Arango-DB

 view release on metacpan or  search on metacpan

lib/Arango/DB/Database.pm  view on Meta::CPAN

# ABSTRACT: ArangoDB Database object

package Arango::DB::Database;
$Arango::DB::Database::VERSION = '0.006';
use Arango::DB::Cursor;

use warnings;
use strict;

sub _new {
    my ($class, %opts) = @_;
    return bless {%opts} => $class;
}

sub collection {
   my ($self, $name) = @_;
   my @match = grep { $_->{name} eq $name } @{$self->list_collections};
   if (scalar(@match)) {
      return Arango::DB::Collection->_new(arango => $self->{arango}, database => $self->{name}, 'name' => $name);
   }
   else {
      die "Arango::DB | Collection not found in database $self->{name}."
   }
}

sub cursor {
    my ($self, $aql, %opts) = @_;
    return Arango::DB::Cursor->_new(arango => $self->{arango}, database => $self->{name}, query => $aql, %opts);
}

sub list_collections {
    my ($self) = @_;
    return $self->{arango}->list_collections($self->{name});
}

sub create_collection {
    my ($self, $name) = @_;
    die "Arango::DB | Cannot create collection with empty collection or database name" unless length $name;
    return $self->{arango}->_api('create_collection', { database => $self->{name}, name => $name })
}

sub delete_collection {
    my ($self, $name) = @_;
    die "Arango::DB | Cannot create collection with empty collection or database name" unless length $name;
    return $self->{arango}->_api('delete_collection', { database => $self->{name}, name => $name })
}

1;

__END__

=pod

=encoding UTF-8

=head1 NAME

Arango::DB::Database - ArangoDB Database object

=head1 VERSION

version 0.006

=head1 USAGE

This class should not be created directly. The L<Arango::DB> module is responsible for
creating instances of this object.

C<Arango::DB::Database> answers to the following methods:

=head2 C<list_collections>

 view all matches for this distribution
 view release on metacpan -  search on metacpan

( run in 1.032 second using v1.00-cache-1.14-grep-28634ff-cpan-207214f8fbd )