NAME

DBD::Neo4p - A DBI driver for Neo4j via REST::Neo4p

SYNOPSIS

use DBI;
my $dbh = DBI->connect("dbi:Neo4p:http://127.0.0.1:7474;user=foo;pass=bar");
my $q =<<CYPHER;
START x = node:node_auto_index(name= { startName })
MATCH path =(x-[r]-friend)
WHERE friend.name = { name }
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.2220 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);
$dbh = DBI->connect("dbi:Neo4p:db=http://127.0.0.1:7474",
                     { Username => 'me', Password => 's3kr1t'};

Database Level

prepare, prepare_cached
$sth = $dbh->prepare("START n = node(0) RETURN n");
$sth = $dbh->prepare("START n = node(0) MATCH n-()->m".
                     "WHERE m.name = { name } RETURN m");

Prepare a Cypher language statement. In Cypher, parameters are named and surrounded by curly brackets.

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. In Neo4j version 2.0 servers, node labels and indexes allow a schema-like constraint system (see http://docs.neo4j.org/chunked/2.0.0-RC1/cypher-schema.html).

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 and execute variants are meant to work. Please file a bug in RT if there are problems.

fetch

fetch and fetch_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-2015 by Mark A. Jensen

LICENSE

Copyright (c) 2013-2015 Mark A. Jensen. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.