xp-forge / neo4j
Neo4J connectivity for XP Framework
Installs: 4 178
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 3
Forks: 0
Open Issues: 2
Requires
- php: >=7.0.0
- xp-forge/json: ^5.0 | ^4.0 | ^3.0 | ^2.2
- xp-framework/core: ^12.0 | ^11.0 | ^10.0 | ^9.0 | ^8.0 | ^7.0
- xp-framework/http: ^10.0 | ^9.0 | ^8.0
Requires (Dev)
- xp-framework/test: ^2.0 | ^1.0
README
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
.