NAME

REST::Neo4p::Query - Execute Neo4j Cypher queries

SYNOPSIS

REST::Neo4p->connect('http:/127.0.0.1:7474');
$query = REST::Neo4p::Query->new('START n=node(0) RETURN n');
$query->execute;
$node = $query->fetch->[0];
$node->relate_to($other_node, 'link');

DESCRIPTION

REST::Neo4p::Query encapsulates Neo4j Cypher language queries, executing them via REST::Neo4p::Agent and returning an iterator over the rows, in the spirit of DBI.

METHODS

new()
$stmt = 'START n=node({node_id}) RETURN n';
$query = REST::Neo4p::Query->new($stmt,{node_id => 1});

Create a new query object. First argument is the Cypher query (required). Second argument is a hashref of parameters (optional).

execute()
$numrows = $query->execute;

Execute the query on the server.

fetch(), fetchrow_array()
$query = REST::Neo4p::Query->new('START n=node(0) RETURN n, n.name');
$query->execute;
while ($row = $query->fetch) { 
  print 'It works!" if ($row->[0]->get_property('name') == $row->[1]);
}

Fetch the next row of returned data (as an arrayref). Nodes are returned as REST::Neo4p::Node objects, relationships are returned as REST::Neo4p::Relationship objects, scalars are returned as-is.

err(), errstr()
$query->execute;
if ($query->err) {
  printf "status code: %d\n", $query->err;
  printf "error message: %s\n", $query->errstr;
}

Returns the HTTP error code and Neo4j server error message if an error was encountered on execution. Set $query->{RaiseError} to die immediately (e.g., to catch the exception in an eval block).

SEE ALSO

REST::Neo4p, REST::Neo4p::Agent.

AUTHOR

Mark A. Jensen
CPAN ID: MAJENSEN
majensen -at- cpan -dot- org

LICENSE

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