Skip to content

Instantly share code, notes, and snippets.

@dacr
Last active February 17, 2024 09:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dacr/87d9e51368446f88587e9ef41d05d473 to your computer and use it in GitHub Desktop.
Save dacr/87d9e51368446f88587e9ef41d05d473 to your computer and use it in GitHub Desktop.
playing with arangodb using java driver and native serdes / published by https://github.com/dacr/code-examples-manager #74fcf308-56a6-458c-b068-82b1df2bc08d/1eadca16d4de1aa5a9effa91fcfae290a96582e
// summary : playing with arangodb using java driver and native serdes
// keywords : arangodb, graphdb, javadriver, velocitypack, @testable,
// publish : gist, corporate
// 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 : 74fcf308-56a6-458c-b068-82b1df2bc08d
// created-on : 2021-03-05T09:25:00Z
// managed-by : https://github.com/dacr/code-examples-manager
// execution : scala ammonite script (http://ammonite.io/) - run as follow 'amm scriptname.sc'
// ---------------------
//> using scala "3.3.1"
//> using dep "com.arangodb:arangodb-java-driver:6.6.3"
//> using dep "com.arangodb:velocypack-module-scala_2.13:1.2.1"
// ---------------------
import com.arangodb._
import com.arangodb.entity._
import com.arangodb.model.AqlQueryOptions
import com.arangodb.util.MapBuilder
import com.arangodb.velocypack.module.scala._
val arango = {
new ArangoDB
.Builder()
.registerModule(new VPackScalaModule)
.host("127.0.0.1", 8529)
.user("root")
.password("root")
.build()
}
try {
arango.createDatabase("example")
} catch {
case _ =>
}
val db = arango.db("example")
try {
db.createCollection("sample")
} catch {
case _ =>
}
import scala.beans.BeanProperty
case class Someone(
@BeanProperty var name: String,
@BeanProperty var age: Int
) {
def this() = this(name = "", age=0)
}
def cursorSomeone: ArangoCursor[Someone] =
db.query(
"FOR i IN @@collection RETURN i",
new MapBuilder().put("@collection", "sample").get(),
new AqlQueryOptions(),
classOf[Someone]
)
cursorSomeone.forEach { someone =>
println(someone)
}
arango.shutdown()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment