Skip to content

Commit

Permalink
fix #51 fix READMe example
Browse files Browse the repository at this point in the history
  • Loading branch information
gkorland authored Oct 15, 2024
1 parent b431610 commit 62329e1
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -21,7 +21,7 @@ FalkorDB Java client
<dependency>
<groupId>com.falkordb</groupId>
<artifactId>jfalkordb</artifactId>
<version>0.2.9</version>
<version>0.4.0</version>
</dependency>
</dependencies>
```
Expand All @@ -44,7 +44,7 @@ and
<dependency>
<groupId>com.falkordb</groupId>
<artifactId>jfalkordb</artifactId>
<version>0.3.0-SNAPSHOT</version>
<version>0.4.1-SNAPSHOT</version>
</dependency>
</dependencies>
```
Expand All @@ -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) {
Expand All @@ -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.
Expand All @@ -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);
Expand All @@ -123,7 +130,6 @@ public class GraphExample {
}
}
}

```

## License
Expand Down

0 comments on commit 62329e1

Please sign in to comment.