NAME

Neo4j::Driver::Result - Result of running a Cypher statement (a stream of records)

VERSION

version 0.45

SYNOPSIS

 use Neo4j::Driver;
 $session = Neo4j::Driver->new->basic_auth(...)->session;
 
 # stream result records
 $result = $session->run('MATCH (a:Actor) RETURN a.name, a.born');
 while ( $record = $result->fetch ) {
   ...
 }
 
 # list result records
 $result = $session->run('MATCH (m:Movie) RETURN m.name, m.year');
 $record_count = $result->size;
 @records = $result->list;
 
 # shortcut for results with a single record only
 $query = 'MATCH (m:Movie) WHERE id(m) = {id} RETURN m.name';
 $name = $session->run($query, id => 12)->single->get('m.name');

DESCRIPTION

The result of running a Cypher statement, 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.

Results received over HTTP always contain the complete list of records, which is kept buffered in the driver. HTTP result streams are thus immediately detached and valid indefinitely.

Result streams received on Bolt are valid until the next statement 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.

To obtain a query result, call "run" in Neo4j::Driver::Transaction.

Until version 0.18, this module was named StatementResult.

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.

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 of the records this result contains.

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.

This method returns an array reference if called in scalar context.

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 exhausts the result stream and buffers all records for use by list().

summary

 $result_summary = $result->summary;

Return a Neo4j::Driver::ResultSummary object. Calling this method detaches the result stream, but does not exhaust it.

This method is discouraged. It may be deprecated and removed in a future version. Please use consume() instead.

As a special case, Records returned by the single method also have a summary method that works the same way.

 $record = $transaction->run('...')->single;
 $result_summary = $record->summary;

EXPERIMENTAL FEATURES

Neo4j::Driver::Result implements the following experimental features. These are subject to unannounced modification or removal in future versions. Expect your code to break if you depend upon these features.

Calling in scalar context

 $count = $result->keys;

The keys() method returns the number of columns if called in scalar context.

Until version 0.25, it returned an array reference instead.

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.