Tango/Database.pm

filter: Statementstmt 46.3% 19 / 41 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 46.6% 7 / 15 Podpod 100% 8 / 8 totaltotal 51.5% 34 / 66 CC 2 SCAR 7.2
CC
2
Cov
44%
collection
6.0
delete
2.0
cursor
2.0
CRAP 2.1
« Tango/Collection.pm ↑ Summary
1 # ABSTRACT: ArangoDB Database object
2  
3 package Arango::Tango::Database;
4 9 $Arango::Tango::Database::VERSION = '0.021';
5 9 ▶use Arango::Tango::Cursor;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 9 ▶use Arango::Tango::API;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 9 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 9 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
12 Arango::Tango::API::_install_methods "Arango::Tango::Database" => {
13  
14 delete_collection => {
15 rest => [ delete => '{{database}}_api/collection/{colname}' ],
16 signature => [ 'colname' ],
17 inject_properties => [ { prop => 'name', as => 'database' } ],
18 },
19  
20 get_indexes => {
21 rest => [ get => '{{database}}_api/index?collection={colname}' ],
22 signature => [ 'colname' ],
23 inject_properties => [ { prop => 'name', as => 'database' } ]
24 },
25  
26 create_ttl_index => {
27 rest => [ post => '{{database}}_api/index?collection={colname}' ],
28 signature => [ 'colname' ],
29 inject_properties => [ { prop => 'name', as => 'database' } ],
30 schema => {
31 name => { type => 'string' },
32 type => { type => 'string', enum => ['ttl'] },
33 fields => { type => 'array', items => { type => 'string' } },
34 expireAfter => { type => 'integer' }
35 }
36 },
37  
38 create_index => {
39 rest => [ post => '{{database}}_api/index?collection={colname}' ],
40 signature => [ 'colname' ],
41 inject_properties => [ { prop => 'name', as => 'database' } ],
42 schema => {
43 name => { type => 'string' },
44 type => { type => 'string', enum => ['hash', 'skiplist', 'persistent', 'geo'] },
45 fields => { type => 'array', items => { type => 'string' } },
46 unique => { type => 'boolean' },
47 sparse => { type => 'boolean' },
48 deduplicate => { type => 'boolean' },
49 estimates => { type => 'boolean' },
50 cacheEnabled => { type => 'boolean' },
51 inBackground => { type => 'boolean' },
52 geoJson => { type => 'boolean' },
53 }
54 },
55  
56 create_collection => {
57 rest => [ post => '{{database}}_api/collection' ],
58 schema => {
59 keyOptions => { type => 'object', additionalProperties => 0, properties => {
60 allowUserKeys => { type => 'boolean' },
61 type => { type => 'string', default => 'traditional', enum => [qw'traditional autoincrement uuid padded'] },
62 increment => { type => 'integer' },
63 offset => { type => 'integer' },
64 }},
65 journalSize => { type => 'integer' },
66 replicationFactor => { type => 'integer' },
67 waitForSync => { type => 'boolean' },
68 doCompact => { type => 'boolean' },
69 shardingStrategy => {
70 type => 'string',
71 default => 'community-compat',
72 enum => ['community-compat', 'enterprise-compat', 'enterprise-smart-edge-compat', 'hash', 'enterprise-hash-smart-edge']},
73 isVolatile => { type => 'boolean' },
74 shardKeys => { type => 'array', items => {type => 'string'} },
75 numberOfShards => { type => 'integer' },
76 isSystem => { type => 'boolean' },
77 type => { type => 'string', default => '2', enum => ['2', '3'] },
78 indexBuckets => { type => 'integer' },
79 distributeShardsLike => { type => 'string' },
80 name => { type => 'string' }
81 },
82 3 ▶ builder => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
83 3 my ($self, %params) = @_;
84 3 return Arango::Tango::Collection->_new(arango => $self, database => $params{database}, 'name' => $params{name});
85 },
86 9 signature => [ 'name' ],
87 inject_properties => [ { prop => 'name', as => 'database' } ]
88 }
89  
90 };
91 }
92  
93 1 ▶sub _new {
Subroutine _new: called CC=1 SCAR=0.0
94 1 my ($class, %opts) = @_;
95 1 return bless {%opts} => $class;
96 }
97  
98 0 ▶sub delete {
Subroutine delete: not called CC=1 SCAR=6.9
Pod documented
99 0 my $self = shift;
100 0 return $self->{arango}->delete_database($self->{name});
101 }
102  
103 0 ▶sub cursor {
Subroutine cursor: not called CC=1 SCAR=6.9
Pod documented
104 0 my ($self, $aql, %opts) = @_;
105 0 return Arango::Tango::Cursor->_new(arango => $self->{arango}, database => $self->{name}, query => $aql, %opts);
106 }
107  
108 0 ▶sub collection {
Subroutine collection: not called CC=2 SCAR=17.9
Pod documented
109 0 my ($self, $name) = @_;
110 0 my @match = grep { $_->{name} eq $name } @{$self->list_collections};
111 0 ▶ if (scalar(@match)) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @match) { } 0 0 0
112 0 return Arango::Tango::Collection->_new(arango => $self->{arango}, database => $self->{name}, 'name' => $name,);
113 }
114 else {
115 0 $self->{arango}{error} = "Collection not found in database $self->{name}";
116 0 die "-1\n";
117 }
118 }
119  
120 0 ▶sub list_collections {
Subroutine list_collections: not called CC=1 SCAR=6.9
Pod documented
121 0 my ($self, %opts) = @_;
122 0 return $self->{arango}->_api( list_collections => { %opts, database => $self->{name} } )->{result};
123 }
124  
125  
126 0 ▶sub get_access_level {
Subroutine get_access_level: not called CC=1 SCAR=6.9
Pod documented
127 0 my ($self, $username, $collection) = @_;
128 0 return $self->{arango}->get_access_level( $username, $self->{name}, $collection);
129 }
130  
131 0 ▶sub clear_access_level {
Subroutine clear_access_level: not called CC=1 SCAR=6.9
Pod documented
132 0 my ($self, $username, $collection) = @_;
133 0 return $self->{arango}->clear_access_level($username, $self->{name}, $collection);
134 }
135  
136 0 ▶sub set_access_level {
Subroutine set_access_level: not called CC=1 SCAR=6.9
Pod documented
137 0 my ($self, $username, $grant, $collection) = @_;
138 0 return $self->{arango}->set_access_level($username, $grant, $self->{name}, $collection);
139 }
140  
141 0 ▶sub error {
Subroutine error: not called CC=1 SCAR=6.9
Pod documented
142 0 my ($self) = @_;
143 0 return $self->{arango}->error;
144 }
145  
146 9 1;
147  
148 __END__
« Tango/Collection.pm ↑ Summary