NAME
Neo4j::Driver::Type::Node - Describes a node from a Neo4j graph
VERSION
version 0.14
SYNOPSIS
my $query = 'MATCH (m:Movie) RETURN m LIMIT 1';
my $node = $driver->session->run($query)->single->get('m');
say 'Movie # ', $node->id(), ' :';
say ' ', $node->get('name'), ' / ', $node->get('year');
say ' Labels: ', join ', ', $node->labels;
DESCRIPTION
Describes a node from a Neo4j graph. A node may be a part of records returned from Cypher statement execution. Its description contains the node's properties as well as certain meta data, all accessible by methods that this class provides.
Neo4j::Driver::Type::Node objects are not in a one-to-one relation with nodes in a Neo4j graph. If the same Neo4j node is fetched multiple times, then multiple distinct Neo4j::Driver::Type::Node objects will be created by the driver. If your intention is to verify that two Neo4j::Driver::Type::Node objects in Perl describe the same node in the Neo4j database, you need to compare their IDs.
METHODS
Neo4j::Driver::Type::Node implements the following methods.
get
my $value = $node->get('property_key');
Retrieve the value of this node's property with the given key. If no such key exists, return undef
.
id
my $id = $node->id;
Return a unique ID for this node.
In the Neo4j Driver API, entity IDs are only guaranteed to remain stable for the duration of the current session. Although in practice server versions at least up to and including Neo4j 3.5 may appear to use persistent IDs, your code should not depend upon that.
A node with the ID 0
may exist. Nodes and relationships do not share the same ID space.
labels
my @labels = $node->labels;
Return all labels of this node.
properties
my $hashref = $node->properties;
my $value = $hashref->{property_key};
Return all properties of this node as a hash reference.
EXPERIMENTAL FEATURES
Neo4j::Driver::Type::Node 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
my $labels = $node->labels; # fails
The labels()
method die
s if called in scalar context.
Direct data structure access
my $property_value = $node->{property_key};
Currently, the node's properties may be directly accessed as if the node was a simple hashref. This is a concession to backwards compatibility, as the data structure only started being blessed as an object in version 0.13.
Relying on this implementation detail is deprecated. Use the accessor methods get()
and properties()
instead.
Deletion indicator
my $node_exists = ! $node->deleted;
In some circumstances, Cypher statements using DELETE
may still RETURN
nodes that were deleted. To help avoid confusion in such cases, the server sometimes reports whether or not a node was deleted.
This method is experimental because that information is not reliably available. In particular, there is a known issue with the Neo4j server (#12306), and old Neo4j versions may not report it at all. If unavailable, undef
will be returned by this method.
BUGS
The value of properties named _meta
, _node
, or _labels
may not be returned correctly.
When using HTTP, the labels
of nodes that are returned as part of a Neo4j::Driver::Type::Path are unavailable, because that information is not currently reported by the Neo4j server. undef
is returned instead.
SEE ALSO
Neo4j::Driver, Neo4j Java Driver, Neo4j Python Driver
AUTHOR
Arne Johannessen <ajnn@cpan.org>
COPYRIGHT AND LICENSE
This software is Copyright (c) 2016-2019 by Arne Johannessen.
This is free software, licensed under:
The Artistic License 2.0 (GPL Compatible)