Last active
April 2, 2023 10:10
-
-
Save dacr/a7309b5f5f5236a79bd16eb58e783fe0 to your computer and use it in GitHub Desktop.
playing with arangodb using java driver and json4s serdes / published by https://github.com/dacr/code-examples-manager #e90e1b94-6a21-4df0-89d1-0e33cf839281/b04a0a45bc69657c6aa234e608974fccbc55af37
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 json4s serdes | |
// keywords : arangodb, graphdb, javadriver, json4s, @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 : e90e1b94-6a21-4df0-89d1-0e33cf839281 | |
// 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' | |
import $ivy.`com.arangodb:arangodb-java-driver:6.6.3` | |
import $ivy.`org.json4s::json4s-native:3.6.8` | |
import $ivy.`org.json4s::json4s-ext:3.6.8` | |
import com.arangodb._ | |
import com.arangodb.entity._ | |
import com.arangodb.model.AqlQueryOptions | |
import com.arangodb.util.MapBuilder | |
import org.json4s.DefaultFormats | |
import org.json4s.native.Serialization.{read, write} | |
val arango = { | |
new ArangoDB | |
.Builder() | |
.host("127.0.0.1", 8529) | |
.user("root@example") | |
.password("password") | |
.build() | |
} | |
val db = arango.db("example") | |
implicit val formats = DefaultFormats.lossless // for milliseconds in iso8601 dates... | |
case class Someone(name: String, age: Int, _key:Option[String]=None) | |
def cursorSomeone: ArangoCursor[String] = | |
db.query( | |
"FOR i IN @@collection RETURN i", | |
new MapBuilder().put("@collection", "sample").get(), | |
new AqlQueryOptions(), | |
classOf[String] | |
) | |
val sampleCollection = db.collection("sample") | |
val terminatorKey = "terminator" | |
if (!sampleCollection.documentExists(terminatorKey)) { | |
sampleCollection.insertDocument(write(Someone("arnold", 142, Some(terminatorKey)))) | |
} | |
sampleCollection.updateDocument(terminatorKey, write(Someone("arnold", 143, None))) | |
println("---------------------") | |
cursorSomeone.forEach { someoneJsonText => | |
val someone:Someone = read[Someone](someoneJsonText) | |
println(someone) | |
} | |
println("---------------------") | |
sampleCollection.deleteDocument(terminatorKey) | |
cursorSomeone.forEach { someoneJsonText => | |
val someone:Someone = read[Someone](someoneJsonText) | |
println(someone) | |
} | |
arango.shutdown() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment