NAME
DBD::Neo4p - A DBI driver for Neo4j via REST::Neo4p
SYNOPSIS
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";
}
DESCRIPTION
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.
Functions
Driver Level
- connect
-
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);
Database Level
- prepare, prepare_cached
-
$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}};
- begin_work
- commit
- rollback
-
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).
- disconnect
-
$dbh->disconnect
- table_info
- type_info
-
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/)
- neo_neo4j_version
-
say "Neo4j Server Version ".$dbh->neo_neo4j_version;
Get the neo4j server version.
Statement Level
- execute
-
$sth->execute; $sth->execute($param_value,...);
All DBI
bind_param
andexecute
variants are meant to work. Please file a bug in RT if there are problems. - fetch
-
fetch
andfetch_rowarray
retrieve the next row from the response.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.
- fetchall_hashref
-
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:$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'};
ATTRIBUTES
Database Handle Attributes
- ResponseAsObjects
-
$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.
Statement Handle Attributes
- neo_param_names
-
@param_names = @{ $sth->{neo_param_names} };
Arrayref of named parameters in statement.
- neo_param_values
-
@param_values = @{ $sth->{neo_param_values} };
Arrayref of bound parameter values.
SEE ALSO
REST::Neo4p, REST::Neo4p::Query, DBI, DBI::DBD
AUTHOR
Mark A. Jensen
CPAN ID : MAJENSEN
majensen -at- cpan -dot- org
COPYRIGHT
(c) 2013-2019 by Mark A. Jensen
LICENSE
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.