DBD::Neo4p - A DBI driver for Neo4j via REST::Neo4p
use DBI; my $dbh = DBI->connect("dbi:Neo4p:db=http://127.0.0.1:7474;user=foo;pass=bar"); my $q =<<CYPHER; MATCH path = (x)-[r]-(friend) WHERE x.name = \$name1 and friend.name = \$name2 RETURN TYPE(r) CYPHER my $sth = $dbh->prepare($q); $sth->execute("I", "you"); # startName => 'I', name => 'you' while (my $row = $sth->fetch) { print "I am a ".$row->[0]." friend of yours.\n"; }
DBD::Neo4p is a DBI-compliant wrapper for REST::Neo4p::Query that allows for the execution of Neo4j Cypher language queries against a Neo4j graph database.
DBD::Neo4p requires REST::Neo4p v0.3030 or greater.
my $dbh = DBI->connect("dbi:Neo4p:db=http://127.0.0.1:7474"); $dbh = DBI->connect("dbi:Neo4p:host=127.0.0.1;port=7474"); $dbh = DBI->connect("dbi:Neo4p:db=http://127.0.0.1:7474",$user,$pass);
$sth = $dbh->prepare("MATCH (a {id:0}) RETURN n"); $sth = $dbh->prepare("MATCH (n)-->(m)". "WHERE m.name = \$name RETURN m");
Prepare a Cypher language statement. In Cypher, parameters are named and begin with the dollar sign.
The driver captures the parameters and treats them as numbered in the order they appear in the statement (per DBI spec). An array of parameter names in order can be obtained from the statement handle:
@param_names = @{$sth->{neo_param_names}};
Transaction support requires Neo4j server version 2.0.0 or greater. The driver will return with error set if your server can't handle transactions (per DBI spec).
$dbh->disconnect
Not currently implemented. Neo4j is basically typeless, and does not have tables. Node labels and indexes allow a schema-like constraint system (see https://neo4j.com/docs/cypher-manual/current/schema/)
say "Neo4j Server Version ".$dbh->neo_neo4j_version;
Get the neo4j server version.
$sth->execute; $sth->execute($param_value,...);
All DBI bind_param and execute variants are meant to work. Please file a bug in RT if there are problems.
bind_param
execute
fetch and fetch_rowarray retrieve the next row from the response.
fetch
fetch_rowarray
The fields returned in Cypher query rows can include nodes and relationships, as well as scalar values. Nodes and relationships are returned as simple Perl structures (hashrefs) by default (see "as_simple()" in REST::Neo4p::Node and "as_simple()" in REST::Neo4p::Relationship for format). REST::Neo4p::Node and REST::Neo4p::Relationship objects themselves can be retrieved by setting
$dbh->{neo_ResponseAsObjects} = 1
on the database handle.
See "fetchall_hashref" in DBI. In DBD::Neo4p, fetchall_hashref is reimplemented so that the node or relationship IDs become the hash keys for key fields:
fetchall_hashref
$sth = $dbh->prepare("START n = node:nameidx(name = 'Ed')". "MATCH n-[:friend]-m return m, m.name"); $sth->execute; my $hash = $sth->fetchall_hashref('m'); my @friend_ids = keys %$hash; say "One friend of Ed's is ".$hash->{$friend_ids[0]}->{'m.name'};
$dbh->{neo_ResponseAsObjects}
If set, columns that are nodes, relationships or paths are returned as REST::Neo4p objects of the appropriate type.
If clear (default), these entities are returned as hash or array refs, as appropriate. For descriptions of these, see "as_simple()" in REST::Neo4p::Node, "as_simple()" in REST::Neo4p::Relationship, and "as_simple()" in REST::Neo4p::Path.
@param_names = @{ $sth->{neo_param_names} };
Arrayref of named parameters in statement.
@param_values = @{ $sth->{neo_param_values} };
Arrayref of bound parameter values.
REST::Neo4p, REST::Neo4p::Query, DBI, DBI::DBD
Mark A. Jensen CPAN ID : MAJENSEN majensen -at- cpan -dot- org
(c) 2013-2019 by Mark A. Jensen
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install DBD::Neo4p, copy and paste the appropriate command in to your terminal.
cpanm
cpanm DBD::Neo4p
CPAN shell
perl -MCPAN -e shell install DBD::Neo4p
For more information on module installation, please visit the detailed CPAN module installation guide.