Last active
May 25, 2024 10:21
-
-
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/134c94aada746f0114b36e6ecb4005e5bd72a4d9
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 : 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.4.2" | |
//> 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