xp-forge/neo4j

Neo4J connectivity for XP Framework

v1.2.0 2024-03-24 12:36 UTC

This package is auto-updated.

Last update: 2024-10-24 13:57:44 UTC


README

Build status on GitHub XP Framework Module BSD Licence Requires PHP 7.0+ Supports PHP 8.0+ Latest Stable Version

This library implements Neo4J connectivity via its REST API.

Examples

Running a query can be done via open() (which yields one record at a time) or query() (which collects the results in an array):

use com\neo4j\Graph;
use util\cmd\Console;

$g= new Graph('http://user:pass@neo4j-db.example.com:7474/db/data');
$q= $g->open('MATCH (t:Topic) RETURN t.name, t.canonical');
foreach ($q as $record) {
  Console::writeLine('#', $record['t.canonical'], ': ', $record['t.name']);
}

To retrieve single results (or NULL if nothing is found), use fetch():

if ($topic= $g->fetch('MATCH (t:Topic{id:%s}) RETURN t', $id)) {
  Console::writeLine('Found topic ', $topic);
}

Formatting parameters uses printf-like format tokens. These will take care of proper escaping and type casting:

use com\neo4j\Graph;
use util\cmd\Console;

$g= new Graph('http://user:pass@neo4j-db.example.com:7474/db/data');
$g->query('CREATE (p:Person) SET t.name = %s, t.id = %d', $name, $id);

Batch statements can be executed via the execute() method.

Format characters

  • %s: Format a string
  • %d: Format a decimal number
  • %f: Format a floating point numer
  • %b: Format a boolean
  • %v: Copy value into parameter
  • %l: Copy label into query
  • %c: Copy literal into query
  • %%: A literal percent sign

Positional parameters (starting at 1) may be used, e.g. %2$s.