Last active
June 19, 2024 22:07
-
-
Save dacr/38d2b7bda4d2f451e840a8ed51de96a7 to your computer and use it in GitHub Desktop.
neo4j cypher queries - simple embedded test example / published by https://github.com/dacr/code-examples-manager #d4ceb08f-d6fe-4853-8ce2-0a0994076590/3fc59c42e429a1414e9afaae856e9a7e1787df92
This file contains hidden or 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
// summary : neo4j cypher queries - simple embedded test example | |
// keywords : scala, neo4j, cypher, @testable | |
// publish : gist | |
// authors : David Crosson | |
// license : Apache NON-AI License Version 2.0 (https://raw.githubusercontent.com/non-ai-licenses/non-ai-licenses/main/NON-AI-APACHE2) | |
// id : d4ceb08f-d6fe-4853-8ce2-0a0994076590 | |
// created-on : 2023-06-24T09:24:39+02:00 | |
// managed-by : https://github.com/dacr/code-examples-manager | |
// run-with : scala-cli $file | |
// --------------------- | |
//> using scala "3.4.2" | |
//> using dep "org.neo4j.test:neo4j-harness:5.20.0" | |
//> using dep "org.neo4j.driver:neo4j-java-driver:5.21.0" | |
// --------------------- | |
import org.neo4j.driver.{GraphDatabase, AuthTokens} | |
import scala.util.Using | |
import scala.util.chaining.* | |
val fixture = | |
""" | |
|CREATE (:Person {name: 'Jane'}) | |
|CREATE (:Person {name: 'Joe'}) | |
|""".stripMargin | |
val builder = | |
org.neo4j.harness.Neo4jBuilders | |
.newInProcessBuilder() | |
.withFixture(fixture) | |
Using(builder.build()) { embedded => | |
Using(GraphDatabase.driver(embedded.boltURI(), AuthTokens.none())) { driver => | |
Using(driver.session()) { session => | |
val query = "MATCH (n) RETURN count(n) AS count" | |
val result = session.run(query) | |
val count = result.single().get("count").asInt() | |
println(s"'$query' : count = $count") | |
}.tap(r => println(r)) | |
}.tap(r => println(r)) | |
}.tap(r => println(r)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment