Last active
February 3, 2026 20:23
-
-
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/a4b11d84567234b2f639ce0c9b6f012bf5ca39a
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 License Version 2.0 (https://www.apache.org/licenses/LICENSE-2.0.txt) | |
| // 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