NAME
Neo4j::Driver::Result - Result of running a Cypher query (a stream of records)
VERSION
version 1.02
SYNOPSIS
$result = $session->run( ... );
# Stream result records
while ( $record = $result->fetch ) {
...
}
# List result records
@records = $result->list;
$records = $result->list; # array ref
$record_count = $result->size;
# Shortcut for results with a single record only
$record = $result->single;
@field_keys = $result->keys;
$summary = $result->consume;
# For error checking, call any method on the result to ensure
# the query has executed before leaving the try block
try {
$result = $transaction->run( ... );
$result->has_next;
}
catch ($e) { ... }
DESCRIPTION
The result of running a Cypher query, conceptually a stream of records. The result stream can be navigated through using fetch()
to consume records one at a time, or be consumed in its entirety using list()
to get an array of all records.
Result streams typically are initially attached to the active session. As records are retrieved from the stream, they may be buffered locally in the driver. Once all data on the result stream has been retrieved from the server and buffered locally, the stream becomes detached.
Result streams are valid until the next query is run on the same session or (if the result was retrieved within an explicit transaction) until the transaction is closed, whichever comes first. When a result stream has become invalid before it was detached, calling any methods in this class may fail.
Some result handlers may automatically detach a result stream immediately when the result is made available by the server. Such result streams are valid indefinitely. In driver version 0.xx, this happened for all HTTP results. This behaviour is subject to change in future versions and shouldn't be relied upon.
To obtain a query result, call "run" in Neo4j::Driver::Transaction.
METHODS
Neo4j::Driver::Result implements the following methods.
consume
$summary = $result->consume;
Return the Neo4j::Driver::ResultSummary.
Calling this method fully exhausts the result and invalidates the result stream, discarding any remaining records. If you want to access records after retrieving the summary, you should use list()
before consume()
to buffer all records into memory.
Before driver version 0.44, the summary was retrieved with the summary()
method, which didn't exhaust the result. That method has since been deprecated, matching a corresponding change in Neo4j 4.0.
fetch
while ($record = $result->fetch) {
...
}
Navigate to and retrieve the next Record in this result.
When a record is fetched, that record is removed from the result stream. Once all records have been fetched, the result stream is exhausted and fetch()
returns undef
.
has_next
while ($record = $result->fetch) {
print $record->get('field');
print ', ' if $result->has_next;
}
Whether the next call to fetch()
will return a record.
Calling this method may change the internal stream buffer and detach the result, but will never exhaust it.
keys
@keys = $result->keys;
Retrieve the column names (field keys) of the records this result contains. In scalar context, return the number of columns.
list
@records = $result->list;
$records = $result->list; # arrayref
Return the entire list of all Records that remain in the result stream. Calling this method exhausts the result stream.
The list is internally buffered by this class. Calling this method multiple times returns the buffered list.
In scalar context, returns an array reference (discouraged in new code).
peek
$record = $result->peek;
Obtain the next Record from this result without actually navigating to it and consuming it. The record is left in the internal stream buffer for further processing. If there is no next record, return undef
.
single
$name = $session->run('... LIMIT 1')->single->get('name');
Return the single Record left in the result stream, failing if there is not exactly one record left. Calling this method exhausts the result stream.
The returned record is internally buffered by this class. Calling this method multiple times returns the buffered record.
size
$record_count = $result->size;
Return the count of records that calling list()
would yield.
Calling this method may exhaust the result stream and may buffer all records for use by list()
.
SEE ALSO
AUTHOR
Arne Johannessen (AJNN)
COPYRIGHT AND LICENSE
This software is Copyright (c) 2016-2024 by Arne Johannessen.
This is free software; you can redistribute it and/or modify it under the terms of the Artistic License 2.0 or (at your option) the same terms as the Perl 5 programming language system itself.