Last active
November 21, 2022 08:45
-
-
Save michael-simons/34e4667a2f491a5533e88b498b1f2cf2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//JAVA 17 | |
///usr/bin/env jbang "$0" "$@" ; exit $? | |
//DEPS org.neo4j.driver:neo4j-java-driver:5.2.0 | |
import java.util.List; | |
import org.neo4j.driver.AuthTokens; | |
import org.neo4j.driver.GraphDatabase; | |
// You need to import the Neo4j record, otherwise you will have ambiguous imports | |
import org.neo4j.driver.Record; | |
class Neo4jAndJDK17Records { | |
public static void main(String... a) { | |
try (var driver = GraphDatabase.driver("neo4j://localhost:7687", AuthTokens.basic("neo4j", "verysecret")); | |
var session = driver.session()) { | |
// use the reserved var name | |
var movieNeo4jRecords = session.run("MATCH (m:Movie) RETURN m").list(); | |
// or use the fully qualified import (see above with the imports) | |
List<Record> movieNeo4jRecordsImplicit = session.run("MATCH (m:Movie) RETURN m").list(); | |
// if you import the fully qualified name, it won't stop you from using the record keyword | |
record Movie(String title) { | |
} | |
List<Movie> movieRecords = session.run("MATCH (m:Movie) RETURN m") | |
.list(r -> new Movie(r.get("m").asNode().get("title").asString())); | |
movieRecords.forEach(System.out::println); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment