ArangoDB

 view release on metacpan or  search on metacpan

README  view on Meta::CPAN

NAME
    ArangoDB - ArangoDB client for Perl

SYNOPSIS
      use ArangoDB;
  
      my $db = ArangoDB->new(
          host       => 'localhost',
          port       => 8529,
          keep_alive => 1,
      );
  
      # Find or create collection
      my $foo = $db->('foo');
  
      # Create new document
      $foo->save({ x => 42, y => { a => 1, b => 2, } });
      $foo->save({ x => 1, y => { a => 1, b => 10, } });
      $foo->name('new_name'); # rename the collection
  

README  view on Meta::CPAN

    port
        Port number of ArangoDB server.

        Default: 8529

    timeout
        Seconds of HTTP connection timeout.

        Default: 300

    keep_alive
        If it is true, use HTTP Keep-Alive connection.

        Default: false

    auth_type
        Authentication method. Supporting "Basic" only.

    auth_user
        User name for authentication

lib/ArangoDB.pm  view on Meta::CPAN


ArangoDB - ArangoDB client for Perl

=head1 SYNOPSIS

  use ArangoDB;
  
  my $db = ArangoDB->new(
      host       => 'localhost',
      port       => 8529,
      keep_alive => 1,
  );
  
  # Find or create collection
  my $foo = $db->('foo');
  
  # Create new document
  $foo->save({ x => 42, y => { a => 1, b => 2, } });
  $foo->save({ x => 1, y => { a => 1, b => 10, } });
  $foo->name('new_name'); # rename the collection
  

lib/ArangoDB.pm  view on Meta::CPAN

Port number of ArangoDB server.

Default: 8529

=item timeout

Seconds of HTTP connection timeout.

Default: 300

=item keep_alive

If it is true, use HTTP Keep-Alive connection.

Default: false

=item auth_type

Authentication method. Supporting "Basic" only.

=item auth_user

lib/ArangoDB/Collection.pm  view on Meta::CPAN

Returns number of documents and additional statistical information about the collection.

$type is key name of figures.The key names are: 

=over 4

=item count

The number of documents inside the collection.

=item alive-count

The number of living documents.

=item alive-size

The total size in bytes used by all living documents.

=item dead-count

The number of dead documents.

=item dead-size

The total size in bytes used by all dead documents.

lib/ArangoDB/ConnectOptions.pm  view on Meta::CPAN

    elsif ( !is_hash_ref($options) ) {
        die "Argument must be HASH reference";
    }

    my %opts = ( %{ $class->_get_defaults() }, %$options );
    my $self = bless { _options => \%opts }, $class;
    $self->_validate();
    return $self;
}

for my $name (qw/host port timeout keep_alive proxy auth_type auth_user auth_passwd inet_aton/) {
    next if __PACKAGE__->can($name);
    no strict 'refs';
    *{ __PACKAGE__ . '::' . $name } = sub {
        $_[0]->{_options}{$name};
    };
}

my @supported_auth_type = qw(Basic);

sub _validate {

lib/ArangoDB/ConnectOptions.pm  view on Meta::CPAN

}

sub _get_defaults {
    return {
        host        => 'localhost',
        port        => 8529,
        timeout     => 300,           # Same value as default timeout of arangosh
        auth_user   => undef,
        auth_passwd => undef,
        auth_type   => undef,
        keep_alive  => 0,
        proxy       => undef,
        inet_aton   => undef,
    };
}

1;
__END__

lib/ArangoDB/Connection.pm  view on Meta::CPAN

use MIME::Base64;
use ArangoDB::ConnectOptions;
use ArangoDB::ServerException;
use Class::Accessor::Lite ( ro => [qw/options/] );

my $JSON = JSON->new->utf8;

sub new {
    my ( $class, $options ) = @_;
    my $opts = ArangoDB::ConnectOptions->new($options);
    my $headers = [ Host => $opts->host, Connection => $opts->keep_alive ? 'Keep-Alive' : 'Close', ];
    if ( $opts->auth_type && $opts->auth_user ) {
        push @$headers, Authorization =>
            sprintf( '%s %s', $opts->auth_type, encode_base64( $opts->auth_user . ':' . $opts->auth_passwd ) );
    }
    my %furl_args = (
        timeout => $opts->timeout,
        headers => $headers,
        proxy   => $opts->proxy,
    );
    if( $opts->inet_aton ){

t/01_new.t  view on Meta::CPAN

use strict;
use Test::More;
use Test::Fatal qw(exception lives_ok);
use ArangoDB;

my $db = ArangoDB->new(
    {   host        => 'localhost',
        port        => 0,
        timeout     => 10,
        keep_alive  => 1,
        use_proxy   => 1,
        auth_type   => 'Basic',
        auth_user   => 'tesuser',
        auth_passwd => 'testuserpw',
        inet_aton   => sub { },
    }
);

isa_ok( $db, "ArangoDB" );
ok exception { $db->find('foo') };

t/02_collection.t  view on Meta::CPAN

use JSON;

if ( !$ENV{TEST_ARANGODB_PORT} ) {
    plan skip_all => 'Can"t find port of arangod';
}

my $port   = $ENV{TEST_ARANGODB_PORT};
my $config = {
    host       => 'localhost',
    port       => $port,
    keep_alive => 1,
};

sub init {
    my $db = ArangoDB->new($config);
    map { $_->drop } @{ $db->collections };
}

subtest 'create collection' => sub {
    init();
    my $db = ArangoDB->new($config);

t/02_collection.t  view on Meta::CPAN

        $coll->count;
    }, qr/^Failed to get the property/;

};

subtest 'figures' => sub {
    my $db    = ArangoDB->new($config);
    my $coll  = $db->collection('bar');
    my $stats = $coll->figure();
    is ref($stats), 'HASH';
    is $stats->{alive}{count}, $coll->figure('alive-count');
    is $stats->{alive}{size},  $coll->figure('alive-size');
    is ref( $coll->figure('alive') ), 'HASH';
    is $coll->figure('count'), 2;
    ok $coll->figure('journalSize');
    ok !defined $coll->figure('foo');
};

subtest 'drop collection by name' => sub {
    my $db   = ArangoDB->new($config);
    my $coll = $db->create('qux');
    ok $coll;
    $db->('qux')->drop;

t/07_index.t  view on Meta::CPAN

use ArangoDB;

if ( !$ENV{TEST_ARANGODB_PORT} ) {
    plan skip_all => 'Can"t find port of arangod';
}

my $port   = $ENV{TEST_ARANGODB_PORT};
my $config = {
    host       => 'localhost',
    port       => $port,
    keep_alive => 1,
};

init();

sub init {
    my $db = ArangoDB->new($config);
    map { $_->drop } @{ $db->collections };
}

subtest 'hash index' => sub {



( run in 2.965 seconds using v1.01-cache-2.11-cpan-df04353d9ac )