File Coverage

blib/lib/ArangoDB2/Query.pm
Criterion Covered Total %
statement 23 37 62.1
branch 0 6 0.0
condition n/a
subroutine 8 15 53.3
pod 9 9 100.0
total 40 67 59.7


line stmt bran cond sub pod time code
1             package ArangoDB2::Query;
2              
3 20     20   80 use strict;
  20         25  
  20         620  
4 20     20   74 use warnings;
  20         24  
  20         545  
5              
6 20         1315 use base qw(
7             ArangoDB2::Base
8 20     20   78 );
  20         21  
9              
10 20     20   93 use Data::Dumper;
  20         26  
  20         945  
11 20     20   93 use JSON::XS;
  20         23  
  20         789  
12              
13 20     20   6871 use ArangoDB2::Cursor;
  20         41  
  20         7192  
14              
15             my $JSON = JSON::XS->new->utf8;
16              
17              
18              
19             # new
20             #
21             # create new instance
22             sub new
23             {
24 2     2 1 4 my($class, $arango, $database, $query) = @_;
25              
26 2         10 my $self = $class->SUPER::new($arango, $database);
27 2         7 $self->query($query);
28              
29 2         4 return $self;
30             }
31              
32             # batchSize
33             #
34             # maximum number of result documents
35 0     0 1 0 sub batchSize { shift->_get_set('batchSize', @_) }
36              
37             # count
38             #
39             # boolean flag that indicates whether the number of documents in the
40             # result set should be returned.
41 0     0 1 0 sub count { shift->_get_set_bool('count', @_) }
42              
43             # execute
44             #
45             # POST /_api/cursor
46             sub execute
47             {
48 0     0 1 0 my($self, $bind, $args) = @_;
49             # process args
50 0         0 $args = $self->_build_args($args, [qw(
51             batchSize fullCount count query ttl
52             )]);
53             # fullCount is an exception that belongs under options
54 0 0       0 $args->{options}->{fullCount} = delete $args->{fullCount}
55             if exists $args->{fullCount};
56             # set bindVars if bind is passed
57 0 0       0 $args->{bindVars} = $bind
58             if defined $bind;
59             # make request
60 0 0       0 my $res = $self->arango->http->post(
61             $self->api_path('cursor'),
62             undef,
63             $JSON->encode($args),
64             ) or return;
65              
66 0         0 return ArangoDB2::Cursor->new($self->arango, $self->database, $res);
67             }
68              
69             # fullCount
70             #
71             # include result count greater than LIMIT
72             #
73             # default false
74 0     0 1 0 sub fullCount { shift->_get_set_bool('fullCount', @_) }
75              
76             # explain
77             #
78             # POST /_api/explain
79             sub explain
80             {
81 0     0 1 0 my($self) = @_;
82              
83 0         0 return $self->arango->http->post(
84             $self->api_path('explain'),
85             undef,
86             $JSON->encode({query => $self->query}),
87             );
88             }
89              
90             # parse
91             #
92             # POST /_api/query
93             sub parse
94             {
95 0     0 1 0 my($self) = @_;
96              
97 0         0 return $self->arango->http->post(
98             $self->api_path('query'),
99             undef,
100             $JSON->encode({query => $self->query}),
101             );
102             }
103              
104             # query
105             #
106             # AQL query
107 2     2 1 9 sub query { shift->_get_set('query', @_) }
108              
109             # ttl
110             #
111             # an optional time-to-live for the cursor (in seconds)
112 0     0 1   sub ttl { shift->_get_set('ttl', @_) }
113              
114             1;
115              
116             __END__