From e702828e28b985119f25aa9a111cacb7334a228f Mon Sep 17 00:00:00 2001 From: Guy Korland Date: Wed, 16 Oct 2024 00:26:50 +0300 Subject: [PATCH] fix #51 fix READMe example (#81) * fix #51 fix READMe example --- README.md | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 5126449..a2fc20b 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ [![license](https://img.shields.io/github/license/FalkorDB/JFalkorDB.svg)](https://github.com/FalkorDB/JFalkorDB/blob/master/LICENSE) [![Release](https://img.shields.io/github/release/FalkorDB/JFalkorDB.svg)](https://github.com/FalkorDB/JFalkorDB/releases/latest) -[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.falkordb/jfalkordb/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.falkordb/jfalkordb) +[![Maven Central Version](https://img.shields.io/maven-central/v/com.falkordb/jfalkordb)](https://central.sonatype.com/artifact/com.falkordb/jfalkordb) [![Javadocs](https://www.javadoc.io/badge/com.falkordb/jfalkordb.svg)](https://www.javadoc.io/doc/com.falkordb/jfalkordb) [![Codecov](https://codecov.io/gh/FalkorDB/JFalkorDB/branch/master/graph/badge.svg)](https://codecov.io/gh/FalkorDB/JFalkorDB) [![Known Vulnerabilities](https://snyk.io/test/github/FalkorDB/JFalkorDB/badge.svg?targetFile=pom.xml)](https://snyk.io/test/github/FalkorDB/JFalkorDB?targetFile=pom.xml) @@ -21,7 +21,7 @@ FalkorDB Java client com.falkordb jfalkordb - 0.2.9 + 0.4.0 ``` @@ -44,7 +44,7 @@ and com.falkordb jfalkordb - 0.3.0-SNAPSHOT + 0.4.1-SNAPSHOT ``` @@ -58,10 +58,17 @@ import com.falkordb.graph_entities.Edge; import com.falkordb.graph_entities.Node; import com.falkordb.graph_entities.Path; import com.falkordb.Graph; +import com.falkordb.GraphContext; +import com.falkordb.GraphContextGenerator; +import com.falkordb.GraphTransaction; +import com.falkordb.Record; +import com.falkordb.ResultSet; import com.falkordb.FalkorDB; import com.falkordb.Driver; +import java.util.HashMap; import java.util.List; +import java.util.Map; public class GraphExample { public static void main(String[] args) { @@ -80,19 +87,19 @@ public class GraphExample { graph.query("MATCH (a:person), (b:person) WHERE (a.name = 'roi' AND b.name='amit') CREATE (a)-[:knows]->(b)"); ResultSet resultSet = graph.query("MATCH (a:person)-[r:knows]->(b:person) RETURN a, r, b"); - while(resultSet.hasNext()) { - Record record = resultSet.next(); + + // iterate over result set + for(Record record: resultSet) { // get values - Node a = record.getValue("a"); - Edge r = record.getValue("r"); + Node n = record.getValue("a"); + Edge e = record.getValue("r"); //print record - System.out.println(record.toString()); + System.out.println("Node: " + n + ", Edge: " + e); } resultSet = graph.query("MATCH p = (:person)-[:knows]->(:person) RETURN p"); - while(resultSet.hasNext()) { - Record record = resultSet.next(); + for(Record record: resultSet) { Path p = record.getValue("p"); // More path API at Javadoc. @@ -102,13 +109,13 @@ public class GraphExample { // delete graph graph.deleteGraph(); - Graph contextGraph = driver.graph("contextSocial"); + GraphContextGenerator contextGraph = driver.graph("contextSocial"); // get connection context - closable object try(GraphContext context = contextGraph.getContext()) { context.query("CREATE (:person{name:'roi',age:32})"); context.query("MATCH (a:person), (b:person) WHERE (a.name = 'roi' AND b.name='amit') CREATE (a)-[:knows]->(b)"); // WATCH/MULTI/EXEC - context.watch(); + context.watch("contextSocial"); GraphTransaction t = context.multi(); t.query("MATCH (a:person)-[r:knows]->(b:person{name:$name,age:$age}) RETURN a, r, b", params); @@ -123,7 +130,6 @@ public class GraphExample { } } } - ``` ## License