Component for handling Neo4j – an ACID-compliant transactional database with native graph storage and processing.
PBClient for Neo4j provides entire Neo4j query syntax based on Cypher. In addition, PBClient for Neo4j has special tools for the most used Cypher commands for nodes and edges, such as: create, match and delete.
Prerequirements
- In order for this component to work you have to obtain, install and run the respective Neo4j software and its licenses. We do not provide any Neo4j software.
OS compatibility
7 SP2 x64 |
8 x64 |
8.1 x64 |
10 x64 |
11 x64 |
RAD Studio compatibility
10 Seattle |
10.1 Berlin |
10.2 Tokyo |
10.3 Rio |
10.4 Sydney |
11 Alexandria |
1 user
3 users
5 users
10 users
Site license
Free components in a bundle
Buy a bundle now and enjoy all new component releases for free during the update period. |
Keep track of multiple versions
You will get access to all older versions and a detailed changelog. |
Free new features
Get all new component features for free during the free update period. |
Install once use forever
Our products are not time limited. |
Source code promise
In case our component will become obsolete and we no longer support it, we will provide you its source code. So you don’t have to worry about a replacement. |
References:
> PBNeo4jDemo example provided with the installer
> Neo4j native documentation, Cypher query syntax
After installation, a group PyBridge will appear in the Tool Palette of Delphi, where you can find the new components TPBNeo4j.
New component PBClient for Neo4j can be found in the Tool Palette under PyBridge group
Place TPBNeo4j onto the form and set up its main properties:
- BaseName – the default base name. You must set a new parameter value in the code each time you are going to work with a different database.
- BaseURL – the URL to connect to Neo4j
- Login and Password to access your database if required
Now PBClient for Neo4j is ready to be used. PBClient for Neo4j provides entire Neo4j query syntax based on Cypher. In addition, PBClient for Neo4j has special tools for the most used Cypher commands for nodes and edges, such as: CREATE, MATCH and DELETE. To demonstrate how it works, let’s create a simple application to manage the nodes and edges of the Neo4j database. Add the corresponding Buttons, Edits and Memo to your form:
In ‘GRAPH_NODE_CREATE’ and ‘GRAPH_NODE_MATCH’ ButtonClick event handler procedures we are using following PBNeo4j functions:
- GRAPH_NODE_CREATE(‘label’, ‘{“key_str”: “value_str”, “key_int”: value_int, …, “key_n”: “value_n”}’) – based on native CREATE this function creates a new ‘label’ node with corresponding ‘{“key”:”value”}’ pairs.
- GRAPH_NODE_MATCH(‘label’, ‘{“key_1”: “value_1”, …, “key_n”: “value_n”}’, [‘key_1’, …, ‘key_n’]) – based on native MATCH this function searches for all the ‘label’ nodes with matching ‘{“key”:”value”}’ pairs, and returns values of selected [‘keys’].
-
res2dic(JsonString) – converts Neo4j JSON string to the usual JSON string. This is necessary because JSON returned by Neo4j has unusual formatting.
When providing a JSON string as function parameter, you can use single quotes instead of double quotes:
‘{“key_str”: “value_str”, …}’ – double quotes
‘{”key_str”: ”value_str”, …}’ – escaped single quotes
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
procedure TForm2.GRAPH_NODE_CREATEClick(Sender: TObject); var Rslt, jres: string; begin Rslt:= PBNeo4j1.GRAPH_NODE_CREATE('Person', '{"name": "Alice", "age": 23, "hair": "blonde"}'); jres := PBNeo4j1.res2dic(Rslt); Memo1.Lines.Append(jres); Rslt:= PBNeo4j1.GRAPH_NODE_CREATE('Person', '{"name": "Alice", "age": 27, "hair": "brown"}'); jres := PBNeo4j1.res2dic(Rslt); Memo1.Lines.Append(jres); Rslt:= PBNeo4j1.GRAPH_NODE_CREATE('Person', '{"name": "Kurt", "age": 27}'); jres := PBNeo4j1.res2dic(Rslt); Memo1.Lines.Append(jres); Rslt:= PBNeo4j1.GRAPH_NODE_CREATE('Movie', '{"name": "Wall Street"}'); jres := PBNeo4j1.res2dic(Rslt); Memo1.Lines.Append(jres); end procedure TForm2.GRAPH_NODE_MATCHClick(Sender: TObject); var Rslt, jres: string; begin Rslt:= PBNeo4j1.GRAPH_NODE_MATCH('Person', '{"name": "Alice", "hair": "blonde"}', ['name', 'age']); jres := PBNeo4j1.res2dic(Rslt); Memo1.Lines.Append(jres); Rslt:= PBNeo4j1.GRAPH_NODE_MATCH('Person', '{"name": "Alice", "age": 23}', ['name', 'hair']); jres := PBNeo4j1.res2dic(Rslt); Memo1.Lines.Append(jres); Memo1.Lines.Append('') end; |
To delete a node we should provide its ID to the GRAPH_NODE_DELETE function.
1 2 3 4 5 6 |
procedure TForm2.GRAPH_NODE_DELETEClick(Sender: TObject); begin if trim(EditDelNode.Text) = '' then exit; PBNeo4j1.GRAPH_NODE_DELETE(StrToInt(EditDelNode.Text)) end; |
In ‘GRAPH_EDGE_CREATE’ and ‘GRAPH_EDGE_MATCH’ ButtonClick event handler procedures we are using following PBNeo4j functions:
- GRAPH_EDGE_CREATE(source_int, destination_int, ‘label’, ‘{“key_str”: “value_str”, “key_int”: value_int, …, “key_n”:”value_n”}’) – based on native CREATE this function creates a new ‘label’ edge between source and destination nodes with corresponding ‘{“key”:”value”}’ pairs.
- GRAPH_EDGE_MATCH(‘label’, ‘{“key_1”: “value_1”, …, “key_n”: “value_n”}’, [‘key_1’, …, ‘key_n’]) – based on native MATCH this function searches for all the ‘label’ edges with matching ‘{“key”:”value”}’ pairs, and returns values of selected [‘keys’].
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
procedure TForm2.GRAPH_EDGE_CREATEClick(Sender: TObject); var Rslt, jres: string; begin if (trim(SourceID.Text) = '') or (trim(EndID.Text) = '') then exit; Rslt:= PBNeo4j1.GRAPH_EDGE_CREATE(StrToInt(SourceID.Text), StrToInt(EndID.Text), 'FRIENDS', '{"duration": ' + cnt.ToString + '}'); jres := PBNeo4j1.res2dic(Rslt); Memo1.Lines.Append(jres); cnt := cnt + 1; end; procedure TForm2.GRAPH_EDGE_MATCHClick(Sender: TObject); var Rslt, jres: string; begin Rslt:= PBNeo4j1.GRAPH_EDGE_MATCH('FRIENDS', '{"duration": ' + cnt.ToString + '}', ['duration']); jres := PBNeo4j1.res2dic(Rslt); Memo1.Lines.Append(jres); Memo1.Lines.Append('') end; |
To delete an edge we should provide its ID to the GRAPH_EDGE_DELETE function.
1 2 3 4 5 6 |
procedure TForm2.GRAPH_EDGE_DELETEClick(Sender: TObject); begin if trim(EditDelEdge.Text) = '' then exit; PBRedisGraph1.GRAPH_EDGE_DELETE(StrToInt(EditDelEdge.Text)) end; |
The most powerful function of PBNeo4j is GRAPH_QUERY. Based on native QUERY this function can execute any Cypher language query that is supported by Neo4j.
1 2 3 4 5 6 7 8 9 10 11 |
procedure TForm2.ButtonQueryClick(Sender: TObject); var Rslt, jres: string; begin if trim(EditQuery.Text) = '' then exit; Rslt := PBNeo4j1.GRAPH_QUERY(trim(EditQuery.Text)); jres := PBNeo4j1.res2dic(Rslt); Memo1.Lines.Append((jres.Replace('},{', '},' + #13#10 + '{').Replace('rslt":[', 'Result":[' + #13#10))); Memo1.Lines.Append('') end; |
Below are some sample commands for you to try. Feel free to experiment with your own requests.
1 2 3 4 5 6 7 8 9 |
MATCH (n) RETURN * MATCH (n)-[r]-() RETURN r MATCH (a:Person) WHERE a.name = 'Kurt' CREATE (a)-[:MEMBER]->(:Band {name:'Nirvana'}) CREATE (jim:Person{name:'Jim', age:29})-[:FRIENDS]->(pam:Person {name:'Pam', age:27})-[:WORKS]->(:Employer {name:'Dunder Mifflin'}) MATCH (:Person {name:'Jim'})-[r:FRIENDS]->() DELETE r MATCH (n) DELETE n MATCH (n:Person{name: 'Alice', hair: 'blonde'}) RETURN n.name, n.age MATCH (n:Person{name: 'Alice', age: 23}) RETURN n.name, n.hair MATCH ()-[r:FRIENDS]->() WHERE r.duration=3 RETURN r.duration |
This example demonstrates how easy it is to develop Delphi applications relying on Neo4j with a help of PBClient for Neo4j. Now you can also enjoy the full power of Neo4j in your applications!