Skip to content

Instantly share code, notes, and snippets.

@dacr
Last active April 2, 2023 10:12
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/023202543583dfd2d0ad95f0b0d94feb to your computer and use it in GitHub Desktop.
Save dacr/023202543583dfd2d0ad95f0b0d94feb to your computer and use it in GitHub Desktop.
basic thing to know about arangodb and graphql / published by https://github.com/dacr/code-examples-manager #59bd7ddf-b7e1-4792-959b-1a321e78c82f/c89f6c2a2f855e9700a1daa68036a02a57ae6560

Graph cheat sheet

introduction

arangodb

  • native multi-model database
    • key-values
    • documents (key-values whose values are JSON documents)
    • graphs defined through vertexes (nodes) and edges (links)
      • edges are oriented => arangodb manages oriented graph
      • from A to B (A->B) : a->B is OUTBOUND while B->A is INBOUND (reverse direction)
  • single query language
  • N databases
    • 1 database -> N collections
      • 1 Collection -> N documents (2 collection types : either document or edge collections)
        • 1 document = json object
          • document = json object enriched with system attributes
            • (_key, _id, _rev) for default documents
            • (_key, _id, _rev, _from, _to) for edge documents
  • vertex are just documents while edges are defined through dedicated collection types which add _from and _to dedicated attributes.
    • edges are also json documents so can comes with many information
    • edges defines relations !
  • kafka arango db connector is available

graph course instructions

cd $HOME/arango-commons
curl -L https://www.arangodb.com/arangodb_graphcourse_demodata/ -o data.zip
unzip data.zip
docker exec -it arango arangoimport --file /commons/airports.csv --collection airports --create-collection true --type csv
docker exec -it arango arangoimport --file /commons/flights.csv --collection flights --create-collection true --type csv --create-collection-type edge 

drivers

java driver java driver (official)

import $ivy.`com.arangodb:arangodb-java-driver:6.6.3`

After various experiments run perfectly, no fully friendly with scala, but it exists an external module which help scala integration. Well designed, quite easy to take benefits of scala features to enrich and simplify the API, also very simple to customize JSON processing with any high level scala JSON library ! :)

proteus scala driver

Some scala instructions using ammonite REPL :

import $ivy.`com.cornfluence::proteus:0.7.3`

Looks like queries are not supported :(

avokka scala driver

Some scala instructions using ammonite REPL :

import $ivy.`avokka::avokka-arangodb:0.0.3`

Very young :(

scarango scala driver

Some scala instructions using ammonite REPL :

import $ivy.`com.outr::scarango-driver:2.3.5`
import com.outr.arango._,query._,profig.Profig
import scala.concurrent.ExecutionContext.Implicits.global

object TestIt {
  Profig.loadDefaults()
  val db = new Graph(
    databaseName = "example",
    baseURL=io.youi.net.URL("http://127.0.0.1:8279"), 
    credentials=Some(Credentials("root@example", "password"))
  )
  println(db.databaseName)
  println(db.collections.size)
  println(db.collections.map(_.name)) 
  println(db.query(aql"RETURN COUNT(sample)").as[Int].one)
  
  def init:Unit 
}

TestIt.init

HAS ISSUES at least when used from ammonite

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment