File Coverage

blib/lib/Neo4j/Bolt/ResultStream.pm
Criterion Covered Total %
statement 5 21 23.8
branch 0 2 0.0
condition n/a
subroutine 1 11 9.0
pod 10 10 100.0
total 16 44 36.3


line stmt bran cond sub pod time code
1             package Neo4j::Bolt::ResultStream;
2             # use Neo4j::Client;
3              
4             BEGIN {
5 4     4   18 our $VERSION = "0.4200";
6 4         18 require Neo4j::Bolt::Cxn;
7 4         1663 require Neo4j::Bolt::CResultStream;
8 4         29 require XSLoader;
9 4         3805 XSLoader::load();
10             }
11              
12 0     0 1   sub fetch_next { shift->fetch_next_ }
13 0     0 1   sub nfields { shift->nfields_ }
14 0     0 1   sub field_names { shift->fieldnames_ }
15 0     0 1   sub success { shift->success_ }
16 0     0 1   sub failure { shift->failure_ }
17 0     0 1   sub client_errnum { shift-> client_errnum_ }
18 0     0 1   sub client_errmsg { shift-> client_errmsg_ }
19 0     0 1   sub server_errmsg { shift-> server_errmsg_ }
20 0     0 1   sub server_errcode { shift-> server_errcode_ }
21              
22             sub update_counts {
23 0     0 1   my $self = shift;
24 0           my %uc;
25 0           my @tags = qw/nodes_created nodes_deleted
26             relationships_created relationships_deleted
27             properties_set
28             labels_added labels_removed
29             indexes_added indexes_removed
30             constraints_added constraints_removed/;
31 0           my @vals = $self->update_counts_;
32 0 0         return unless @vals;
33 0           @uc{@tags} = @vals;
34 0           return \%uc;
35             }
36              
37             =head1 NAME
38              
39             Neo4j::Bolt::ResultStream - Iterator on Neo4j Bolt query response
40              
41             =head1 SYNOPSIS
42              
43             use Neo4j::Bolt;
44             $cxn = Neo4j::Bolt->connect("bolt://localhost:7687");
45              
46             $stream = $cxn->run_query(
47             "MATCH (a) RETURN labels(a) as lbls, count(a) as ct"
48             );
49             while ( my @row = $stream->fetch_next ) {
50             print "For label set [".join(',',@{$row[0]})."] there are $row[1] nodes.\n";
51             }
52             # check that the stream emptied cleanly...
53             unless ( $stream->success ) {
54             print STDERR "Uh oh: ".($stream->client_errmsg || $stream->server_errmsg);
55             }
56              
57             =head1 DESCRIPTION
58              
59             L objects are created by a successful query
60             performed on a L. They are iterated to obtain the rows
61             of the response as Perl arrays (not arrayrefs).
62              
63             =head1 METHODS
64              
65             =over
66              
67             =item fetch_next()
68              
69             Obtain the next row of results as an array. Returns false when done.
70              
71             =item update_counts()
72              
73             If a write query is successful, returns a hashref containing the
74             numbers of items created or removed in the query. The keys indicate
75             the items, as follows:
76              
77             nodes_created
78             nodes_deleted
79             relationships_created
80             relationships_deleted
81             properties_set
82             labels_added
83             labels_removed
84             indexes_added
85             indexes_removed
86             constraints_added
87             constraints_removed
88              
89             If query is unsuccessful, or the stream is not completely fetched yet,
90             returns undef (check L).
91              
92             =item field_names()
93              
94             Obtain the column names of the response as an array (not arrayref).
95              
96             =item nfields()
97              
98             Obtain the number of fields in the response row as an integer.
99              
100             =item success(), failure()
101              
102             Use these to check whether fetch_next() succeeded. They indicate the
103             current error state of the result stream. If
104              
105             $stream->success == $stream->failure == -1
106              
107             then the stream has been exhausted.
108              
109             =item client_errnum()
110              
111             =item client_errmsg()
112              
113             =item server_errcode()
114              
115             =item server_errmsg()
116              
117             If C<$stream-Esuccess> is false, these will indicate what happened.
118              
119             If the error occurred within the C code,
120             C will provide the C and C
121             the associated error message. This is a probably a good time to file a
122             bug report.
123              
124             If the error occurred at the server, C and
125             C will contain information sent by the server. In
126             particular, Cypher syntax errors will appear here.
127              
128             =item result_count_()
129              
130             =item available_after()
131              
132             =item consumed_after()
133              
134             These are performance numbers that the server provides after the
135             stream has been fetched out. result_count_() is the number of rows
136             returned, available_after() is the time in ms it took the server to
137             provide the stream, and consumed_after() is the time it took the
138             client (you) to pull them all.
139              
140             =back
141              
142             =head1 SEE ALSO
143              
144             L, L.
145              
146             =head1 AUTHOR
147              
148             Mark A. Jensen
149             CPAN: MAJENSEN
150             majensen -at- cpan -dot- org
151              
152             =head1 LICENSE
153              
154             This software is Copyright (c) 2019-2020 by Mark A. Jensen.
155              
156             This is free software, licensed under:
157              
158             The Apache License, Version 2.0, January 2004
159              
160             =cut
161              
162             1;