| 1 | package ArangoDB2::Database; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 22 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 22 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | |||||||||||||||||||||
| 6 | 22 | ▶ | use base qw( | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | ArangoDB2::Base | ||||||||||||||||||||
| 8 | 22 | ); | |||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | 22 | ▶ | use Data::Dumper; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | 22 | ▶ | use JSON::XS; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 12 | 22 | ▶ | use Scalar::Util qw(reftype); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | 22 | ▶ | use ArangoDB2::Collection; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 15 | 22 | ▶ | use ArangoDB2::Graph; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 16 | 22 | ▶ | use ArangoDB2::Query; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 17 | 22 | ▶ | use ArangoDB2::Replication; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 18 | 22 | ▶ | use ArangoDB2::Transaction; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 19 | 22 | ▶ | use ArangoDB2::User; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | 22 | my $JSON = JSON::XS->new->utf8; | |||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | |||||||||||||||||||||
| 24 | |||||||||||||||||||||
| 25 | # collection | ||||||||||||||||||||
| 26 | # | ||||||||||||||||||||
| 27 | # get/create ArangoDB2::Collection object | ||||||||||||||||||||
| 28 | sub collection | ||||||||||||||||||||
| 29 | 8 | ▶ | { | ||||||||||||||||||
|
Subroutine
collection: called CC=3 SCAR=13.3
Pod
documented
| |||||||||||||||||||||
| 30 | 8 | my($self, $name) = @_; | |||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | 8 | ▶ | if (defined $name) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 33 | # only create one ArangoDB2::Collection instance per name | ||||||||||||||||||||
| 34 | 8 | ▶ | return $self->collections->{$name} ||= ArangoDB2::Collection->new( | ||||||||||||||||||
|
Condition33%1/3
$self->collections->{$name} ||= "ArangoDB2::Collection"->new($self->arango, $self, $name)
MC/DC0%0/2
$self->collections->{$name} ||= "ArangoDB2::Collection"->new($self->arango, $self, $name)
$self->collections->{$name}
"ArangoDB2::Collection"->new($self->arango, $self, $name)
Truth table33%1/3
A ||= B
A= $self->collections->{$name}B= "ArangoDB2::Collection"->new($self->arango, $self, $name)
| |||||||||||||||||||||
| 35 | $self->arango, | ||||||||||||||||||||
| 36 | $self, | ||||||||||||||||||||
| 37 | $name, | ||||||||||||||||||||
| 38 | ); | ||||||||||||||||||||
| 39 | } | ||||||||||||||||||||
| 40 | else { | ||||||||||||||||||||
| 41 | 0 | ArangoDB2::Collection->new( | |||||||||||||||||||
| 42 | $self->arango, | ||||||||||||||||||||
| 43 | $self, | ||||||||||||||||||||
| 44 | $name, | ||||||||||||||||||||
| 45 | ); | ||||||||||||||||||||
| 46 | } | ||||||||||||||||||||
| 47 | } | ||||||||||||||||||||
| 48 | |||||||||||||||||||||
| 49 | # collections | ||||||||||||||||||||
| 50 | # | ||||||||||||||||||||
| 51 | # index of ArangoDB2::Collection objects by name | ||||||||||||||||||||
| 52 | 8 | ▶ | sub collections { $_[0]->{collections} ||= {} } | ||||||||||||||||||
|
Subroutine
collections: called CC=2 SCAR=7.6
Pod
documented
Condition50%1/2
$_[0]{"collections"} ||= {}
MC/DC0%0/1
$_[0]{"collections"} ||= {}
$_[0]{"collections"}
Truth table50%1/2
A
A= $_[0]{"collections"}
| |||||||||||||||||||||
| 53 | |||||||||||||||||||||
| 54 | # create | ||||||||||||||||||||
| 55 | # | ||||||||||||||||||||
| 56 | # POST /_api/database | ||||||||||||||||||||
| 57 | sub create | ||||||||||||||||||||
| 58 | 0 | ▶ | { | ||||||||||||||||||
|
Subroutine
create: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 59 | 0 | my($self, $args) = @_; | |||||||||||||||||||
| 60 | # process args | ||||||||||||||||||||
| 61 | 0 | $args = $self->_build_args($args, ['name','users']); | |||||||||||||||||||
| 62 | # make request | ||||||||||||||||||||
| 63 | 0 | ▶ | my $res = $self->arango->http->post( | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 64 | '/_api/database', | ||||||||||||||||||||
| 65 | undef, | ||||||||||||||||||||
| 66 | $JSON->encode($args), | ||||||||||||||||||||
| 67 | ) or return; | ||||||||||||||||||||
| 68 | |||||||||||||||||||||
| 69 | 0 | return $self; | |||||||||||||||||||
| 70 | } | ||||||||||||||||||||
| 71 | |||||||||||||||||||||
| 72 | # current | ||||||||||||||||||||
| 73 | # | ||||||||||||||||||||
| 74 | # GET /_api/database/current | ||||||||||||||||||||
| 75 | sub current | ||||||||||||||||||||
| 76 | 0 | ▶ | { | ||||||||||||||||||
|
Subroutine
current: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 77 | 0 | my($self) = @_; | |||||||||||||||||||
| 78 | |||||||||||||||||||||
| 79 | 0 | return $self->arango->http->get('/_api/database/current'); | |||||||||||||||||||
| 80 | } | ||||||||||||||||||||
| 81 | |||||||||||||||||||||
| 82 | # delete | ||||||||||||||||||||
| 83 | # | ||||||||||||||||||||
| 84 | # DELETE /_api/database/{database-name} | ||||||||||||||||||||
| 85 | sub delete | ||||||||||||||||||||
| 86 | 0 | ▶ | { | ||||||||||||||||||
|
Subroutine
delete: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 87 | 0 | my($self) = @_; | |||||||||||||||||||
| 88 | |||||||||||||||||||||
| 89 | 0 | return $self->arango->http->delete("/_api/database/".$self->name); | |||||||||||||||||||
| 90 | } | ||||||||||||||||||||
| 91 | |||||||||||||||||||||
| 92 | # graph | ||||||||||||||||||||
| 93 | # | ||||||||||||||||||||
| 94 | # get/create ArangoDB2::Graph object | ||||||||||||||||||||
| 95 | sub graph | ||||||||||||||||||||
| 96 | 6 | ▶ | { | ||||||||||||||||||
|
Subroutine
graph: called CC=3 SCAR=15.1
Pod
documented
| |||||||||||||||||||||
| 97 | 6 | my($self, $name) = @_; | |||||||||||||||||||
| 98 | |||||||||||||||||||||
| 99 | 6 | ▶ | if (defined $name) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 100 | 0 | ▶ | return $self->graphs->{$name} ||= ArangoDB2::Graph->new( | ||||||||||||||||||
|
Condition0%0/3
$self->graphs->{$name} ||= "ArangoDB2::Graph"->new($self->arango, $self, $name)
MC/DC0%0/2
$self->graphs->{$name} ||= "ArangoDB2::Graph"->new($self->arango, $self, $name)
$self->graphs->{$name}
"ArangoDB2::Graph"->new($self->arango, $self, $name)
Truth table0%0/3
A ||= B
A= $self->graphs->{$name}B= "ArangoDB2::Graph"->new($self->arango, $self, $name)
| |||||||||||||||||||||
| 101 | $self->arango, | ||||||||||||||||||||
| 102 | $self, | ||||||||||||||||||||
| 103 | $name, | ||||||||||||||||||||
| 104 | ); | ||||||||||||||||||||
| 105 | } | ||||||||||||||||||||
| 106 | else { | ||||||||||||||||||||
| 107 | 6 | return ArangoDB2::Graph->new( | |||||||||||||||||||
| 108 | $self->arango, | ||||||||||||||||||||
| 109 | $self, | ||||||||||||||||||||
| 110 | ); | ||||||||||||||||||||
| 111 | } | ||||||||||||||||||||
| 112 | } | ||||||||||||||||||||
| 113 | |||||||||||||||||||||
| 114 | # graphs | ||||||||||||||||||||
| 115 | # | ||||||||||||||||||||
| 116 | # index of ArangoDB2::Graph objects by name | ||||||||||||||||||||
| 117 | 0 | ▶ | sub graphs { $_[0]->{graphs} ||= {} } | ||||||||||||||||||
|
Subroutine
graphs: not called CC=2 SCAR=17.9
Pod
documented
Condition0%0/2
$_[0]{"graphs"} ||= {}
MC/DC0%0/1
$_[0]{"graphs"} ||= {}
$_[0]{"graphs"}
Truth table0%0/2
A
A= $_[0]{"graphs"}
| |||||||||||||||||||||
| 118 | |||||||||||||||||||||
| 119 | # list | ||||||||||||||||||||
| 120 | # | ||||||||||||||||||||
| 121 | # GET /_api/database | ||||||||||||||||||||
| 122 | # | ||||||||||||||||||||
| 123 | # Retrieves the list of all existing databases | ||||||||||||||||||||
| 124 | sub list | ||||||||||||||||||||
| 125 | 0 | ▶ | { | ||||||||||||||||||
|
Subroutine
list: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 126 | 0 | my($self) = @_; | |||||||||||||||||||
| 127 | |||||||||||||||||||||
| 128 | 0 | return $self->arango->http->get('/_api/database'); | |||||||||||||||||||
| 129 | } | ||||||||||||||||||||
| 130 | |||||||||||||||||||||
| 131 | |||||||||||||||||||||
| 132 | # query | ||||||||||||||||||||
| 133 | # | ||||||||||||||||||||
| 134 | # get a new ArangoDB2::Query object | ||||||||||||||||||||
| 135 | sub query | ||||||||||||||||||||
| 136 | 2 | ▶ | { | ||||||||||||||||||
|
Subroutine
query: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 137 | 2 | my($self, $query) = @_; | |||||||||||||||||||
| 138 | |||||||||||||||||||||
| 139 | 2 | return ArangoDB2::Query->new( | |||||||||||||||||||
| 140 | $self->arango, | ||||||||||||||||||||
| 141 | $self, | ||||||||||||||||||||
| 142 | $query | ||||||||||||||||||||
| 143 | ); | ||||||||||||||||||||
| 144 | } | ||||||||||||||||||||
| 145 | |||||||||||||||||||||
| 146 | # replication | ||||||||||||||||||||
| 147 | # | ||||||||||||||||||||
| 148 | # get a new ArangoDB2::Replication object | ||||||||||||||||||||
| 149 | sub replication | ||||||||||||||||||||
| 150 | 1 | ▶ | { | ||||||||||||||||||
|
Subroutine
replication: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 151 | 1 | my($self) = @_; | |||||||||||||||||||
| 152 | |||||||||||||||||||||
| 153 | 1 | return ArangoDB2::Replication->new( | |||||||||||||||||||
| 154 | $self->arango, | ||||||||||||||||||||
| 155 | $self, | ||||||||||||||||||||
| 156 | ); | ||||||||||||||||||||
| 157 | } | ||||||||||||||||||||
| 158 | |||||||||||||||||||||
| 159 | # transaction | ||||||||||||||||||||
| 160 | # | ||||||||||||||||||||
| 161 | # get a new ArangoDB2::Transaction object | ||||||||||||||||||||
| 162 | sub transaction | ||||||||||||||||||||
| 163 | 1 | ▶ | { | ||||||||||||||||||
|
Subroutine
transaction: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 164 | 1 | my($self) = @_; | |||||||||||||||||||
| 165 | |||||||||||||||||||||
| 166 | 1 | return ArangoDB2::Transaction->new( | |||||||||||||||||||
| 167 | $self->arango, | ||||||||||||||||||||
| 168 | $self, | ||||||||||||||||||||
| 169 | ); | ||||||||||||||||||||
| 170 | } | ||||||||||||||||||||
| 171 | |||||||||||||||||||||
| 172 | # user | ||||||||||||||||||||
| 173 | # | ||||||||||||||||||||
| 174 | # ArangoDB2::User object | ||||||||||||||||||||
| 175 | sub user | ||||||||||||||||||||
| 176 | 1 | ▶ | { | ||||||||||||||||||
|
Subroutine
user: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 177 | 1 | my($self, $name) = @_; | |||||||||||||||||||
| 178 | |||||||||||||||||||||
| 179 | 1 | return ArangoDB2::User->new( | |||||||||||||||||||
| 180 | $self->arango, | ||||||||||||||||||||
| 181 | $self, | ||||||||||||||||||||
| 182 | $name, | ||||||||||||||||||||
| 183 | ); | ||||||||||||||||||||
| 184 | } | ||||||||||||||||||||
| 185 | |||||||||||||||||||||
| 186 | # userDatabases | ||||||||||||||||||||
| 187 | # | ||||||||||||||||||||
| 188 | # GET /_api/database/user | ||||||||||||||||||||
| 189 | # | ||||||||||||||||||||
| 190 | # Retrieves the list of all databases the current user can access without specifying | ||||||||||||||||||||
| 191 | # a different username or password. | ||||||||||||||||||||
| 192 | sub userDatabases | ||||||||||||||||||||
| 193 | 0 | ▶ | { | ||||||||||||||||||
|
Subroutine
userDatabases: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 194 | 0 | my($self) = @_; | |||||||||||||||||||
| 195 | |||||||||||||||||||||
| 196 | 0 | return $self->arango->http->get('/_api/database/user'); | |||||||||||||||||||
| 197 | } | ||||||||||||||||||||
| 198 | |||||||||||||||||||||
| 199 | # users | ||||||||||||||||||||
| 200 | # | ||||||||||||||||||||
| 201 | # get/set users | ||||||||||||||||||||
| 202 | 0 | ▶ | sub users { shift->_get_set('users', @_) } | ||||||||||||||||||
|
Subroutine
users: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 203 | |||||||||||||||||||||
| 204 | # _class | ||||||||||||||||||||
| 205 | # | ||||||||||||||||||||
| 206 | # internal name for class | ||||||||||||||||||||
| 207 | 32 | ▶ | sub _class { 'database' } | ||||||||||||||||||
|
Subroutine
_class: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 208 | |||||||||||||||||||||
| 209 | 22 | 1; | |||||||||||||||||||
| 210 | |||||||||||||||||||||
| 211 | __END__ | ||||||||||||||||||||