NAME
Neo4j::Driver::Record - Container for Cypher result values
VERSION
version 0.15
SYNOPSIS
use Neo4j::Driver;
$session = Neo4j::Driver->new->basic_auth(...)->session;
$query = 'MATCH (m:Movie) RETURN m.name, m.year';
$records = $session->run($query)->list;
foreach $record ( @$records ) {
say $record->get('m.name');
}
$query .= ' ORDER BY m.year LIMIT 1';
$record = $session->run($query)->single;
say 'Year of oldest movie: ', $record->get(1);
DESCRIPTION
Container for Cypher result values. Records are returned from Cypher statement execution, contained within a StatementResult. A record is a form of ordered map and, as such, contained values can be accessed by either positional index or textual key.
METHODS
Neo4j::Driver::Record implements the following methods.
get
$value1 = $record->get('field_key');
$value2 = $record->get(2);
Get a value from this record, either by field key or by zero-based index.
When called without parameters, get()
will return the first field. If there is more than a single field, a warning in the category `ambiguous` will be issued.
$value = $session->run('RETURN "It works!"')->single->get;
$value = $session->run('RETURN "warning", "ambiguous"')->single->get;
When retrieving values from records, Neo4j types are converted to Perl types as shown in the following table.
Neo4j type resulting Perl type
---------- -------------------
Number scalar
String scalar
Boolean JSON::PP::true or JSON::PP::false
null undef
Node Neo4j::Driver::Type::Node
Relationship Neo4j::Driver::Type::Relationship
Path Neo4j::Driver::Type::Path
List array reference
Map hash reference
Boolean values are returned as JSON types; use !!
to force-convert to a plain Perl boolean value if necessary.
Note that early versions of this class returned nodes, relationships and paths as hashrefs or arrayrefs rather than blessed objects. This was a bug. The underlying data structure of nodes and relationships is an implementation detail that should not be relied upon. If you try to treat Neo4j::Driver::Type::Node, Neo4j::Driver::Type::Relationship or Neo4j::Driver::Type::Path objects as hashrefs or arrayrefs, your code will eventually fail with a future version of this driver.
data
$hashref = $record->data;
$value = $hashref->{field_key};
Return the keys and values of this record as a hash reference.
EXPERIMENTAL FEATURES
Neo4j::Driver::Record 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.
column_keys
$size = $record->{column_keys}->count;
$record->{column_keys}->add('new_field_key');
Allows adding new columns to the record's field key / index resolution used by the get
method. Can be used to synthesize 'virtual' fields based on other data in the result. The new fields can then be accessed just like regular columns.
graph
$nodes = $record->{graph}->{nodes};
$rels = $record->{graph}->{relationships};
Allows accessing the graph response the Neo4j server can deliver via HTTP. Requires the return_graph
field to be set on the Transaction before the statement is executed.
meta
$meta = $record->{meta};
Allows accessing the entity meta data that some versions of the Neo4j server provide via HTTP.
SEE ALSO
Neo4j::Driver::Type::Node, Neo4j::Driver::Type::Relationship, Neo4j::Driver::Type::Path
Equivalent documentation for the official Neo4j drivers: Record (Java), Record (JavaScript), IRecord (.NET)
AUTHOR
Arne Johannessen <ajnn@cpan.org>
COPYRIGHT AND LICENSE
This software is Copyright (c) 2016-2020 by Arne Johannessen.
This is free software, licensed under:
The Artistic License 2.0 (GPL Compatible)